Documentation
¶
Index ¶
- Constants
- Variables
- func MarshalHeader(x any, header Header) ([]byte, error)
- func SetContentEncoding(h Header, e ContentEncoding)
- func TypeFromHeaderCopy(dst, src Header)
- func UnmarshalHeader(data []byte, x any, header Header) error
- type Codec
- type Compressor
- type ContentEncoding
- type ContentType
- type Header
Constants ¶
const HeaderContentEncoding = "Content-Encoding"
const HeaderContentType = "Content-Type"
Variables ¶
var ErrUnsupportedEncoding = errors.New("unsupported content encoding")
ErrUnsupportedEncoding is returned when a Content-Encoding value is not recognized.
Functions ¶
func MarshalHeader ¶
MarshalHeader encodes x using the codec specified in the header, then compresses the result if Content-Encoding is set.
func SetContentEncoding ¶ added in v0.24.0
func SetContentEncoding(h Header, e ContentEncoding)
SetContentEncoding sets the Content-Encoding header value.
func TypeFromHeaderCopy ¶
func TypeFromHeaderCopy(dst, src Header)
TypeFromHeaderCopy copies the Content-Type from src to dst, defaulting to JSON.
Types ¶
type Codec ¶
type Codec interface {
Marshal(any) ([]byte, error)
Unmarshal([]byte, any) error
ContentType() ContentType
SetContentType(Header)
MatchContentType(Header) bool
}
Codec defines the interface for message serialization/deserialization.
func ForContentType ¶
func ForContentType(c ContentType) (Codec, error)
ForContentType returns the codec for the given content type.
type Compressor ¶ added in v0.24.0
type Compressor interface {
Compress([]byte) ([]byte, error)
Decompress([]byte) ([]byte, error)
ContentEncoding() ContentEncoding
}
Compressor defines the interface for message compression/decompression.
func ForContentEncoding ¶ added in v0.24.0
func ForContentEncoding(e ContentEncoding) (Compressor, error)
ForContentEncoding returns the compressor for the given content encoding.
type ContentEncoding ¶ added in v0.24.0
type ContentEncoding uint16
ContentEncoding represents a supported compression algorithm.
const ( Zstd ContentEncoding = iota + 1 S2 )
func EncodingFromHeader ¶ added in v0.24.0
func EncodingFromHeader(h Header) ContentEncoding
EncodingFromHeader extracts the ContentEncoding from a header. Returns 0 if absent or unrecognized.
func (ContentEncoding) String ¶ added in v0.24.0
func (e ContentEncoding) String() string
type ContentType ¶
type ContentType uint16
ContentType represents a supported serialization format.
const ( JSON ContentType YAML Msgpack Protojson Prototext Protobin Default = JSON )
func TypeFromHeader ¶
func TypeFromHeader(header Header) ContentType
TypeFromHeader extracts the ContentType from a header, defaulting to JSON.
func (ContentType) String ¶
func (c ContentType) String() string
type Header ¶
type Header = textproto.MIMEHeader
Header is a type alias for textproto.MIMEHeader, identical to peanats.Header. Defined here to avoid circular imports between codec and root packages.