pub struct Encoder<T> { /* private fields */ }
Expand description
Encodes XML into buffers.
Encoders are stateful. They can only be used to encode a single XML document and have then to be disposed.
use rxml::{Encoder, Item, XmlVersion};
use bytes::BytesMut;
let mut enc = Encoder::new();
let mut buf = BytesMut::new();
enc.encode(Item::XmlDeclaration(XmlVersion::V1_0), &mut buf);
assert_eq!(&buf[..], b"<?xml version='1.0' encoding='utf-8'?>\n");
Implementations§
source§impl Encoder<SimpleNamespaces>
impl Encoder<SimpleNamespaces>
sourcepub fn new() -> Self
pub fn new() -> Self
Create a new default encoder.
This encoder uses the SimpleNamespaces
strategy, which is not
optimal with respect to the number of bytes written, but has reduced
memory cost.
source§impl<T: TrackNamespace> Encoder<T>
impl<T: TrackNamespace> Encoder<T>
pub fn inner(&self) -> &T
pub fn inner_mut(&mut self) -> &mut T
sourcepub fn encode<O: BufMut>(
&mut self,
item: Item<'_>,
output: &mut O
) -> Result<(), EncodeError>
pub fn encode<O: BufMut>(
&mut self,
item: Item<'_>,
output: &mut O
) -> Result<(), EncodeError>
Encode a single item into a buffer.
There is no requirement for the buffer to be the same for subsequent calls to this function. This allows users to use small, but long-lived, buffers for serialization before sending data over the network, for instance.
sourcepub fn encode_into_bytes(
&mut self,
item: Item<'_>,
output: &mut BytesMut
) -> Result<(), EncodeError>
pub fn encode_into_bytes(
&mut self,
item: Item<'_>,
output: &mut BytesMut
) -> Result<(), EncodeError>
Encode a single item into a BytesMut.
This might have a slight performance advantage over
encode
in some scenarios, as it might be able to give
the BytesMut a heads up about required space, thus avoiding frequent
reallocations.
There is no requirement for the buffer to be the same for subsequent calls to this function. This allows users to use small, but long-lived, buffers for serialization before sending data over the network, for instance.
sourcepub fn encode_event<O: BufMut>(
&mut self,
ev: &ResolvedEvent,
output: &mut O
) -> Result<(), EncodeError>
pub fn encode_event<O: BufMut>(
&mut self,
ev: &ResolvedEvent,
output: &mut O
) -> Result<(), EncodeError>
Encode a single event into a buffer.
This internally decomposes the event into multiple items and then
encodes these into the given buffer using encode
.
sourcepub fn encode_event_into_bytes(
&mut self,
ev: &ResolvedEvent,
output: &mut BytesMut
) -> Result<(), EncodeError>
pub fn encode_event_into_bytes(
&mut self,
ev: &ResolvedEvent,
output: &mut BytesMut
) -> Result<(), EncodeError>
Encode a single event into a BytesMut.
This internally decomposes the event into multiple items and then
encodes these into the given buffer using encode_into_bytes
.
Trait Implementations§
source§impl<T: TrackNamespace> From<T> for Encoder<T>
impl<T: TrackNamespace> From<T> for Encoder<T>
source§fn from(ns: T) -> Self
fn from(ns: T) -> Self
Create an encoder from a TrackNamespace
instance.
Use your own custom namespace strategy.