Skip to main content

Codec

Trait Codec 

Source
pub trait Codec<T: ?Sized> {
    // Required methods
    fn content_type() -> ContentType;
    fn encode(value: &T) -> Result<Vec<u8>, DecodeError>;
}
Expand description

Encoding strategy for a typed body. Four first-party codecs ship here, all self-describing so LaserData Cloud’s projector can index their fields without a schema: Json (serde_json), Msgpack (rmp_serde), Cbor (ciborium), and Bson (bson, native-only feature). For a schema-first format (Avro or Protobuf), Arrow, or your own framing, implement Codec on a marker type. The codec advertises its ContentType so consumers can decode downstream.

The trait is generic on T so codecs can constrain the body type they accept. Serde-based codecs constrain T: Serialize, a Prost codec constrains T: prost::Message.

struct AvroCodec<S>(std::marker::PhantomData<S>);
// Where `S` is your generated Avro schema:
// impl<S: AvroSerialize> Codec<S> for AvroCodec<S> {
//     fn content_type() -> ContentType { ContentType::Avro }
//     fn encode(value: &S) -> Result<Vec<u8>, DecodeError> {
//         avro::to_avro_bytes(value).map_err(|e| DecodeError::Encode(e.to_string()))
//     }
// }

Required Methods§

Source

fn content_type() -> ContentType

The wire-format tag stamped on agdx.ct.

Source

fn encode(value: &T) -> Result<Vec<u8>, DecodeError>

Encode value into the bytes that ride the Iggy payload.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T: Serialize + ?Sized> Codec<T> for Cbor

Source§

impl<T: Serialize + ?Sized> Codec<T> for Json

Source§

impl<T: Serialize + ?Sized> Codec<T> for Msgpack

Source§

impl<T: Serialize> Codec<T> for Bson

Available on crate feature bson only.