aboutsummaryrefslogtreecommitdiff
path: root/message.go
blob: bc0a6e0260b2aae6b3a7f94bff19175c9c5627a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package muxer

// Message represents a single protocol message with a channel ID, type, and payload.
//
// ┌──────────────────────────────────────────────┐
// │ length | channel ID × message type │ payload │
// └──────────────────────────────────────────────┘
//
// Each message starts with a varint encoded unsigned 64-bit integer which consists of
// a channel ID (first 60-bits) and a message type (last 4-bits) followed by the payload.
type Message struct {
	ID   uint64
	Type uint8
	Data []byte
}

// NewMessage returns a new Message.
func NewMessage(id uint64, messageType uint8, data []byte) *Message {
	return &Message{
		ID:   id,
		Type: messageType,
		Data: data,
	}
}