Skip to main content

Module ser

Module ser 

Source
Expand description

Serialize support for messagepack

§Limitation

MessagePack requires the length header of arrays and maps to be written before any elements are encoded. Therefore this serializer needs serde to provide the exact length up front. If serde calls serialize_seq(None) or serialize_map(None), this serializer returns Error::SeqLenNone.

Examples with serde(flatten):

use serde::Serialize;
use std::collections::HashMap;

// Fails
#[derive(Serialize)]
struct Inner { b: u8, c: u8 }

#[derive(Serialize)]
struct Outer {
    a: u8,
    #[serde(flatten)]
    extra: Inner,
}

let mut buf = [0u8; 32];
let v = Outer { a: 1, extra: Inner { b: 2, c: 3 } };
let err = messagepack_serde::ser::to_slice(&v, &mut buf).unwrap_err();
assert_eq!(err, messagepack_serde::ser::Error::SeqLenNone);

Structs§

AggressiveMinimize
Encode a given numeric value by aggressively minimising its format.
Exact
Encode a given numeric value exactly using its native format.
LosslessMinimize
Encode a given numeric value in a lossless minimised format without changing its original format.

Enums§

Error
Error during serialization

Traits§

NumEncoder
Decide how numeric values are encoded.

Functions§

to_core_writer
Serialize value to messagepack_core::io::IoWrite.
to_core_writer_with_config
Serialize value to messagepack_core::io::IoWrite with config.
to_slice
Serialize value to slice
to_slice_with_config
Serialize value to slice with config.
to_vecalloc
Serialize value as messagepack byte vector
to_vec_with_configalloc
Serialize value as messagepack byte vector with config
to_writerstd
Serialize value to std::io::Write
to_writer_with_configstd
Serialize value to std::io::Write with config.