Skip to main content

Module encode

Module encode 

Source
Expand description

Encoding DBN records to various formats: DBN binary, CSV, and JSON.

Each format has a dedicated encoder (DbnEncoder, CsvEncoder, JsonEncoder). When the format is chosen at runtime, use DynEncoder with DynEncoderBuilder.

Sync encoders implement the EncodeDbn trait. With the async feature flag, async variants are also available.

§Examples

Encode records to DBN in memory:

use dbn::{
    MboMsg, Metadata, Schema, SType,
    encode::{DbnEncoder, EncodeRecord},
    decode::{DbnDecoder, DecodeRecord},
};

let metadata = Metadata::builder()
    .dataset("GLBX.MDP3")
    .schema(Some(Schema::Mbo))
    .start(0)
    .stype_in(Some(SType::InstrumentId))
    .stype_out(SType::InstrumentId)
    .build();

let mut buf = Vec::new();
let mut encoder = DbnEncoder::new(&mut buf, &metadata)?;
encoder.encode_record(&MboMsg::default())?;
drop(encoder);

// Read back
let mut decoder = DbnDecoder::new(buf.as_slice())?;
let rec = decoder.decode_record::<MboMsg>()?.unwrap();
assert_eq!(*rec, MboMsg::default());

Re-exports§

pub use self::csv::Encoder as CsvEncoder;
pub use self::dbn::Encoder as DbnEncoder;
pub use self::dbn::MetadataEncoder as DbnMetadataEncoder;
pub use self::dbn::RecordEncoder as DbnRecordEncoder;
pub use self::json::Encoder as JsonEncoder;
pub use self::dbn::AsyncEncoder as AsyncDbnEncoder;async
pub use self::dbn::AsyncMetadataEncoder as AsyncDbnMetadataEncoder;async
pub use self::dbn::AsyncRecordEncoder as AsyncDbnRecordEncoder;async
pub use self::json::AsyncEncoder as AsyncJsonEncoder;async

Modules§

csv
Encoding of DBN records into comma-separated values (CSV).
dbn
Encoding DBN records into DBN, Zstandard-compressed or not.
json
Encoding of DBN records into JSON lines.

Structs§

DynAsyncBufWriterasync
An object that allows for abstracting over compressed and uncompressed output with buffering.
DynAsyncWriterasync
An object that allows for abstracting over compressed and uncompressed output.
DynEncoder
An encoder whose Encoding and Compression can be set at runtime.
DynEncoderBuilder
Helper for constructing a DynEncoder.
DynWriter
Type for runtime polymorphism over whether encoding uncompressed or Zstd-compressed DBN records. Implements std::io::Write.
SchemaSplitter
Splits a stream by schema.
SplitEncoder
An encoder that routes records to sub-encoders based on a Splitter strategy.
SymbolSplitter
Splits a stream by symbol.
TimeSplitter
Splits a stream by time.

Enums§

NoSchemaBehavior
How to handle records with an rtype that doesn’t map to a schema such as an ErrorMsg.
SplitDuration
How to group records according to their index timestamp.

Constants§

ZSTD_COMPRESSION_LEVEL
The default Zstandard compression level used.

Traits§

AsyncEncodeRecordasync
Trait for async encoding of DBN records of a specific type.
AsyncEncodeRecordRefasync
Trait for async encoding of DBN of RecordRef records.
AsyncEncodeRecordTextExtasync
Async extension trait for text encodings.
DbnEncodable
Trait alias for Record, CsvSerialize, fmt::Debug, and JsonSerialize.
EncodeDbn
Trait for types that encode DBN records with a specific record type.
EncodeRecord
Trait for types that encode a DBN record of a specific type.
EncodeRecordRef
Trait for types that encode DBN records with mixed schemas.
EncodeRecordTextExt
Extension trait for text encodings.
Splitter
A strategy for routing records to different sub-encoders.