Skip to main content

SchemaSerializer

Trait SchemaSerializer 

Source
pub trait SchemaSerializer {
    const FORMAT_NAME: &'static str;
    const FORMAT_ID: u8;

    // Required methods
    fn serialize(
        msg: &mut CdrReader<'_>,
        type_name: &str,
        schema: &'static [Field],
        out: &mut [u8],
    ) -> Result<usize, SchemaError>;
    fn deserialize(
        bytes: &[u8],
        type_name: &str,
        schema: &'static [Field],
        msg: &mut CdrWriter<'_>,
    ) -> Result<usize, SchemaError>;

    // Provided methods
    fn serialize_message<M: Message>(
        msg: &mut CdrReader<'_>,
        out: &mut [u8],
    ) -> Result<usize, SchemaError>
       where Self: Sized { ... }
    fn deserialize_message<M: Message>(
        bytes: &[u8],
        msg: &mut CdrWriter<'_>,
    ) -> Result<usize, SchemaError>
       where Self: Sized { ... }
}
Expand description

A serialization format implemented once, by walking the schema (RFC-0088 D7).

§How this differs from the D7 sketch, and why

D7 wrote serialize(msg: *const u8, schema, out). The host struct pointer is not usable — see the module docs for the three measured reasons — so the message side of both methods is the CDR byte stream instead: a CdrReader positioned at the members on the way out, a CdrWriter on the way back. Everything else survives: one implementation, every message, no generated code, the schema as the only description.

The second added parameter is type_name. A &'static [Field] slice has no name of its own — Message::TYPE_NAME is a separate const, and nested members carry theirs in crate::schema::NestedType — so without it the top-level struct would be the one node a self-describing format could not name. Use SchemaSerializer::serialize_message to supply both from a type.

Required Associated Constants§

Source

const FORMAT_NAME: &'static str

Cross-image identity (RFC-0088 D2). The string, never the number, is what crosses an image boundary.

Source

const FORMAT_ID: u8

Image-local discriminant, as a raw u8 rather than a crate::format::SerializationFormatId: the enum reserves values for in-tree formats, and a third-party provider is assigned one by the build from the set of formats its image declares. A provider that becomes in-tree gains a variant; one that does not still has a number here.

Required Methods§

Source

fn serialize( msg: &mut CdrReader<'_>, type_name: &str, schema: &'static [Field], out: &mut [u8], ) -> Result<usize, SchemaError>

Encode one message from its CDR form into out, returning bytes written.

Source

fn deserialize( bytes: &[u8], type_name: &str, schema: &'static [Field], msg: &mut CdrWriter<'_>, ) -> Result<usize, SchemaError>

Decode one message from bytes into CDR, returning bytes consumed.

Provided Methods§

Source

fn serialize_message<M: Message>( msg: &mut CdrReader<'_>, out: &mut [u8], ) -> Result<usize, SchemaError>
where Self: Sized,

Self::serialize with the name and schema taken from the type.

Source

fn deserialize_message<M: Message>( bytes: &[u8], msg: &mut CdrWriter<'_>, ) -> Result<usize, SchemaError>
where Self: Sized,

Self::deserialize with the name and schema taken from the type.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§