Documentation
¶
Overview ¶
Package message 消息对象
Index ¶
- Constants
- Variables
- func GetAcceptBodyCodec(meta *gmap.Map) (byte, bool)
- func MsgSizeLimit() uint32
- func PutMessage(m Message)
- func SetMsgSizeLimit(maxMessageSize uint32)
- func TypeText(typ byte) string
- type Body
- type Header
- type Message
- type MsgSetting
- func WithBody(body interface{}) MsgSetting
- func WithBodyCodec(bodyCodec byte) MsgSetting
- func WithContext(ctx context.Context) MsgSetting
- func WithDelMeta(key string) MsgSetting
- func WithNewBody(newBodyFunc NewBodyFunc) MsgSetting
- func WithNothing() MsgSetting
- func WithServiceMethod(serviceMethod string) MsgSetting
- func WithSetMeta(key, value string) MsgSetting
- func WithSetMetas(metas map[string]interface{}) MsgSetting
- func WithStatus(stat *status.Status) MsgSetting
- func WithXFerPipe(filterID ...byte) MsgSetting
- type NewBodyFunc
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 ¶
GetAcceptBodyCodec 获取发送方希望接受的正文编解码器。 //注意:如果指定的编解码器无效,接收器将忽略配对数据
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 ¶
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() *gmap.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 消息
type MsgSetting ¶
type MsgSetting func(Message)
func WithServiceMethod ¶
func WithServiceMethod(serviceMethod string) MsgSetting
WithServiceMethod 设置消息的服务器接口名
func WithSetMetas ¶
func WithSetMetas(metas map[string]interface{}) MsgSetting
WithSetMetas 使用数组添加元数据
type NewBodyFunc ¶
type NewBodyFunc func(Header) interface{}
NewBodyFunc 根据消息头,生成消息体,这个函数只会在读取connection上的
Click to show internal directories.
Click to hide internal directories.