pub struct Codec {
pub format: Format,
pub channels: usize,
pub order: ByteOrder,
pub suppress_subnormals: bool,
}Expand description
Everything a codec call needs to know about the connection.
Fields§
§format: FormatThe format of every channel in the stream.
channels: usizeThe number of channels in one sample.
order: ByteOrderThe byte order that the connection selected.
suppress_subnormals: boolTrue when the reader clears subnormal values. SPEC.md 7.4.
Implementations§
Source§impl Codec
impl Codec
Sourcepub fn encode(&self, s: &Sample, out: &mut Vec<u8>) -> Result<(), Error>
pub fn encode(&self, s: &Sample, out: &mut Vec<u8>) -> Result<(), Error>
Write one sample to the end of out.
The layout is the tag byte, then an optional timestamp, then one value per channel. SPEC.md 7.1.
Sourcepub fn encode_to_vec(&self, s: &Sample) -> Result<Vec<u8>, Error>
pub fn encode_to_vec(&self, s: &Sample) -> Result<Vec<u8>, Error>
Write one sample and return the bytes.
Sourcepub fn encode_packed(
&self,
s: &PackedSample,
out: &mut Vec<u8>,
) -> Result<(), Error>
pub fn encode_packed( &self, s: &PackedSample, out: &mut Vec<u8>, ) -> Result<(), Error>
Write one PackedSample to the end of out using a single slice copy
on native byte order.
Sourcepub fn encode_packed_at(
&self,
s: &PackedSample,
timestamp: f64,
out: &mut Vec<u8>,
) -> Result<(), Error>
pub fn encode_packed_at( &self, s: &PackedSample, timestamp: f64, out: &mut Vec<u8>, ) -> Result<(), Error>
Write one PackedSample with an explicit timestamp override, without
cloning the sample.
Source§impl Codec
impl Codec
Sourcepub fn decode(&self, buf: &[u8]) -> Result<(Sample, usize), Error>
pub fn decode(&self, buf: &[u8]) -> Result<(Sample, usize), Error>
Read one sample from the start of buf.
Returns the sample and the number of bytes that it used.
Sourcepub fn decode_packed(&self, buf: &[u8]) -> Result<(PackedSample, usize), Error>
pub fn decode_packed(&self, buf: &[u8]) -> Result<(PackedSample, usize), Error>
Read one PackedSample directly from the start of buf without
allocating a Vec<Value>.