Struct dbn::encode::json::AsyncEncoder
source · pub struct AsyncEncoder<W>where
W: AsyncWriteExt + Unpin,{ /* private fields */ }async only.Expand description
Type for encoding files and streams of DBN records in newline-delimited JSON (ndjson).
Implementations§
source§impl<W> Encoder<W>where
W: AsyncWriteExt + Unpin,
impl<W> Encoder<W>where W: AsyncWriteExt + Unpin,
sourcepub fn new(
writer: W,
should_pretty_print: bool,
use_pretty_px: bool,
use_pretty_ts: bool
) -> Self
pub fn new( writer: W, should_pretty_print: bool, use_pretty_px: bool, use_pretty_ts: bool ) -> Self
Creates a new instance of Encoder. If should_pretty_print is true,
each JSON object will be nicely formatted and indented, instead of the default
compact output with no whitespace between key-value pairs.
sourcepub async fn encode_metadata(&mut self, metadata: &Metadata) -> Result<()>
pub async fn encode_metadata(&mut self, metadata: &Metadata) -> Result<()>
Encodes metadata into JSON.
Errors
This function returns an error if there’s an error writing to writer.
Cancel safety
This method is not cancellation safe. If the method is used in
tokio::select! statement and another branch completes first, then the
metadata JSON may have been partially written, but future calls will begin writing
the metadata JSON from the beginning.
sourcepub async fn encode_record<R: DbnEncodable>(&mut self, record: &R) -> Result<()>
pub async fn encode_record<R: DbnEncodable>(&mut self, record: &R) -> Result<()>
Encode a single DBN record of type R.
Errors
This function returns an error if it’s unable to write to the underlying writer.
Cancel safety
This method is not cancellation safe. If the method is used in
tokio::select! statement and another branch completes first, then the
record may have been partially written, but future calls will begin writing the
encoded record from the beginning.