Crates.io | hubpack |
lib.rs | hubpack |
version | 0.1.2 |
source | src |
created_at | 2022-04-10 16:54:44.213094 |
updated_at | 2023-04-14 20:14:09.118346 |
description | A predictable serialization format. |
homepage | |
repository | |
max_upload_size | |
id | 565167 |
size | 47,077 |
hubpack
: a predictable serde
formathubpack
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, hubpack
provides a SerializedSize
trait.
Any type that implements SerializedSize
can report the maximum number of
bytes necessary to encode it using hubpack
. 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 unsafe
code, 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:
hubpack
is designed for fixed-size small data structures, and cannot encode
things like Vec
, str
, and maps.
hubpack
does not support enum
types with more than 256 variants.
hubpack
aims 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 like bincode
.