codec

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: Apache-2.0 Imports: 14 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	CodecJSONDataNoHeader = uint8(0) // 标准协议头的JSON
	CodecJSONData         = uint8(1) // 标准协议头的JSON
	CodecProtoData        = uint8(2) // 使用proto解码

	CurrentMaxCodecType = uint8(2) // 当前最大编码类型
	MaxCodecType        = uint8(7) // 最大编码类型
)

Variables

View Source
var (
	ErrActionNotFound         = errors.New("action not found")
	ErrMethodNotFound         = errors.New("method not found")
	ErrMessageDecode          = errors.New("message decode error")
	ErrRegisterCodecType      = errors.New("register codec type error")
	ErrRegisterCodecTypeExist = errors.New("register codec type exist")
	ErrCodecType              = errors.New("codec type error")
	ErrNotValidJSONType       = errors.New("not valid json type")
	ErrActionNotExist         = errors.New("action not exist")
	ErrInvalidProtoMessage    = errors.New("invalid proto message")
)

Functions

This section is empty.

Types

type CodecHelper

type CodecHelper struct {
	*zap.Logger
	// contains filtered or unexported fields
}

func NewCodecHelper

func NewCodecHelper(config *config.Config, dispatcher Dispatch) *CodecHelper

func (*CodecHelper) Decode

func (d *CodecHelper) Decode(data []byte) (*packet.Packet, error)

func (*CodecHelper) Encode

func (d *CodecHelper) Encode(in interface{}, name ...string) (*packet.Packet, error)

func (*CodecHelper) GetTypes

func (d *CodecHelper) GetTypes() (map[string]uint8, string)

func (*CodecHelper) RegisterDecode

func (d *CodecHelper) RegisterDecode(decodeKey uint8, c PacketDecode) error

func (*CodecHelper) RegisterEncode

func (d *CodecHelper) RegisterEncode(v uint8, e PacketEncode)

type Dispatch

type Dispatch interface {
	GetAction(in interface{}) (uint32, error) //直接通过反射获取对象的ActionKey
	GetActionByName(string) (uint32, error)   //通过名称获取对象的ActionKey
	GetObj(uint32) (interface{}, bool)
}

Dispatch 用于获取对象类型和ActionKey

type JSONDecode

type JSONDecode struct{}

func (*JSONDecode) Decode

func (c *JSONDecode) Decode(data []byte, in interface{}) error

func (*JSONDecode) String

func (c *JSONDecode) String(in interface{}) string

type JSONEncode

type JSONEncode struct{}

func (*JSONEncode) Encode

func (c *JSONEncode) Encode(in interface{}) ([]byte, error)

func (*JSONEncode) String

func (c *JSONEncode) String(in interface{}) string

type PacketDecode

type PacketDecode interface {
	Decode(data []byte, in interface{}) error
	String(in interface{}) string
}

type PacketEncode

type PacketEncode interface {
	Encode(in interface{}) ([]byte, error)
	String(in interface{}) string
}

type Ping

type Ping struct {
	Time string `protobuf:"bytes,1,opt,name=time,proto3" json:"time,omitempty"`
	// contains filtered or unexported fields
}

@gogs:Request

func (*Ping) Descriptor deprecated

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

Deprecated: Use Ping.ProtoReflect.Descriptor instead.

func (*Ping) GetTime

func (x *Ping) GetTime() string

func (*Ping) ProtoMessage

func (*Ping) ProtoMessage()

func (*Ping) ProtoReflect

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

func (*Ping) Reset

func (x *Ping) Reset()

func (*Ping) String

func (x *Ping) String() string

type Pong

type Pong struct {
	Time string `protobuf:"bytes,1,opt,name=time,proto3" json:"time,omitempty"`
	// contains filtered or unexported fields
}

func (*Pong) Descriptor deprecated

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

Deprecated: Use Pong.ProtoReflect.Descriptor instead.

func (*Pong) GetTime

func (x *Pong) GetTime() string

func (*Pong) ProtoMessage

func (*Pong) ProtoMessage()

func (*Pong) ProtoReflect

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

func (*Pong) Reset

func (x *Pong) Reset()

func (*Pong) String

func (x *Pong) String() string

type ProtoDecode

type ProtoDecode struct{}

func (*ProtoDecode) Decode

func (c *ProtoDecode) Decode(data []byte, in interface{}) error

func (*ProtoDecode) String

func (c *ProtoDecode) String(in interface{}) string

type ProtoEncode

type ProtoEncode struct{}

func (*ProtoEncode) Encode

func (c *ProtoEncode) Encode(in interface{}) ([]byte, error)

func (*ProtoEncode) String

func (c *ProtoEncode) String(in interface{}) string

Jump to

Keyboard shortcuts

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