Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
A simple binary encoding format used in the Matrix world.
The matrix-pickle binary encoding format is used in the libolm and
vodozemac cryptographic libraries.
How to use
The simplest way to use matrix-pickle is using the derive macros:
use Result;
use ;
Format definition
matrix-pickle encodes most values without any metadata, the bytes that are
part of the struct in most cases get encoded verbatim.
The table bellow defines how common types are encoded.
| Type | Example value | Encoded value | Comment |
|---|---|---|---|
u8 |
255 |
[FF] |
Encoded verbatim |
bool |
true |
[01] |
Converted to an u8 before encoding |
[u8; N] |
[1u8, 2u8] |
[01, 02] |
Encoded verbatim |
u32 |
16 |
[00, 00, 00, 10] |
Encoded as a byte array in big endian form |
usize |
32 |
[00, 00, 00, 20] |
Converted to an u32 before encoding |
&[T] |
&[3u8, 4u8] |
[00, 00, 00, 02, 03, 04] |
The length gets encoded first, then each element |
Derive support
The crate supports deriving Encode and Decode implementations for structs
and enums as long as the types inside them implement Encode and Decode as
well.
Structs
The derive support for structs simply encodes each field of a struct in the order they are defined, for example:
use Write;
use ;
Enums
Enums on the other hand first encode the number of the variant as an u8, then
the value of the enum.
Only enums with variants that contain a single associated data value are supported.
use Write;
use ;
Encoding and decoding secrets
For decoding values which are meant to be secret, make sure to box the array. We have a helper attribute that reminds you that values that are meant to be kept secret should be boxed.
Simply annotate any struct field using the #[secret] attribute.
If a value that is meant to be a secret is not boxed a compiler error will be thrown. For example, this snippet won't compile.
use ;
This example on the other hand compiles.
use ;
Comparison to bincode
The binary format is similar to what the bincode crate provides with the following config:
let config = standard
.with_big_endian
.with_fixed_int_encoding
.skip_fixed_array_length;
The two major differences to the format are:
bincodeusesu64to encode slice lengthsmatrix-pickleusesu32to encode slice lengths
Other differences are:
- No support to configure the encoding format, if you need to tweak the format, use bincode.
- No unsafe code. Optimized for simplicity, not for pure performance