3 releases

0.1.2 Apr 14, 2023
0.1.1 Dec 7, 2022
0.1.0 Apr 10, 2022

#1779 in Encoding

Download history 2988/week @ 2024-03-15 3588/week @ 2024-03-22 4720/week @ 2024-03-29 3964/week @ 2024-04-05 3150/week @ 2024-04-12 3287/week @ 2024-04-19 3706/week @ 2024-04-26 2812/week @ 2024-05-03 4159/week @ 2024-05-10 2426/week @ 2024-05-17 2366/week @ 2024-05-24 2669/week @ 2024-05-31 2130/week @ 2024-06-07 1933/week @ 2024-06-14 3743/week @ 2024-06-21 1760/week @ 2024-06-28

9,982 downloads per month

MPL-2.0 license

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 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.

Dependencies

~1.5MB
~41K SLoC