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
Codectrait, 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'staticto allow sharing across threads. - Statelessness: Implementations are generally expected to be stateless.
- Serialization Support: Relies on
serdefor JSON andprostfor Protocol Buffers.
Structs§
- Json
Codec - Implements
Codecfor the JSON format. - Json
Decoder Options - Options for JSON decoding.
- Json
Encoder Options - Options for JSON encoding.
- Multimedia
Codec - Implements
Codecfor both JSON and Protocol Buffers formats. - Protobuf
Codec - Implements
Codecfor the Protocol Buffers binary format.
Traits§
- Codec
- Defines how to encode and decode gRPC messages to/from HTTP bodies.