codec

package
v0.0.0-...-566873a Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2021 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

codec

Index

Constants

View Source
const (
	Json     = "Json"
	Protobuf = "Protobuf"
	Thrift   = "Thrift"
	Msgpack  = "MessagePack"
	Gob      = "Gob"
)

Variables

This section is empty.

Functions

func RegisterCompressor

func RegisterCompressor(name string, compressor Compressor)

RegisterCompressor

func RegisterMarshaler

func RegisterMarshaler(name string, marshaller Marshaler)

RegisterMarshaller

Types

type Codec

type Codec interface {
	// Encode
	Encode(req interface{}) ([]byte, error)

	// Decode
	Decode(req, rsp interface{}) error
}

Codec Interface

func GetCodec

func GetCodec(name string) Codec

GetCodec

func RegisterCodec

func RegisterCodec(name string, codec Codec) Codec

RegisterCodec

type Compressor

type Compressor interface {
	// Zip
	Zip(v interface{}) ([]byte, error)

	// Unzip
	Unzip(data []byte, v interface{}) error
}

Compressor

type GzipCompressor

type GzipCompressor struct{}

GzipCompressor

func (GzipCompressor) Unzip

func (c GzipCompressor) Unzip(data []byte) ([]byte, error)

func (GzipCompressor) Zip

func (c GzipCompressor) Zip(data []byte) ([]byte, error)

type JsonMarshaler

type JsonMarshaler struct{}

JsonMarshaler

func (*JsonMarshaler) Marshal

func (jm *JsonMarshaler) Marshal(v interface{}) ([]byte, error)

Marshal

func (*JsonMarshaler) Unmarshal

func (jm *JsonMarshaler) Unmarshal(data []byte, v interface{}) error

Unmarshal

type Marshaler

type Marshaler interface {
	// Marshal
	Marshal(v interface{}) ([]byte, error)

	// Unmarshal
	Unmarshal(data []byte, v interface{}) error
}

Marshaler encode/decode go struct

func GetMarshaler

func GetMarshaler(name string) Marshaler

type MsgpackMarshaler

type MsgpackMarshaler struct{}

MsgpackMarshaler

func (*MsgpackMarshaler) Marshal

func (mm *MsgpackMarshaler) Marshal(v interface{}) ([]byte, error)

func (*MsgpackMarshaler) Unmarshal

func (mm *MsgpackMarshaler) Unmarshal(data []byte, v interface{}) error

type ProtobufMarshaler

type ProtobufMarshaler struct{}

ProtobufMarshaler

func (*ProtobufMarshaler) Marshal

func (s *ProtobufMarshaler) Marshal(body interface{}) ([]byte, error)

Marshal

func (*ProtobufMarshaler) Unmarshal

func (s *ProtobufMarshaler) Unmarshal(in []byte, body interface{}) error

/ Unmarshal 反序列protobuf

type RawDataCompressor

type RawDataCompressor struct {
}

func (RawDataCompressor) Unzip

func (c RawDataCompressor) Unzip(data []byte) ([]byte, error)

func (RawDataCompressor) Zip

func (c RawDataCompressor) Zip(data []byte) ([]byte, error)

type SnappyCompressor

type SnappyCompressor struct{}

SnappyCompressor implements snappy compressor

func (*SnappyCompressor) Unzip

func (c *SnappyCompressor) Unzip(data []byte) ([]byte, error)

func (*SnappyCompressor) Zip

func (c *SnappyCompressor) Zip(data []byte) ([]byte, error)

type ThriftMarshaler

type ThriftMarshaler struct{}

ThriftMarshaler

func (*ThriftMarshaler) Marshal

func (tm *ThriftMarshaler) Marshal(v interface{}) ([]byte, error)

func (*ThriftMarshaler) Unmarshal

func (tm *ThriftMarshaler) Unmarshal(data []byte, v interface{}) error

Jump to

Keyboard shortcuts

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