Description
Component
primitives
What version of Alloy are you on?
alloy-primitives v0.3.1
Operating System
None
Describe the bug
Trying to use bincode
to deserialize FixedBytes<N>
fails because deserializer.deserialize_any
is not supported.
Code snippet to reproduce this bug:
let hash = B256::ZERO;
bincode::deserialize::<B256>(&bincode::serialize(&hash).unwrap()).unwrap();
The serde
documentation also discourages the use of deserialize_any
for this very reason:
When implementing Deserialize, you should avoid relying on Deserializer::deserialize_any unless you need to be told by the Deserializer what type is in the input. Know that relying on Deserializer::deserialize_any means your data type will be able to deserialize from self-describing formats only, ruling out Postcard and many others.
However, as I understand #202, JSON deserialization support for either a byte array, byte sequence, or string was explicitly required. Here I see a possible compromise to also check is_human_readable()
in the deserialization and keep the current parsing only for human readable, e.g. JSON, and use deserializer.deserialize_bytes
otherwise, which would also allow bincode
and similar formats.
If this approach is acceptable, I would be happy to provide a PR.