diff --git a/rmp/Cargo.toml b/rmp/Cargo.toml index cc522b84..bca041c2 100644 --- a/rmp/Cargo.toml +++ b/rmp/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rmp" -version = "0.8.13" +version = "0.8.14" authors = ["Evgeny Safronov "] license = "MIT" description = "Pure Rust MessagePack serialization implementation" diff --git a/rmp/src/marker.rs b/rmp/src/marker.rs index 6da1d902..71bfaa17 100644 --- a/rmp/src/marker.rs +++ b/rmp/src/marker.rs @@ -4,12 +4,26 @@ const FIXMAP_SIZE : u8 = 0x0f; /// Format markers. #[derive(Clone, Copy, Debug, PartialEq)] +#[repr(u8)] pub enum Marker { - FixPos(u8), - FixNeg(i8), - Null, - True, + FixPos(u8) = 0x00, + FixNeg(i8) = 0xe0, + FixMap(u8) = 0x80, + FixArray(u8) = 0x90, + FixStr(u8) = 0xa0, + Null = 0xc0, + // Marked in MessagePack spec as never used. + Reserved, False, + True, + Bin8, + Bin16, + Bin32, + Ext8, + Ext16, + Ext32, + F32, + F64, U8, U16, U32, @@ -18,35 +32,24 @@ pub enum Marker { I16, I32, I64, - F32, - F64, - FixStr(u8), + FixExt1, + FixExt2, + FixExt4, + FixExt8, + FixExt16, Str8, Str16, Str32, - Bin8, - Bin16, - Bin32, - FixArray(u8), Array16, Array32, - FixMap(u8), Map16, Map32, - FixExt1, - FixExt2, - FixExt4, - FixExt8, - FixExt16, - Ext8, - Ext16, - Ext32, - Reserved, } impl Marker { /// Construct a msgpack marker from a single byte. #[must_use] + #[inline] pub fn from_u8(n: u8) -> Marker { match n { 0x00 ..= 0x7f => Marker::FixPos(n), @@ -91,7 +94,9 @@ impl Marker { } /// Converts a marker object into a single-byte representation. - #[must_use] pub fn to_u8(&self) -> u8 { + #[must_use] + #[inline] + pub fn to_u8(&self) -> u8 { match *self { Marker::FixPos(val) => val, Marker::FixNeg(val) => val as u8, @@ -146,14 +151,14 @@ impl Marker { } impl From for Marker { - #[inline] + #[inline(always)] fn from(val: u8) -> Marker { Marker::from_u8(val) } } impl From for u8 { - #[inline] + #[inline(always)] fn from(val: Marker) -> Self { val.to_u8() }