Documentation
¶
Overview ¶
Package codec provides encoding and decoding functionality for different data formats.
Package codec provides encoding and decoding functionality for different data formats.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JSONCodec ¶
JSONCodec is a codec that uses JSON for marshaling and unmarshaling. It implements the Codec interface for encoding responses and decoding requests.
func NewJSONCodec ¶
NewJSONCodec creates a new JSONCodec instance for the specified types. T represents the request type and U represents the response type.
type ProtoCodec ¶
ProtoCodec is a codec that uses Protocol Buffers for marshaling and unmarshaling. This is a basic implementation that requires the types T and U to implement the proto.Message interface and have Marshal/Unmarshal methods. It implements the Codec interface for encoding responses and decoding requests.
func NewProtoCodec ¶
func NewProtoCodec[T any, U any]() *ProtoCodec[T, U]
NewProtoCodec creates a new ProtoCodec instance for the specified types. T represents the request type and U represents the response type. Both types must implement the appropriate Protocol Buffers methods.
func (*ProtoCodec[T, U]) Decode ¶
func (c *ProtoCodec[T, U]) Decode(r *http.Request) (T, error)
Decode decodes the request body into a value of type T. It reads the entire request body and unmarshals it from Protocol Buffers format. The type T must implement the Unmarshal method.
func (*ProtoCodec[T, U]) Encode ¶
func (c *ProtoCodec[T, U]) Encode(w http.ResponseWriter, resp U) error
Encode encodes a value of type U into the response. It marshals the value to Protocol Buffers format and writes it to the response with the appropriate content type. The type U must implement the Marshal method.