Expand description
A predictable serialization format for serde.
hubpack is an algorithm for converting Rust values to bytes and back. It
was originally designed for encoding messages sent between embedded
programs. It is designed for use with serde.
Some of the nice things about hubpack include:
-
Its encoding format is relatively compact.
-
Its encoding format is predictable. In particular, there are no variable-length integer encodings.
-
Because the size is predictable,
hubpackprovides aSerializedSizetrait. Any type that implementsSerializedSizecan report the maximum number of bytes necessary to encode it usinghubpack. This means you can allocate a fixed-size buffer without worry. (You can#[derive(SerializedSize)]for your own types.) -
The encode/decode implementations generate fairly small, efficient code.
-
The implementation uses very little
unsafecode, only in specific cases with a measurable performance improvement and no reasonable alternative.
You might not want to use hubpack because of the following limitations:
-
hubpackis designed for fixed-size small data structures, and cannot encode things likeVec,str, and maps. -
hubpackdoes not supportenumtypes with more than 256 variants. -
hubpackaims for predictability over compactness, so certain types of data – like lots of integers whose values are small relative to their types – can be more compactly encoded using formats likebincode.
Re-exports§
pub use de::deserialize;pub use error::Error;pub use error::Result;pub use ser::serialize;pub use size::SerializedSize;
Modules§
- de
- Deserializing
hubpack-encoded values back into Rust. - error
- Error type.
- ser
- Serialization of Rust values into
hubpackformat. - size
- Reasoning about the maximum encoded size of types.
Derive Macros§
- Serialized
Size - Derive macro for the
SerializedSizetrait.