codec

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec interface {
	Encode(v interface{}) ([]byte, error)
	Decode(data []byte, target interface{}) error
}

A Codec can encode and decode values.

func Float64

func Float64() Codec

Float64 Codec handles float64 encoding.

func Int64

func Int64() Codec

Int64 Codec handles int64 encoding.

func JSON

func JSON() Codec

JSON Codec handles JSON encoding.

func String

func String() Codec

String encodes and decodes strings or byte slices into themselves. It is useful when passing raw data without touching it. The Encode method takes a byte slice, string, stringer or error and returns a byte slice. The Decode method turns data into v without touching it. v must be a pointer to byte slice or a pointer to string.

type Decoder

type Decoder interface {
	Decode(interface{}) error
	Bytes() []byte
}

A Decoder decodes encoded data. It can be decoded to an arbitrary value using the Decode method.

func Float64Decoder

func Float64Decoder(data []byte) Decoder

Float64Decoder returns a decoder using the Float64 codec.

func Int64Decoder

func Int64Decoder(data []byte) Decoder

Int64Decoder returns a decoder using the Int64 codec.

func JSONDecoder

func JSONDecoder(data []byte) Decoder

JSONDecoder returns a decoder using the JSON codec.

func NewDecoder

func NewDecoder(codec Codec, data []byte) Decoder

NewDecoder creates a decoder using the given codec.

func StringDecoder

func StringDecoder(data []byte) Decoder

StringDecoder returns a decoder using the String codec.

type Encoder

type Encoder interface {
	Encode() ([]byte, error)
	Length() int
}

Encoder is a simple interface for any type that can be encoded as an array of bytes in order to be sent as the key or value of a Kafka message. It matches the sarama.Encoder interface.

func Float64Encoder

func Float64Encoder(v float64) Encoder

Float64Encoder creates a Encoder that encodes using the Float64 Codec.

func Int64Encoder

func Int64Encoder(v int) Encoder

Int64Encoder creates a Encoder that encodes using the Int64 codec.

func JSONEncoder

func JSONEncoder(v interface{}) Encoder

JSONEncoder creates a Encoder that encodes using the JSON Codec.

func StringEncoder

func StringEncoder(v string) Encoder

StringEncoder creates a Encoder that encodes using the String codec.

Jump to

Keyboard shortcuts

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