Fix encoding of fields so that CanAddr() passes. Adds tests.

Thanks to @sbinet for the PR. Fixes #5.