pub struct Serializer { /* private fields */ }Expand description
Serializes values into MessagePack.
Every call to serialize writes an item, the items
follow each other (which is how MessagePack streams work).
use deser_msgpack::Serializer;
let mut serializer = Serializer::new();
serializer.serialize(&1u32).unwrap();
serializer.serialize(&"hi").unwrap();
assert_eq!(serializer.finish(), [0x01, 0xa2, b'h', b'i']);The serializer is also the stream serializer of MessagePack (see
StreamSerializer): the output can be taken
while values are written, and large values can be written in parts.
The output of arrays and maps whose length is not known upfront (and of
maps in canonical mode) is held back until they are complete, as their
header or the order of their entries is only known then. To write to
a Write use SerializerConfig::writer.
Implementations§
Source§impl Serializer
impl Serializer
Sourcepub fn new() -> Serializer
pub fn new() -> Serializer
Creates a serializer.
Sourcepub fn with_config(config: SerializerConfig) -> Serializer
pub fn with_config(config: SerializerConfig) -> Serializer
Creates a serializer with the given configuration.
Sourcepub fn config(&self) -> &SerializerConfig
pub fn config(&self) -> &SerializerConfig
Returns the configuration.
Sourcepub fn serialize<T: Serialize + ?Sized>(
&mut self,
value: &T,
) -> Result<(), Error>
pub fn serialize<T: Serialize + ?Sized>( &mut self, value: &T, ) -> Result<(), Error>
Serializes a value.
If the value fails to serialize, nothing is written.
Trait Implementations§
Source§impl Clone for Serializer
impl Clone for Serializer
Source§fn clone(&self) -> Serializer
fn clone(&self) -> Serializer
Clones the serializer.
The clone of a serializer that writes a value in parts cannot write
more values (see
StreamSerializer::in_progress).
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Serializer
impl Debug for Serializer
Source§impl Default for Serializer
impl Default for Serializer
Source§fn default() -> Serializer
fn default() -> Serializer
Source§impl Serializer for Serializer
impl Serializer for Serializer
Source§fn drive(&mut self, driver: &mut SerializeDriver<'_>) -> Result<(), Error>
fn drive(&mut self, driver: &mut SerializeDriver<'_>) -> Result<(), Error>
Source§fn serialize_with<T, F>(&mut self, value: &T, setup: F) -> Result<(), Error>
fn serialize_with<T, F>(&mut self, value: &T, setup: F) -> Result<(), Error>
Source§fn serialize_ref(&mut self, value: SerializeRef<'_>) -> Result<(), Error>
fn serialize_ref(&mut self, value: SerializeRef<'_>) -> Result<(), Error>
Source§impl StreamSerializer for Serializer
impl StreamSerializer for Serializer
Source§fn output(&self) -> &[u8] ⓘ
fn output(&self) -> &[u8] ⓘ
Source§fn clear_output(&mut self)
fn clear_output(&mut self)
output, for
instance because they were written.Source§fn supports_partial(&self) -> bool
fn supports_partial(&self) -> bool
Source§fn drive_partial(
&mut self,
driver: &mut SerializeDriver<'_>,
limit: usize,
) -> Result<bool, Error>
fn drive_partial( &mut self, driver: &mut SerializeDriver<'_>, limit: usize, ) -> Result<bool, Error>
Source§fn in_progress(&self) -> bool
fn in_progress(&self) -> bool
true if a value is partially serialized. Read more