Expand description
Codec implementations for Rust primitive types.
§Fixed-size vs Variable-size
Most primitives therefore have a compile-time constant SIZE and can be
encoded/decoded without any configuration.
usize is the lone exception: since most values refer to a length or size
of an object in memory, values are biased towards smaller values. Therefore,
it uses variable-length (varint) encoding to save space. This means that it
does not implement FixedSize. When decoding a usize, callers must
supply a RangeCfg to bound the allowable value. This protects against
denial-of-service attacks that would allocate oversized buffers.
§Safety & portability
usizeis restricted to values that fit in au32to keep the on-wire format identical across 32-bit and 64-bit architectures.- All fixed-size integers and floats are written big-endian to avoid host- endian ambiguity.