Skip to main content

Module bincode_io

Module bincode_io 

Source
Expand description

Thin wrappers around bincode’s free (de)serialization functions that avoid bincode::serialize’s built-in serialized-size pre-pass.

bincode::serialize (and Options::serialize, which it’s built on) always calls serialized_size — a full Serialize::serialize pass against a SizeChecker — before encoding for real into a correctly pre-sized Vec (see bincode’s internal serialize function). For most #[derive(Serialize)] types that’s cheap: both passes just walk fields, and the size pass does no real work. But Serialize impls that build their output eagerly regardless of which serializer is asking — most notably HeapArray’s (the InPlaceCodec fast path), whose serialize calls self.to_inplace_bytes() unconditionally — end up doing that work twice: once to be measured and thrown away by the SizeChecker pass, once for the real encode.

serialize encodes exactly once, writing directly into a growable Vec via bincode::serialize_into (the same fix already used by network’s IoSink::send). deserialize is a plain passthrough to bincode::deserialize — bincode’s decode path has no equivalent double pass — kept alongside serialize so callers use one consistent (de)serialization entry point instead of mixing direct bincode::* calls with this module.

Functions§

deserialize
Deserialize a T with bincode. A thin passthrough to bincode::deserialize, kept alongside serialize so callers use one consistent (de)serialization entry point.
serialize
Serialize value with bincode, without bincode::serialize’s serialized-size pre-pass.