mux

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// BlockBaseLen 基本长度, 不包含载荷数据, 因为载荷数据的长度可变
	// - (3 + 6) 是因为考虑到了Struct的对齐
	BlockBaseLen = 1 + 4 + 8 + 2
	// MaxBlockSize Mux模式下Server一次接收多少长度的消息
	MaxBlockSize = 1400
	// MaxPayloadSizeOnMux 在Mux模式上发送的消息一次最多携带多少属于Message的数据
	MaxPayloadSizeOnMux = MaxBlockSize - BlockBaseLen
)
View Source
const (
	// Enabled 指示在Stream中开启Mux的功能
	Enabled uint8 = 0b01
)

Variables

This section is empty.

Functions

func Marshal

func Marshal(msg *Block, payloads *container.Slice[byte])

Marshal 与message.Marshal不同, 该函数没有任何副作用

func MarshalIteratorFromMessage

func MarshalIteratorFromMessage(msg *message2.Message, noMuxBuf, muxBuf *container.Slice[byte], base Block) (*container.Iterator[[]byte], error)

MarshalIteratorFromMessage buf1在返回时可以回收, buf2需要迭代器完成工作时才可回收 base Block中需要有除Payloads&PayloadLength之外的所有信息

func Unmarshal

func Unmarshal(data container.Slice[byte], msg *Block) error

Types

type Block

type Block struct {
	// Flags可以标记是否开启了Mux
	Flags uint8
	// 通过连接的流的Id
	// 在开启Mux的时候一个连接中可能会有多个流的数据
	StreamId uint32
	// 通过此流传输的消息的Id
	MsgId uint64
	// 消息的载荷数据长度
	PayloadLength uint16
	// 消息的载荷数据
	Payloads container.Slice[byte]
}

Block 对一次Mux中的消息帧描述 StreamId必须确保Server和多个Client之间唯一

func (*Block) GetFlags

func (m *Block) GetFlags() uint8

func (*Block) GetMsgId

func (m *Block) GetMsgId() uint64

func (*Block) GetPayloadLength

func (m *Block) GetPayloadLength() uint16

func (*Block) GetPayloads

func (m *Block) GetPayloads() []byte

func (*Block) GetStreamId

func (m *Block) GetStreamId() uint32

func (*Block) Reset

func (m *Block) Reset()

Reset implement Reset interface

func (*Block) SetFlags

func (m *Block) SetFlags(flags uint8)

func (*Block) SetMsgId

func (m *Block) SetMsgId(msgId uint64)

func (*Block) SetPayloads

func (m *Block) SetPayloads(payloads []byte)

func (*Block) SetStreamId

func (m *Block) SetStreamId(streamId uint32)

Jump to

Keyboard shortcuts

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