Struct msgpack_schema::value::Str [−][src]
Expand description
String objects of MessagePack are essentially byte arrays type that may contain any bytes.
String type vs Binary type
MessagePack has a complicated history about its distinction between string type and binary type.
While an earlier version of MessagePack had only one type for encoding a binary data, namely the raw type, it was later divided into two distinct types for supporting use cases in dynamically-typed languages. 1 The string type, one of the newly added types, is essentially what was originally called the raw type. Because of this origin, despite its name, string objects of MessagePack can contain not just valid UTF-8 sequences but also any byte sequences. And encoding non-UTF-8 byte sequences as a string object is a perfectly valid and expected usage by the spec authors.
So which to use in encoding my binary data?
When you decide to implement a custom serializer/deserializer for your own binary type, it is recommended to use string type instead of binary type for its encoding scheme for the following reasons.
- It just saves some memory. If your byte array is less than 32 byte length, using string type instead of byte array saves one byte per object.
- The disiction only matters when not using a data schema. Because this crate offers a statically-typed data schema, and we know how to decode data into a Rust object at compile time, distinction of these types in the input binary data is almost useless,
Although we strongly recommend you to use string types rather than binary types, this crate does not force you to do so. The functions and trait implementations provided by this crate are all taking a neutral stand.
Implementations
Trait Implementations
fn deserialize<D>(
deserializer: &mut D
) -> Result<Self, DeserializeError<D::Error>> where
D: Deserializer,
[src]Auto Trait Implementations
impl RefUnwindSafe for Str
impl UnwindSafe for Str
Blanket Implementations
Mutably borrows from an owned value. Read more