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 and returns the corresponding bytes.
The base62 encoding uses the characters [0-9, A-Z, a-z], corresponding to values [0..61]. This function treats the first 10 digits ('0'–'9') as values 0–9, the next 26 letters ('A'–'Z') as values 10–35, and the final 26 letters ('a'–'z') as values 36–61.
An error is returned if the input string contains invalid characters.
Example usage:
decoded, err := DecodeBase62("0A1B")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Decoded bytes: %x\n", decoded)
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.