proto

package
v0.0.0-...-4cd9d19 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DK_CHECK_NEW = 0x24 //校验类型

Variables

View Source
var (
	MsgProtoType         ProtoType
	IsUseBigEndian       bool
	MsgUnMarshal         func(t reflect.Type, d []byte) (interface{}, error)
	MsgMarshal           func(comId uint16, msgId uint16, msg interface{}) IMessage
	StructUnmarshal      func(d []byte, v interface{}) error
	StructMarshal        func(v interface{}) ([]byte, error)
	MsgToString          func(v interface{}) string
	MessageDecodeBybufio func(r *bufio.Reader) (IMessage, error)
	MessageDecodeBybytes func(buffer []byte) (msg IMessage, err error)
)

Functions

func JsonStructMarshal

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

func JsonStructUnmarshal

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

func OnInit

func OnInit(s core.IService, opt ...Option) (err error)

func ProtoStructMarshal

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

func ProtoStructUnmarshal

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

func ReadByte

func ReadByte(r *bufio.Reader) (byte, error)

func ReadUInt16

func ReadUInt16(r *bufio.Reader) (uint16, error)

func ReadUInt32

func ReadUInt32(r *bufio.Reader) (uint32, error)

Types

type IMessage

type IMessage interface {
	GetComId() uint16
	GetMsgId() uint16
	GetMsg() []byte
	Serializable() (bytes []byte, err error)
	ToString() string
}

func DefMessageDecodeBybufio

func DefMessageDecodeBybufio(r *bufio.Reader) (msg IMessage, err error)

func DefMessageDecodeBybytes

func DefMessageDecodeBybytes(buffer []byte) (msg IMessage, err error)

func DefMessageMarshal

func DefMessageMarshal(comId uint16, msgId uint16, msg interface{}) IMessage

type IMsgMarshalString

type IMsgMarshalString interface {
	ToString() (string, error)
}

type Message

type Message struct {
	ComId   uint16
	MsgId   uint16
	CheckId byte
	MsgLen  uint32
	Buffer  []byte
}

func (*Message) GetComId

func (this *Message) GetComId() uint16

func (*Message) GetMsg

func (this *Message) GetMsg() []byte

func (*Message) GetMsgId

func (this *Message) GetMsgId() uint16

func (*Message) Serializable

func (this *Message) Serializable() (bytes []byte, err error)

func (*Message) ToString

func (this *Message) ToString() string

type Option

type Option func(*Options)

func SetIsUseBigEndian

func SetIsUseBigEndian(v bool) Option

func SetMessageDecodeBybufio

func SetMessageDecodeBybufio(v func(r *bufio.Reader) (IMessage, error)) Option

func SetMessageDecodeBybytes

func SetMessageDecodeBybytes(v func(buffer []byte) (msg IMessage, err error)) Option

func SetMsgMarshal

func SetMsgMarshal(v func(comId uint16, msgId uint16, msg interface{}) IMessage) Option

func SetProtoType

func SetProtoType(v ProtoType) Option

type Options

type Options struct {
	MsgProtoType         ProtoType
	IsUseBigEndian       bool
	MessageDecodeBybufio func(r *bufio.Reader) (IMessage, error)
	MessageDecodeBybytes func(buffer []byte) (msg IMessage, err error)
	MsgMarshal           func(comId uint16, msgId uint16, msg interface{}) IMessage
}

type ProtoType

type ProtoType uint8
var (
	Proto_Json ProtoType = 1
	Proto_Buff ProtoType = 2
)

Directories

Path Synopsis
message

Jump to

Keyboard shortcuts

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