codecs

package
v2.75.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 13 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec interface {
	Decoder
	Encoder
}

Codec embeds both Decoder and Encoder.

var Binary Codec = codecBinary{}

Binary codec encodes and decodes binary requests and responses. Decode/Unmarshal accepts an io.Writer and copies content to the writer. Encode/Marshal accepts an io.Reader and copies content from the reader.

var FormURLEncoded Codec = codecFormURLEncoded{}

FormURLEncoded (de)serializes Form parameters.

var JSON Codec = codecJSON{}

JSON codec encodes and decodes JSON requests and responses using github.com/palantir/pkg/safejson. On Decode, it sets UseNumber on the json.Decoder to account for large numbers. On Encode, we disable HTML escaping, which for bad reasons (as acknowledged by go team), is default-enabled.

var Plain Codec = codecPlain{}

Plain implements a text/plain codec. Values used to marshal/unmarshal must be of type string or encoding.TextMarshaler/encoding.TextUnmarshaler.

var Protobuf Codec = codecProtobuf{}

Protobuf codec encodes and decodes protobuf requests and responses using google.golang.org/protobuf.

func GZIP added in v2.58.0

func GZIP(codec Codec) Codec

GZIP wraps an existing Codec and uses gzip for compression and decompression.

func Snappy added in v2.47.0

func Snappy(codec Codec) Codec

Snappy wraps an existing Codec and uses snappy with no-framing for compression and decompression using github.com/golang/snappy. Ref: https://github.com/google/snappy/blob/main/format_description.txt

func ZLIB

func ZLIB(codec Codec) Codec

ZLIB wraps an existing Codec and uses zlib for compression and decompression.

type Decoder

type Decoder interface {
	Accept() string
	Decode(r io.Reader, v interface{}) error
	Unmarshal(data []byte, v interface{}) error
}

A Decoder decodes a serialized message.

type Encoder

type Encoder interface {
	ContentType() string
	Encode(w io.Writer, v interface{}) error
	Marshal(v interface{}) ([]byte, error)
}

An Encoder serializes a message.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL