1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//! Pure Rust [MessagePack](https://msgpack.org): serde support, a dynamic value type and a low-level API in one crate.
//!
//! A reworked fork of `rmp`, `rmp-serde` and `rmpv`: one crate, no `unsafe`, no panics, faster; the wire format is the
//! same, the API is not. The [README](https://github.com/alfatm/rmpx#readme) lists the differences and the trade-offs.
//!
//! - The crate root and [`ser`] / [`de`]: any `serde::Serialize` / `serde::Deserialize` type to and from MessagePack
//! (feature `serde`).
//! - [`value`]: [`Value`] and [`ValueRef`], MessagePack data of any shape, and their readers and writers (feature
//! `value`).
//! - [`raw`]: readers and writers for single MessagePack values with direct mapping to the binary format, no heap
//! allocations; the only part available without `std`.
//!
//! All three features are on by default; `default-features = false` leaves only [`raw`], usable in `no_std` builds.
//!
//! # Serde
//!
//! ```
//! use serde::{Deserialize, Serialize};
//!
//! #[derive(Debug, PartialEq, Deserialize, Serialize)]
//! struct Human {
//! age: u32,
//! name: String,
//! }
//!
//! let john = Human { age: 42, name: "John".into() };
//!
//! // Structs as arrays of their fields: compact, but both sides must agree on the field order.
//! let buf = rmpx::to_vec(&john).unwrap();
//! assert_eq!(buf, [0x92, 0x2a, 0xa4, b'J', b'o', b'h', b'n']);
//!
//! // Structs as maps with field names, readable by any MessagePack implementation.
//! let named = rmpx::to_vec_named(&john).unwrap();
//!
//! // Either form decodes into the struct.
//! assert_eq!(rmpx::from_slice::<Human>(&buf).unwrap(), john);
//! assert_eq!(rmpx::from_slice::<Human>(&named).unwrap(), john);
//! ```
//!
//! [`Serializer`] and [`Deserializer`] work with any `std::io::Write` / `std::io::Read` and take their options
//! through [`config`].
//!
//! # Dynamic values
//!
//! ```
//! use rmpx::Value;
//!
//! let buf = rmpx::to_vec_named(&std::collections::BTreeMap::from([("id", 7)])).unwrap();
//!
//! let value = rmpx::value::decode::read_value(&mut &buf[..]).unwrap();
//! assert_eq!(value, Value::Map(vec![("id".into(), 7.into())]));
//! ```
//!
//! # Low level
//!
//! ```
//! let mut buf = Vec::new();
//! rmpx::raw::encode::write_sint(&mut buf, 300).unwrap();
//! assert_eq!(buf, [0xcd, 0x01, 0x2c]);
//! assert_eq!(rmpx::raw::decode::read_int::<u16, _>(&mut &buf[..]).unwrap(), 300);
//! ```
extern crate alloc;
// Only serde support for `Value` uses it; Cargo cannot enable a dependency for a combination of features.
use serde_bytes as _;
pub use crate;
pub use crate;
pub use crate;
pub use crate;
/// Name of the serde newtype struct that stands for a MessagePack ext value.
///
/// MessagePack `ext(tag, data)` maps to the serde data model as `_ExtStruct((tag, data))`, so a type serializes as an
/// ext value like this:
///
/// ```
/// # #[cfg(all(feature = "serde", feature = "value"))] {
/// use serde::{Deserialize, Serialize};
///
/// #[derive(Debug, PartialEq, Serialize, Deserialize)]
/// #[serde(rename = "_ExtStruct")]
/// struct ExtStruct((i8, serde_bytes::ByteBuf));
///
/// let ext = ExtStruct((2, serde_bytes::ByteBuf::from(vec![5])));
/// let buf = rmpx::to_vec(&ext).unwrap();
/// assert_eq!(rmpx::value::decode::read_value(&mut &buf[..]).unwrap(), rmpx::Value::Ext(2, vec![5]));
/// assert_eq!(rmpx::from_slice::<ExtStruct>(&buf).unwrap(), ext);
/// # }
/// ```
pub const MSGPACK_EXT_STRUCT_NAME: &str = "_ExtStruct";
/// The examples in the README, compiled and run as doc tests.
;