Closed WesleyAC closed 5 months ago
Bincode tries to achieve this but like you mentioned cases like NaN floating point deserialization could violate this assumption. Specifically we use a lot of from_le_bytes
and from_be_bytes
calls which could result in situations where the encoded value is different than the in-memory value.
That being said, I think in reality all values from the standard library will be a 1:1 mapping.
The bigger thing where this guarantee could break is when 3rd parties implement bincode for their types. At this point they could implement it any way they want, even using a randomizer to populate the data.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I require a encoding system that guarantees a 1:1 relationship between encodings and values.
That is to say, given a particular value, only one sequence of bytes will deserialize to that value, all other sequences either represent some other value or are invalid and will throw an error.
From looking at the bincode format, it seems like if it's correctly implemented, and if there aren't any custom decoders in play that violate this assumption, it should fit this, but I'm not 100% sure (for instance, it could not unreasonably canonicalize floating-point NaNs when decoding, which would violate this assumption — I assume it doesn't, but I don't know).
Is this a guarantee that bincode intends to provide? If so, could that be documented?