msg

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package msg micserver 中消息传递的基本单位

Index

Constants

View Source
const (
	DEFAULTMSGHEADSIZE = (4 + 2)
)

默认的消息头大小

View Source
const (
	// MessageMaxSize 允许的最大消息大小(包括头部大小)
	// 普通代码中间应留出至少 32 字节提供给消息头部使用
	MessageMaxSize = 8 * 1024 * 1024
)

Variables

This section is empty.

Functions

func DefaultWriteHead

func DefaultWriteHead(data []byte, totalLen int,
	msgid uint16) (size int)

DefaultWriteHead 默认写头

Types

type DefaultCodec

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

DefaultCodec micserver 默认的消息编解码器

func (*DefaultCodec) EncodeBytes

func (defaultCodec *DefaultCodec) EncodeBytes(cmdid uint16,
	protodata []byte) *MessageBinary

EncodeBytes 编码一个由消息号及二进制内容构成的消息

func (*DefaultCodec) EncodeObj

func (defaultCodec *DefaultCodec) EncodeObj(v IMsgStruct) *MessageBinary

EncodeObj 编码一个消息对象

func (*DefaultCodec) RangeMsgBinary

func (defaultCodec *DefaultCodec) RangeMsgBinary(
	buf *buffer.IOBuffer, cb func(*MessageBinary)) (reerr error)

RangeMsgBinary 遍历目标缓冲区中的消息

type IMsgCodec

type IMsgCodec interface {
	RangeMsgBinary(buf *buffer.IOBuffer, cb func(*MessageBinary)) error
	EncodeBytes(cmdid uint16, protodata []byte) *MessageBinary
	EncodeObj(v IMsgStruct) *MessageBinary
}

IMsgCodec 消息编解码器

type IMsgStruct

type IMsgStruct interface {
	WriteBinary(data []byte) int
	GetMsgId() uint16
	GetMsgName() string
	GetSize() int
	GetJSON() string
}

IMsgStruct micserver消息接口,所有在micserver架构间的消息类都要满足这些接口

type MessageBinary

type MessageBinary struct {
	msgbase.MessageBase

	ProtoData []byte
	// contains filtered or unexported fields
}

MessageBinary micserver 中消息传递的基本单位

func DefaultEncodeBytes

func DefaultEncodeBytes(cmdid uint16, protodata []byte) *MessageBinary

DefaultEncodeBytes 默认通过字节流构造消息体

func DefaultEncodeObj

func DefaultEncodeObj(v IMsgStruct) *MessageBinary

DefaultEncodeObj 默认通过结构构造消息体

func GetMessageBinary

func GetMessageBinary(totalLength int) *MessageBinary

GetMessageBinary 根据消息内容大小从对象池获取对应的消息对象

func (*MessageBinary) Free

func (mb *MessageBinary) Free()

Free 将消息对象释放到对象池中

func (*MessageBinary) GetBuffer

func (mb *MessageBinary) GetBuffer() []byte

GetBuffer 获取消息的二进制流数据

func (*MessageBinary) GetMsgID

func (mb *MessageBinary) GetMsgID() uint16

GetMsgID 获取消息ID

func (*MessageBinary) GetProtoLength

func (mb *MessageBinary) GetProtoLength() int

GetProtoLength 获取消息包数据段总长度

func (*MessageBinary) GetTotalLength

func (mb *MessageBinary) GetTotalLength() int

GetTotalLength 获取消息包二进制总长度

func (*MessageBinary) Read

func (mb *MessageBinary) Read(soffset int,
	data []byte, doffset int, bytenum int) error

从二进制流中读取数据 soffset 从本地偏移复制 data 数据源 doffset 数据源偏移 Read bytenum 要读取的字节数

func (*MessageBinary) Reset

func (mb *MessageBinary) Reset()

Reset 重置 Message 数据

func (*MessageBinary) SetMsgID

func (mb *MessageBinary) SetMsgID(v uint16)

SetMsgID 设置消息ID

func (*MessageBinary) SetProtoDataBound

func (mb *MessageBinary) SetProtoDataBound(offset int, bytenum int) error

SetProtoDataBound 设置消息内容数据域

func (*MessageBinary) SetProtoLength

func (mb *MessageBinary) SetProtoLength(v int)

SetProtoLength 设置消息包数据段总长度

func (*MessageBinary) SetTotalLength

func (mb *MessageBinary) SetTotalLength(v int)

SetTotalLength 设置消息包二进制总长度

func (*MessageBinary) String

func (mb *MessageBinary) String() string

String 获取消息的所有二进制内容的16进制字符串

Directories

Path Synopsis
Package base 一个消息具有的基础数据
Package base 一个消息具有的基础数据

Jump to

Keyboard shortcuts

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