message

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package message 消息对象

Index

Constants

View Source
const (
	TypeUndefined byte = 0 //未知类型
	TypeCall      byte = 1 // call
	TypeReply     byte = 2 // reply to call
	TypePush      byte = 3
	TypeAuthCall  byte = 4
	TypeAuthReply byte = 5
)

消息类型

View Source
const (
	// MetaRealIP real IP metadata key
	MetaRealIP = "X-Real-IP"
	// MetaAcceptBodyCodec the key of body codec that the sender wishes to accept
	MetaAcceptBodyCodec = "X-Accept-Body-Codec"
)

Variables

View Source
var (

	// ErrExceedMessageSizeLimit error
	ErrExceedMessageSizeLimit = errors.New("size of package exceeds limit")
)

Functions

func GetAcceptBodyCodec

func GetAcceptBodyCodec(meta *dmap.Map) (byte, bool)

GetAcceptBodyCodec 获取发送方希望接受的正文编解码器。 //注意:如果指定的编解码器无效,接收器将忽略配对数据

func MsgSizeLimit

func MsgSizeLimit() uint32

MsgSizeLimit 获取消息的最大长度

func PutMessage

func PutMessage(m Message)

PutMessage 把message对象返回对象池

func SetMsgSizeLimit

func SetMsgSizeLimit(maxMessageSize uint32)

SetMsgSizeLimit 设置消息的最大长度

func TypeText

func TypeText(typ byte) string

Types

type Body

type Body interface {
	// BodyCodec 消息体编码格式
	BodyCodec() byte
	// SetBodyCodec 设置消息体编码格式
	SetBodyCodec(bodyCodec byte)
	// Body 返回消息体内容
	Body() interface{}
	// SetBody 设置消息体内容
	SetBody(body interface{})
	// SetNewBody 设置一个函数,该函数根据消息头生成一个新的消息体
	SetNewBody(NewBodyFunc)
	// MarshalBody 编码消息体
	MarshalBody() ([]byte, error)
	// UnmarshalBody 解码消息体
	UnmarshalBody(bodyBytes []byte) error
}

Body 消息体

type Header interface {
	// Seq 序列号
	Seq() int32
	// SetSeq 设置序列号
	SetSeq(int32)
	// MType 消息类型 有三种:CALL,REPLY,PUSH
	MType() byte
	// SetMType 设置消息类型 有三种:CALL,REPLY,PUSH
	SetMType(byte)
	// ServiceMethod 请求的服务方法名称 长度必须小于255字节 max <= 255
	ServiceMethod() string
	// SetServiceMethod 设置请求的服务方法名
	SetServiceMethod(string)
	// StatusOK 判断当前消息是否是 OK
	StatusOK() bool
	// Status 返回当前消息的状态,包含code,msg,cause或者stack,
	//如果消息是nil或者autoInit传入了true,则返回一个 code为OK的新对象
	Status(autoInit ...bool) *status.Status
	// SetStatus 设置消息的状态
	SetStatus(*status.Status)
	// Meta 获取消息的元数据,数据在传输的时候是使用了序列化串,最大长度为 max len ≤ 65535
	Meta() *dmap.Map
}

Header 消息头

type Message

type Message interface {
	Reset(settings ...MsgSetting) Message
	Header
	Body
	// PipeTFilter 针对传入的数据做
	PipeTFilter() *tfilter.PipeTFilter

	// Size 消息长度
	Size() uint32
	// SetSize 设置消息长度,如果长度超长了,则返回错误
	SetSize(size uint32) error
	// Context 返回消息的上下文对象
	Context() context.Context
	// String 把消息转换成可打印的字符串
	String() string
	// AsHeader 把消息转换成header接口
	AsHeader() Header
	// AsBody 把消息转换成body接口
	AsBody() Body
	// contains filtered or unexported methods
}

Message 消息

func GetMessage

func GetMessage(settings ...MsgSetting) Message

GetMessage 从对象池中获取message

func NewMessage

func NewMessage(settings ...MsgSetting) Message

NewMessage 创建message对象

type MsgSetting

type MsgSetting func(Message)

func WithBody

func WithBody(body interface{}) MsgSetting

WithBody 设置消息体的内容

func WithBodyCodec

func WithBodyCodec(bodyCodec byte) MsgSetting

WithBodyCodec 设置消息的消息体编码格式

func WithContext

func WithContext(ctx context.Context) MsgSetting

WithContext 设置消息的上下文对象

func WithDelMeta

func WithDelMeta(key string) MsgSetting

WithDelMeta 删除消息元数据

func WithNewBody

func WithNewBody(newBodyFunc NewBodyFunc) MsgSetting

WithNewBody 设置创建消息体的函数

func WithNothing

func WithNothing() MsgSetting

WithNothing 什么也不做

func WithServiceMethod

func WithServiceMethod(serviceMethod string) MsgSetting

WithServiceMethod 设置消息的服务器接口名

func WithSetMeta

func WithSetMeta(key, value string) MsgSetting

WithSetMeta 添加消息的元数据

func WithSetMetas added in v0.0.10

func WithSetMetas(metas map[string]interface{}) MsgSetting

WithSetMetas 使用数组添加元数据

func WithStatus

func WithStatus(stat *status.Status) MsgSetting

WithStatus 设置消息的状态

func WithXFerPipe

func WithXFerPipe(filterID ...byte) MsgSetting

WithXFerPipe 设置消息的管道类型

type NewBodyFunc

type NewBodyFunc func(Header) interface{}

NewBodyFunc 根据消息头,生成消息体,这个函数只会在读取connection上的

Jump to

Keyboard shortcuts

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