View Source EdgeDB.Protocol.Codec behaviour (EdgeDB v0.1.0)

A codec structure knows how to work with the internal binary data from EdgeDB.

The binary protocol specification for the codecs can be found on the official EdgeDB site.

Useful links for codec developers:

Link to this section Summary

Types

Options for defining custom codecs with EdgeDB.Protocol.Codec.defscalarcodec/1.

Function that can decode EdgeDB binary format into an entity.

Function that can encode an entity to EdgeDB binary format.

t()

A codec structure knows how to work with the internal binary data from EdgeDB.

UUID value.

Callbacks

Decode binary data from EdgeDB format to the expected entity.

Encode the entity into EdgeDB binary format.

Functions

Decode EdgeDB binary data into an enitity using the codec.

Macros for defining custom scalar codecs implementation.

Encode an entity into EdgeDB binary format using the codec.

Link to this section Types

Specs

codec_option() ::
  {:type, term()} | {:type_name, String.t()} | {:calculate_size, boolean()}

Options for defining custom codecs with EdgeDB.Protocol.Codec.defscalarcodec/1.

Supported options:

  • :type - typepec for the type that can be processed by the encoder/decoder function.
  • :type_name - the name of the EdgeDB type that can be processed by codec.
  • :calculate_size - flag specifying whether to automatically calculate the payload size for the encoder/decoder.

Specs

decoder() :: (t(), bitstring() -> term())

Function that can decode EdgeDB binary format into an entity.

Specs

encoder() :: (t(), term() -> iodata())

Function that can encode an entity to EdgeDB binary format.

Specs

t() :: %EdgeDB.Protocol.Codec{
  decoder: decoder(),
  encoder: encoder(),
  is_scalar: boolean(),
  module: module(),
  parent: module() | nil,
  type_id: uuid() | nil,
  type_name: String.t() | nil
}

A codec structure knows how to work with the internal binary data from EdgeDB.

Fields:

  • :type_id - EdgeDB type ID that can be encoded/decoded by the codec.
  • :type_name - optional name of the type that can be encoded/decoded by the codec.
  • :encoder - function that can encode an entity to EdgeDB binary format.
  • :decoder - function that can decode EdgeDB binary format into an entity.
  • :module - module which defines the implementation of the codec.
  • :parent - module, which was used as the base for the implementation of the codec.
  • :is_scalar - flag specifying that the codec is used to encode/decode EdgeDB scalar values.

Specs

uuid() :: String.t()

UUID value.

Link to this section Callbacks

Link to this callback

decode_instance(bitstring)

View Source

Specs

decode_instance(bitstring()) :: term()

Decode binary data from EdgeDB format to the expected entity.

Specs

encode_instance(term()) :: iodata()

Encode the entity into EdgeDB binary format.

Link to this section Functions

Specs

decode(t(), bitstring()) :: term()

Decode EdgeDB binary data into an enitity using the codec.

Link to this macro

defscalarcodec(opts)

View Source (macro)

Specs

defscalarcodec([codec_option()]) :: Macro.t()

Macros for defining custom scalar codecs implementation.

See custom codecs development guide for more information.

Specs

encode(t(), term()) :: iodata()

Encode an entity into EdgeDB binary format using the codec.