codec

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NilCodecID 空的编解码器id.
	NilCodecID byte = 0
	// NilCodecName 空的编解码器名称.
	NilCodecName string = ""
)
View Source
const (
	FormName = "form"
	FormId   = 'f'
)
View Source
const (
	JsonName = "json"
	JsonId   = 'j'
)
View Source
const (
	PlainName = "plain"
	PlainId   = 's'
)
View Source
const (
	ProtobufName = "protobuf"
	ProtobufId   = 'p'
)
View Source
const (
	XmlName = "xml"
	XmlId   = 'x'
)

Variables

View Source
var File_empty_proto protoreflect.FileDescriptor
View Source
var (
	// PbEmptyStruct 如果需要编码nil 或者struct,则不能编码,使用空的
	PbEmptyStruct = new(PbEmpty)
)

Functions

func Marshal

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

Marshal 使用指定编解码器编码

func ProtoMarshal added in v0.2.0

func ProtoMarshal(v interface{}) ([]byte, error)

func ProtoUnmarshal added in v0.2.0

func ProtoUnmarshal(data []byte, v interface{}) error

func Reg

func Reg(codec Codec)

Reg 注册编解码器到容器

func Unmarshal

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

Unmarshal 使用指定编解码器解码

Types

type Codec

type Codec interface {
	ID() byte
	Name() string
	Marshal(interface{}) ([]byte, error)
	Unmarshal([]byte, interface{}) error
}

Codec 消息内容的编解码器

func Get

func Get(codecID byte) (Codec, error)

Get 通过编解码器的id获取编解码器对象

func GetByName

func GetByName(codecName string) (Codec, error)

GetByName 通过编解码器的名字获取编解码器对象

type FormCodec added in v0.0.3

type FormCodec struct{}

FormCodec url encode codec

func (FormCodec) ID added in v0.0.3

func (FormCodec) ID() byte

ID returns codec id.

func (FormCodec) Marshal added in v0.0.3

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

func (FormCodec) Name added in v0.0.3

func (FormCodec) Name() string

Name returns codec name.

func (FormCodec) Unmarshal added in v0.0.3

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

type JSONCodec

type JSONCodec struct{}

func (JSONCodec) ID

func (JSONCodec) ID() byte

func (JSONCodec) Marshal

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

func (JSONCodec) Name

func (JSONCodec) Name() string

func (JSONCodec) Unmarshal

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

type PbEmpty added in v0.2.0

type PbEmpty struct {
	// contains filtered or unexported fields
}

func (*PbEmpty) Descriptor deprecated added in v0.2.0

func (*PbEmpty) Descriptor() ([]byte, []int)

Deprecated: Use PbEmpty.ProtoReflect.Descriptor instead.

func (*PbEmpty) ProtoMessage added in v0.2.0

func (*PbEmpty) ProtoMessage()

func (*PbEmpty) ProtoReflect added in v0.2.0

func (x *PbEmpty) ProtoReflect() protoreflect.Message

func (*PbEmpty) Reset added in v0.2.0

func (x *PbEmpty) Reset()

func (*PbEmpty) String added in v0.2.0

func (x *PbEmpty) String() string

type PlainCodec added in v0.0.3

type PlainCodec struct{}

PlainCodec plain text codec

func (PlainCodec) ID added in v0.0.3

func (PlainCodec) ID() byte

ID returns codec id.

func (PlainCodec) Marshal added in v0.0.3

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

func (PlainCodec) Name added in v0.0.3

func (PlainCodec) Name() string

Name returns codec name.

func (PlainCodec) Unmarshal added in v0.0.3

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

type ProtoCodec added in v0.2.0

type ProtoCodec struct{}

func (ProtoCodec) ID added in v0.2.0

func (ProtoCodec) ID() byte

func (ProtoCodec) Marshal added in v0.2.0

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

Marshal 编码

func (ProtoCodec) Name added in v0.2.0

func (ProtoCodec) Name() string

func (ProtoCodec) Unmarshal added in v0.2.0

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

Unmarshal 解码

type XMLCodec added in v0.0.3

type XMLCodec struct{}

func (XMLCodec) ID added in v0.0.3

func (XMLCodec) ID() byte

ID returns codec id.

func (XMLCodec) Marshal added in v0.0.3

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

func (XMLCodec) Name added in v0.0.3

func (XMLCodec) Name() string

Name returns codec name.

func (XMLCodec) Unmarshal added in v0.0.3

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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