Skip to main content

Module codec

Module codec 

Source
Expand description

§Codec

§Purpose

Defines the interface and implementations for encoding and decoding gRPC messages to and from HTTP body formats. This module abstracts the wire format details, allowing the gateway to support multiple content types (e.g., JSON, Protocol Buffers).

§Scope

This module provides:

  • The Codec trait, which defines the contract for message serialization and deserialization.
  • ProtobufCodec: A concrete implementation for the binary Protocol Buffers format (application/octet-stream).
  • JsonCodec: A concrete implementation for the JSON format (application/json).
  • MultimediaCodec: A codec that selects between JSON and Protocol Buffers based on MIME types.

§Position in the Architecture

The Codec is used by the generated service registration code to unmarshal incoming HTTP request bodies into gRPC request messages and to marshal gRPC response messages back into HTTP response bodies.

§Design Constraints

  • Concurrency: Codecs must be Send, Sync, and 'static to allow sharing across threads.
  • Statelessness: Implementations are generally expected to be stateless.
  • Serialization Support: Relies on serde for JSON and prost for Protocol Buffers.

Structs§

JsonCodec
Implements Codec for the JSON format.
JsonDecoderOptions
Options for JSON decoding.
JsonEncoderOptions
Options for JSON encoding.
MultimediaCodec
Implements Codec for both JSON and Protocol Buffers formats.
ProtobufCodec
Implements Codec for the Protocol Buffers binary format.

Traits§

Codec
Defines how to encode and decode gRPC messages to/from HTTP bodies.