3 releases
0.1.2 | Apr 14, 2023 |
---|---|
0.1.1 | Dec 7, 2022 |
0.1.0 | Apr 10, 2022 |
#552 in HTTP server
12,105 downloads per month
31KB
720 lines
hubpack
: a predictable serde
format
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,
hubpack
provides aSerializedSize
trait. Any type that implementsSerializedSize
can 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
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 likeVec
,str
, and maps. -
hubpack
does not supportenum
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 likebincode
.
Dependencies
~2MB
~42K SLoC