Struct rmp_serde::encode::Serializer
source · [−]pub struct Serializer<W, C = DefaultConfig> { /* private fields */ }
Expand description
Represents MessagePack serialization implementation.
Note
MessagePack has no specification about how to encode enum types. Thus we are free to do whatever we want, so the given choice may be not ideal for you.
An enum value is represented as a single-entry map whose key is the variant id and whose value is a sequence containing all associated data. If the enum does not have associated data, the sequence is empty.
All instances of ErrorKind::Interrupted
are handled by this function and the underlying
operation is retried.
Implementations
sourceimpl<W: Write, C> Serializer<W, C>
impl<W: Write, C> Serializer<W, C>
sourcepub fn get_mut(&mut self) -> &mut W
pub fn get_mut(&mut self) -> &mut W
Gets a mutable reference to the underlying writer.
It is inadvisable to directly write to the underlying writer.
sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Unwraps this Serializer
, returning the underlying writer.
sourceimpl<W: Write> Serializer<W, DefaultConfig>
impl<W: Write> Serializer<W, DefaultConfig>
sourceimpl<W: Write, C> Serializer<W, C>
impl<W: Write, C> Serializer<W, C>
sourcepub fn with_struct_map(self) -> Serializer<W, StructMapConfig<C>>
pub fn with_struct_map(self) -> Serializer<W, StructMapConfig<C>>
Consumes this serializer returning the new one, which will serialize structs as a map.
This is used, when the default struct serialization as a tuple does not fit your requirements.
sourcepub fn with_struct_tuple(self) -> Serializer<W, StructTupleConfig<C>>
pub fn with_struct_tuple(self) -> Serializer<W, StructTupleConfig<C>>
Consumes this serializer returning the new one, which will serialize structs as a tuple without field names.
This is the default MessagePack serialization mechanism, emitting the most compact representation.
sourcepub fn with_human_readable(self) -> Serializer<W, HumanReadableConfig<C>>
pub fn with_human_readable(self) -> Serializer<W, HumanReadableConfig<C>>
Consumes this serializer returning the new one, which will serialize some types in
human-readable representations (Serializer::is_human_readable
will return true
). Note
that the overall representation is still binary, but some types such as IP addresses will
be saved as human-readable strings.
This is primarily useful if you need to interoperate with serializations produced by older
versions of rmp-serde
.
sourcepub fn with_binary(self) -> Serializer<W, BinaryConfig<C>>
pub fn with_binary(self) -> Serializer<W, BinaryConfig<C>>
Consumes this serializer returning the new one, which will serialize types as binary
(Serializer::is_human_readable
will return false
).
This is the default MessagePack serialization mechanism, emitting the most compact representation.
Trait Implementations
sourceimpl<W: Debug, C: Debug> Debug for Serializer<W, C>
impl<W: Debug, C: Debug> Debug for Serializer<W, C>
sourceimpl<'a, W, C> Serializer for &'a mut Serializer<W, C>where
W: Write,
C: SerializerConfig,
impl<'a, W, C> Serializer for &'a mut Serializer<W, C>where
W: Write,
C: SerializerConfig,
type Ok = ()
type Ok = ()
Serializer
during successful
serialization. Most serializers that produce text or binary output
should set Ok = ()
and serialize into an io::Write
or buffer
contained within the Serializer
instance. Serializers that build
in-memory data structures may be simplified by using Ok
to propagate
the data structure around. Read moretype SerializeSeq = MaybeUnknownLengthCompound<'a, W, C>
type SerializeSeq = MaybeUnknownLengthCompound<'a, W, C>
serialize_seq
for serializing the content of the
sequence. Read moretype SerializeTuple = Compound<'a, W, C>
type SerializeTuple = Compound<'a, W, C>
serialize_tuple
for serializing the content of
the tuple. Read moretype SerializeTupleStruct = Compound<'a, W, C>
type SerializeTupleStruct = Compound<'a, W, C>
serialize_tuple_struct
for serializing the
content of the tuple struct. Read moretype SerializeTupleVariant = Compound<'a, W, C>
type SerializeTupleVariant = Compound<'a, W, C>
serialize_tuple_variant
for serializing the
content of the tuple variant. Read moretype SerializeMap = MaybeUnknownLengthCompound<'a, W, C>
type SerializeMap = MaybeUnknownLengthCompound<'a, W, C>
serialize_map
for serializing the content of the
map. Read moretype SerializeStruct = Compound<'a, W, C>
type SerializeStruct = Compound<'a, W, C>
serialize_struct
for serializing the content of
the struct. Read moretype SerializeStructVariant = Compound<'a, W, C>
type SerializeStructVariant = Compound<'a, W, C>
serialize_struct_variant
for serializing the
content of the struct variant. Read moresourcefn is_human_readable(&self) -> bool
fn is_human_readable(&self) -> bool
Serialize
implementations should serialize in
human-readable form. Read moresourcefn serialize_bool(self, v: bool) -> Result<Self::Ok, Self::Error>
fn serialize_bool(self, v: bool) -> Result<Self::Ok, Self::Error>
bool
value. Read moresourcefn serialize_i16(self, v: i16) -> Result<Self::Ok, Self::Error>
fn serialize_i16(self, v: i16) -> Result<Self::Ok, Self::Error>
i16
value. Read moresourcefn serialize_i32(self, v: i32) -> Result<Self::Ok, Self::Error>
fn serialize_i32(self, v: i32) -> Result<Self::Ok, Self::Error>
i32
value. Read moresourcefn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error>
fn serialize_i64(self, v: i64) -> Result<Self::Ok, Self::Error>
i64
value. Read moresourcefn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error>
fn serialize_i128(self, v: i128) -> Result<Self::Ok, Self::Error>
i128
value. Read moresourcefn serialize_u16(self, v: u16) -> Result<Self::Ok, Self::Error>
fn serialize_u16(self, v: u16) -> Result<Self::Ok, Self::Error>
u16
value. Read moresourcefn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error>
fn serialize_u32(self, v: u32) -> Result<Self::Ok, Self::Error>
u32
value. Read moresourcefn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error>
fn serialize_u64(self, v: u64) -> Result<Self::Ok, Self::Error>
u64
value. Read moresourcefn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error>
fn serialize_u128(self, v: u128) -> Result<Self::Ok, Self::Error>
u128
value. Read moresourcefn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error>
fn serialize_f32(self, v: f32) -> Result<Self::Ok, Self::Error>
f32
value. Read moresourcefn serialize_f64(self, v: f64) -> Result<Self::Ok, Self::Error>
fn serialize_f64(self, v: f64) -> Result<Self::Ok, Self::Error>
f64
value. Read moresourcefn serialize_char(self, v: char) -> Result<Self::Ok, Self::Error>
fn serialize_char(self, v: char) -> Result<Self::Ok, Self::Error>
sourcefn serialize_bytes(self, value: &[u8]) -> Result<Self::Ok, Self::Error>
fn serialize_bytes(self, value: &[u8]) -> Result<Self::Ok, Self::Error>
sourcefn serialize_unit_variant(
self,
_name: &str,
idx: u32,
variant: &'static str
) -> Result<Self::Ok, Self::Error>
fn serialize_unit_variant(
self,
_name: &str,
idx: u32,
variant: &'static str
) -> Result<Self::Ok, Self::Error>
sourcefn serialize_newtype_struct<T: ?Sized + Serialize>(
self,
name: &'static str,
value: &T
) -> Result<(), Self::Error>
fn serialize_newtype_struct<T: ?Sized + Serialize>(
self,
name: &'static str,
value: &T
) -> Result<(), Self::Error>
struct Millimeters(u8)
. Read moresourcefn serialize_newtype_variant<T: ?Sized + Serialize>(
self,
_name: &'static str,
idx: u32,
variant: &'static str,
value: &T
) -> Result<Self::Ok, Self::Error>
fn serialize_newtype_variant<T: ?Sized + Serialize>(
self,
_name: &'static str,
idx: u32,
variant: &'static str,
value: &T
) -> Result<Self::Ok, Self::Error>
sourcefn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, Error>
fn serialize_seq(self, len: Option<usize>) -> Result<Self::SerializeSeq, Error>
serialize_element
, then a call to
end
. Read moresourcefn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple, Self::Error>
fn serialize_tuple(self, len: usize) -> Result<Self::SerializeTuple, Self::Error>
serialize_element
,
then a call to end
. Read moresourcefn serialize_tuple_struct(
self,
_name: &'static str,
len: usize
) -> Result<Self::SerializeTupleStruct, Self::Error>
fn serialize_tuple_struct(
self,
_name: &'static str,
len: usize
) -> Result<Self::SerializeTupleStruct, Self::Error>
struct Rgb(u8, u8, u8)
. This
call must be followed by zero or more calls to serialize_field
, then a
call to end
. Read moresourcefn serialize_tuple_variant(
self,
_name: &'static str,
idx: u32,
variant: &'static str,
len: usize
) -> Result<Self::SerializeTupleVariant, Error>
fn serialize_tuple_variant(
self,
_name: &'static str,
idx: u32,
variant: &'static str,
len: usize
) -> Result<Self::SerializeTupleVariant, Error>
E::T
in enum E { T(u8, u8) }
. This call must be followed by zero or more calls to
serialize_field
, then a call to end
. Read moresourcefn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Error>
fn serialize_map(self, len: Option<usize>) -> Result<Self::SerializeMap, Error>
serialize_key
and serialize_value
, then a call to end
. Read moresourcefn serialize_struct(
self,
_name: &'static str,
len: usize
) -> Result<Self::SerializeStruct, Self::Error>
fn serialize_struct(
self,
_name: &'static str,
len: usize
) -> Result<Self::SerializeStruct, Self::Error>
struct Rgb { r: u8, g: u8, b: u8 }
.
This call must be followed by zero or more calls to serialize_field
,
then a call to end
. Read moresourcefn serialize_struct_variant(
self,
name: &'static str,
id: u32,
variant: &'static str,
len: usize
) -> Result<Self::SerializeStructVariant, Error>
fn serialize_struct_variant(
self,
name: &'static str,
id: u32,
variant: &'static str,
len: usize
) -> Result<Self::SerializeStructVariant, Error>
E::S
in enum E { S { r: u8, g: u8, b: u8 } }
. This call must be followed by zero or more calls to
serialize_field
, then a call to end
. Read more