Codec

Trait Codec 

Source
pub trait Codec {
    type Serializer: ShapeSerializer;
    type Deserializer: ShapeDeserializer;

    // Required methods
    fn create_serializer(&self) -> Self::Serializer;
    fn create_deserializer(&self, input: &[u8]) -> Self::Deserializer;
}
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: 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(&self, input: &[u8]) -> Self::Deserializer

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

Implementors§