fuel_core_storage

Module codec

source
Expand description

The module contains the traits for encoding and decoding the types(a.k.a Codec). It implements common codecs and encoders, but it is always possible to define own codecs.

Modules§

  • The module contains the implementation of the Manual codec. The codec allows the definition of manual implementation for specific types that don’t follow any patterns from other codecs. Anyone can implement a codec like that, and it’s more of an example of how it can be done for foreign types.
  • The module contains the implementation of the Postcard codec. Any type that implements serde::Serialize and serde::Deserialize can use the Postcard codec to be encoded/decoded into/from bytes. The serde serialization and deserialization add their own overhead, so this codec shouldn’t be used for simple types.
  • The module contains the implementation of the Postcard codec. The codec is used for types that can be represented by an array. It includes all primitive types and types that are arrays inside or could be represented by arrays.
  • The module contains the implementation of the Raw codec. The codec is used for types that are already represented by bytes and can be deserialized into bytes-based objects.

Traits§

  • The trait decodes the type from the bytes.
  • The trait encodes the type to the bytes and passes it to the Encoder, which stores it and provides a reference to it. That allows gives more flexibility and more performant encoding, allowing the use of slices and arrays instead of vectors in some cases. Since the Encoder returns Cow<[u8]>, it is always possible to take ownership of the serialized value.
  • The trait is usually implemented by the encoder that stores serialized objects.