Documentation
¶
Overview ¶
Package codec provides encoding and decoding functionality for different data formats.
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 ¶
func DecodeBase62 ¶ added in v1.0.5
DecodeBase62 decodes a base62-encoded string to bytes. Base62 is a subset of base64 that uses only alphanumeric characters (A-Z, a-z, 0-9). This encoding is useful for URLs and other contexts where special characters might cause issues. This function is used by the router when processing requests with Base62QueryParameter or Base62PathParameter source types.
Parameters:
- encoded: The base62-encoded string to decode
Returns:
- []byte: The decoded bytes
- error: An error if the input is not valid base62 or if decoding is not implemented
func DecodeBase64 ¶ added in v1.0.5
DecodeBase64 decodes a base64-encoded string to bytes. It uses the standard base64 encoding as defined in RFC 4648. This function is used by the router when processing requests with Base64QueryParameter or Base64PathParameter source types.
Parameters:
- encoded: The base64-encoded string to decode
Returns:
- []byte: The decoded bytes
- error: An error if the input is not valid base64
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 ¶
Force T to be a pointer to a type implementing proto.Message.
func NewProtoCodec ¶
func NewProtoCodec[T proto.Message, U proto.Message]() *ProtoCodec[T, U]
NewProtoCodec creates a new ProtoCodec instance.
func (*ProtoCodec[T, U]) Decode ¶
func (c *ProtoCodec[T, U]) Decode(r *http.Request) (T, error)
Decode reads the request body and unmarshals into T (which is a pointer).
func (*ProtoCodec[T, U]) Encode ¶
func (c *ProtoCodec[T, U]) Encode(w http.ResponseWriter, resp U) error
Encode marshals U (also a pointer type) and writes to response.