Documentation ¶
Index ¶
- Constants
- func MarshaToMux(msg *Message, payloads *container.Slice[byte]) error
- func Marshal(msg *Message, p *container.Slice[byte]) error
- func ResetMsg(msg *Message, resetOther, freeMetaData, usePayload bool, useSize int)
- func Unmarshal(p container.Slice[byte], msg *Message) error
- func UnmarshalFromMux(data container.Slice[byte], msg *Message) error
- type Getter
- type GetterSetter
- type Message
- func (m *Message) AppendPayloads(p []byte)
- func (m *Message) BaseLength() int
- func (m *Message) First() uint8
- func (m *Message) GetAndSetLength() uint32
- func (m *Message) GetMsgId() uint64
- func (m *Message) GetMsgType() uint8
- func (m *Message) GetServiceName() string
- func (m *Message) Length() uint32
- func (m *Message) MinMux() int
- func (m *Message) Payloads() container2.Slice[byte]
- func (m *Message) PayloadsIterator() *container2.Iterator[[]byte]
- func (m *Message) ReWritePayload(p []byte)
- func (m *Message) Reset()
- func (m *Message) SetMsgId(msgId uint64)
- func (m *Message) SetMsgType(msgTyp uint8)
- func (m *Message) SetPayloads(payloads []byte)
- func (m *Message) SetServiceName(s string)
- type Setter
Constants ¶
View Source
const ( MagicNumber uint8 = 0x45 // Call 表示这是一条调用的消息 Call uint8 = 0x10 // Return 表示这是一条调用返回消息 Return uint8 = 0x18 // ContextCancel 用户服务端接收的context.Context的取消API ContextCancel uint8 = 0x24 // Ping Ping消息 Ping uint8 = 0x33 // Pong Pong消息 Pong uint8 = 0x35 // BaseLen 的基本长度 BaseLen = _ScopeLength + 4 + 8 // DefaultPacker TODO: 将Encoder改为Packer DefaultPacker string = "text" // encoding == text DefaultCodec string = "json" // codec == text ErrorCode string = "code" ErrorMessage string = "message" ErrorMore string = "bin" ContextId string = "context-id" CodecScheme string = "codec" // PackerScheme TODO: 将Encoder改为Packer PackerScheme string = "packer" )
Variables ¶
This section is empty.
Functions ¶
func MarshaToMux ¶
MarshaToMux 此API只会序列化Mux功能需要的数据
func ResetMsg ¶
ResetMsg 指定策略的复用,对内存重用更加友好 resetOther指示是否释放|Scope|NameLayout|InstanceName|MethodName|MsgId|Timestamp freeMetaData指示是否要释放存放元数据对应的map[string]sting usePayload指示是否要复用载荷数据 useSize指示复用的slice类型长度的上限,即使指定了usePayload payload数据超过这个长度还是会被释放
Types ¶
type GetterSetter ¶
type Message ¶
type Message struct { // NOTE: // 有效载荷和元数据的范围 // 在Mux模式中MetaData及其Desc必须能在一个MuxBlock下被装下,否则将会丢失数据 // 元数据的布局 // NMetaData(1 Byte)|Key-Size(4 Byte)|Value-Size(4 Byte)|Key|Size // Example : // "hello":"world","world:hello" // OutPut: // 0x00000002|0x00000005|0x00000005|hello|world|0x00000005|0x00000005|world|hello MetaData *container2.SliceMap[string, string] // contains filtered or unexported fields }
Message 是对一次RPC调用传递的数据的描述 封装的方法均不是线程安全的 DecodeHeader会修改一些内部值,调用时需要注意顺序 为了使用一致性的API,在访问内部一些简单的属性时,请使用Getxx方法 在设置一些值的过程中可能需要调整其它值,所以请使用Setxx方法
func (*Message) AppendPayloads ¶
func (*Message) BaseLength ¶
BaseLength 获取基本数据的长度防止输入过短的数据导致panic
func (*Message) GetAndSetLength ¶
func (*Message) GetMsgType ¶
func (*Message) GetServiceName ¶
func (*Message) PayloadsIterator ¶
func (m *Message) PayloadsIterator() *container2.Iterator[[]byte]
func (*Message) ReWritePayload ¶
func (*Message) SetMsgType ¶
func (*Message) SetPayloads ¶
func (*Message) SetServiceName ¶
Click to show internal directories.
Click to hide internal directories.