Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func JsonMarshal ¶
JsonMarshal json訊息序列化
Types ¶
type Json ¶
type Json struct { *Procmgr // 管理器 // contains filtered or unexported fields }
Json json處理器, 封包結構使用JsonMsg, 可以選擇是否啟用base64編碼或是des-cbc加密
- 訊息定義: support/proto/mizugo/msg-go/msgs-json/jsonmsg.go
- 訊息定義: support/proto/mizugo/msg-cs/msgs-json/Jsonmsg.cs
- 封包編碼: json編碼成位元陣列, (可選)des-cbc加密, (可選)base64編碼
- 封包解碼: (可選)base64解碼, (可選)des-cbc解密, json解碼成訊息結構
type MessageID ¶
type MessageID = int32
MessageID 訊息編號, 設置為int32以跟proto的列舉類型統一
func JsonUnmarshal ¶
JsonUnmarshal json訊息反序列化
type Processor ¶
type Processor interface { // Encode 封包編碼 Encode(input any) (output []byte, err error) // Decode 封包解碼 Decode(input []byte) (output any, err error) // Process 訊息處理 Process(input any) error // Add 新增訊息處理 Add(messageID MessageID, process Process) // Del 刪除訊息處理 Del(messageID MessageID) }
Processor 處理介面, 負責以下功能
- 封包編碼: 在 Encode 中實現
- 封包解碼: 在 Decode 中實現
- 收到訊息時的處理: 在 Process 中實現
- 管理訊息處理函式: 在 Add, Del 中實現
如果想要建立新的處理結構, 需要遵循以下流程
- 定義訊息結構, 訊息結構必須包含 MessageID
- 訊息結構如果要使用protobuf, 可以把定義檔放在support/proto/mizugo中
- 定義處理結構, 處理結構需要繼承 Processor 介面, 並實現所有函式; 在處理結構中包含 Procmgr 結構來實現訊息處理功能, 這樣只要實作 Encode, Decode, Process 三個函式就可以了
mizugo提供的預設處理器有 Json, Proto
type Procmgr ¶
type Procmgr struct {
// contains filtered or unexported fields
}
Procmgr 管理器, 負責管理訊息處理函式
type Proto ¶
type Proto struct { *Procmgr // 管理器 // contains filtered or unexported fields }
Proto proto處理器, 封包結構使用ProtoMsg, 可以選擇是否啟用base64編碼或是des-cbc加密
- 訊息定義: support/proto/mizugo/protomsg.proto
- 封包編碼: protobuf編碼成位元陣列, (可選)des-cbc加密, (可選)base64編碼
- 封包解碼: (可選)base64解碼, (可選)des-cbc解密, protobuf解碼成訊息結構
Click to show internal directories.
Click to hide internal directories.