Codec

Trait Codec 

Source
pub trait Codec {
    type Serializer: ShapeSerializer;
    type Deserializer<'a>: ShapeDeserializer;

    // Required methods
    fn create_serializer(&self) -> Self::Serializer;
    fn create_deserializer<'a>(&self, input: &'a [u8]) -> Self::Deserializer<'a>;
}
Expand description

A codec for a specific serialization format.

Codecs are responsible for creating ShapeSerializer and ShapeDeserializer instances that can serialize and deserialize shapes to and from a specific format.

§Examples

Implementing a custom codec:

use aws_smithy_schema::codec::Codec;
use aws_smithy_schema::serde::{ShapeSerializer, ShapeDeserializer};

struct MyCodec {
    // codec configuration
}

impl Codec for MyCodec {
    type Serializer = MySerializer;
    type Deserializer = MyDeserializer;

    fn create_serializer(&self) -> Self::Serializer {
        MySerializer::new()
    }

    fn create_deserializer(&self, input: &[u8]) -> Self::Deserializer {
        MyDeserializer::new(input)
    }
}

Required Associated Types§

Source

type Serializer: ShapeSerializer

The serializer type for this codec.

Source

type Deserializer<'a>: ShapeDeserializer

The deserializer type for this codec.

Required Methods§

Source

fn create_serializer(&self) -> Self::Serializer

Creates a new serializer for this codec.

Source

fn create_deserializer<'a>(&self, input: &'a [u8]) -> Self::Deserializer<'a>

Creates a new deserializer for this codec from the given input bytes.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§