-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relative encodings #24
Conversation
Good point. Yeah, I like the two separate traits, then.
Not sure about this one. I think this should be a panic rather than an error, since it indicates a bug in your own implementation rather than an expected case that is allowed to happen. |
be0b244
to
a977f64
Compare
Agreed. |
Efficient path decoding
Private entry fields
New relative encoding traits
Adds
RelativeEncodable
andRelativeDecodable
traits. But wait! Why the new traits, you ask? Why not just define aRelativity
struct and implementEncoder
andDecoder
on those?Decoder::decode
is a static method which takes a Ufotofu producer as its single parameter. But we need the reference value to to decode relative to! Thus we must have aRelativeDecoder
trait which has the reference in question as a (&self
) parameter.Encodable
on a Relativity struct (see the first commit), symmetry betweenEncodable
andDecodable
traits has now been broken, which I found a bit confusingThere is another kind of error exclusive to relative encodings which we'd like to be able to surface, which isIllegalRelativity
. Some relative encodings require the subject being encoded to be logically included by the reference item, e.g. anEntry
encoded relative to anArea
must be included by thatArea
. With a Relativity struct, the only way to check for this would be to define custom constructors for each kind of relative pairing, which was possible to accidentally forget to do. But with a dedicatedRelativeEncoder
trait, we can returnResult<(), RelativeEncodeError>
.All this considered it made more sense to me to have dedicated traits.
Fuzzing utilities
relative_encoding_roundtrip
(encode, decode, check it came out okay)relative_encoding_random
(decode random bytes, encode, assert new encoding is exactly the same as the previous one)relative_encoding_random_less_strict
(decode random bytes, encode, decode it again, assert the decoded object is the same the second time around)Encodings