encoding

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package encoding Provides encoding and decoding of json, protobuf and gob.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotAPointer .
	ErrNotAPointer = errors.New("v argument must be a pointer")
)

Functions

func GzipDecode

func GzipDecode(in []byte) ([]byte, error)

GzipDecode decode

func GzipEncode

func GzipEncode(in []byte) ([]byte, error)

GzipEncode encoding

func Marshal

func Marshal(e Encoding, v interface{}) (data []byte, err error)

Marshal encode data

func RegisterCodec

func RegisterCodec(codec Codec)

RegisterCodec registers the provided Codec for use with all transport clients and servers.

The Codec will be stored and looked up by result of its Name() method, which should match the content-subtype of the encoding handled by the Codec. This is case-insensitive, and is stored and looked up as lowercase. If the result of calling Name() is an empty string, RegisterCodec will panic. See Content-Type on https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#requests for more details.

NOTE: this function must only be called during initialization time (i.e. in an init() function), and is not thread-safe. If multiple Compressors are registered with the same name, the one registered last will take effect.

func Unmarshal

func Unmarshal(e Encoding, data []byte, v interface{}) (err error)

Unmarshal decode data

Types

type Codec

type Codec interface {
	// Marshal returns the wire format of v.
	Marshal(v interface{}) ([]byte, error)
	// Unmarshal parses the wire format into v.
	Unmarshal(data []byte, v interface{}) error
	// Name returns the name of the Codec implementation. The returned string
	// will be used as part of content type in transmission.  The result must be
	// static; the result cannot change between calls.
	Name() string
}

Codec defines the interface gRPC uses to encode and decode messages. Note that implementations of this interface must be thread safe; a Codec's methods can be called from concurrent goroutines.

func GetCodec

func GetCodec(contentSubtype string) Codec

GetCodec gets a registered Codec by content-subtype, or nil if no Codec is registered for the content-subtype.

The content-subtype is expected to be lowercase.

type Encoding

type Encoding interface {
	Marshal(v interface{}) ([]byte, error)
	Unmarshal(data []byte, v interface{}) error
}

Encoding definition of coding interfaces

type GobEncoding

type GobEncoding struct{}

GobEncoding gob encode

func (GobEncoding) Marshal

func (g GobEncoding) Marshal(v interface{}) ([]byte, error)

Marshal gob encode

func (GobEncoding) Unmarshal

func (g GobEncoding) Unmarshal(data []byte, value interface{}) error

Unmarshal gob encode

type JSONEncoding

type JSONEncoding struct{}

JSONEncoding json format

func (JSONEncoding) Marshal

func (j JSONEncoding) Marshal(v interface{}) ([]byte, error)

Marshal json encode

func (JSONEncoding) Unmarshal

func (j JSONEncoding) Unmarshal(data []byte, value interface{}) error

Unmarshal json decode

type JSONGzipEncoding

type JSONGzipEncoding struct{}

JSONGzipEncoding json and gzip

func (JSONGzipEncoding) Marshal

func (jz JSONGzipEncoding) Marshal(v interface{}) ([]byte, error)

Marshal json encode and gzip

func (JSONGzipEncoding) Unmarshal

func (jz JSONGzipEncoding) Unmarshal(data []byte, value interface{}) error

Unmarshal json encode and gzip

type JSONSnappyEncoding

type JSONSnappyEncoding struct{}

JSONSnappyEncoding json format and snappy compression

func (JSONSnappyEncoding) Marshal

func (s JSONSnappyEncoding) Marshal(v interface{}) (data []byte, err error)

Marshal serialization

func (JSONSnappyEncoding) Unmarshal

func (s JSONSnappyEncoding) Unmarshal(data []byte, value interface{}) error

Unmarshal deserialization

type MsgPackEncoding

type MsgPackEncoding struct{}

MsgPackEncoding msgpack format

func (MsgPackEncoding) Marshal

func (mp MsgPackEncoding) Marshal(v interface{}) ([]byte, error)

Marshal msgpack encode

func (MsgPackEncoding) Unmarshal

func (mp MsgPackEncoding) Unmarshal(data []byte, value interface{}) error

Unmarshal msgpack decode

Directories

Path Synopsis
Package json is a JSON encoding and decoding.
Package json is a JSON encoding and decoding.
Package proto is a protobuf encoding and decoding.
Package proto is a protobuf encoding and decoding.

Jump to

Keyboard shortcuts

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