procs

package
v1.1.4 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JsonMarshal

func JsonMarshal(messageID int32, input any) (output *msgs.Json, err error)

JsonMarshal json訊息序列化

func JsonUnmarshal

func JsonUnmarshal[T any](input any) (messageID int32, output *T, err error)

JsonUnmarshal json訊息反序列化

func ProtoMarshal

func ProtoMarshal(messageID int32, input proto.Message) (output *msgs.Proto, err error)

ProtoMarshal 序列化proto訊息

func ProtoUnmarshal

func ProtoUnmarshal[T any](input any) (messageID int32, output *T, err error)

ProtoUnmarshal 反序列化proto訊息

func RavenCBuilder added in v1.1.1

func RavenCBuilder(messageID, errID int32, header, request proto.Message, respond ...proto.Message) (output any, err error)

RavenCBuilder 建立RavenC訊息

func RavenRespond added in v1.1.1

func RavenRespond[T any](respond []proto.Message) *T

RavenRespond 取得回應列表中首個符合指定類型的資料

func RavenRespondAt added in v1.1.1

func RavenRespondAt[T any](respond []proto.Message, index int) *T

RavenRespondAt 取得回應列表中指定位置的資料

func RavenSBuilder added in v1.1.1

func RavenSBuilder(messageID int32, header, request proto.Message) (output any, err error)

RavenSBuilder 建立RavenS訊息

func RavenTestErrID added in v1.1.1

func RavenTestErrID(input any, expected int32) bool

RavenTestErrID 測試錯誤編號是否相符, input必須是msgs.RavenC, 並且錯誤編號與expected相符才會傳回true, 否則為false

func RavenTestHeader added in v1.1.1

func RavenTestHeader(input any, expected proto.Message) bool

RavenTestHeader 測試標頭資料是否相符, input必須是msgs.RavenC, 並且標頭資料與expected相符才會傳回true, 否則為false

func RavenTestMessageID added in v1.1.1

func RavenTestMessageID(input any, expected int32) bool

RavenTestMessageID 測試訊息編號是否相符, input必須是msgs.RavenC, 並且訊息編號與expected相符才會傳回true, 否則為false

func RavenTestRequest added in v1.1.1

func RavenTestRequest(input any, expected proto.Message) bool

RavenTestRequest 測試要求資料是否相符, input必須是msgs.RavenC, 並且要求資料與expected相符才會傳回true, 否則為false

func RavenTestRespond added in v1.1.1

func RavenTestRespond(input any, expected ...proto.Message) bool

RavenTestRespond 測試回應列表資料是否相符, input必須是msgs.RavenC, 並且expected列表的每一項元素都有與之相符的回應資料才會傳回true, 否則為false; 但是這並不代表expected列表與回應列表完全一致, 例如有只出現於回應列表, 但不在expected列表中的資料, 就無法通過此函式檢測出來

func RavenTestRespondLength added in v1.1.1

func RavenTestRespondLength(input any, expected int) bool

RavenTestRespondLength 測試回應列表長度是否相符, input必須是msgs.RavenC, 並且回應列表長度必須相符才會傳回true, 否則為false

func RavenTestRespondType added in v1.1.1

func RavenTestRespondType(input any, expected ...proto.Message) bool

RavenTestRespondType 測試回應列表類型是否相符, input必須是msgs.RavenC, 並且expected列表的每一項元素都有與之相符的回應類型才會傳回true, 否則為false; 但是這並不代表expected列表與回應列表完全一致, 例如有只出現於回應列表, 但不在expected列表中的類型, 就無法通過此函式檢測出來

Types

type Json

type Json struct {
	*Procmgr // 管理器
}

Json json處理器, 封包結構使用msgs.Json

  • 訊息定義: support/proto/mizugo/msg-go/msgs-json/json.go
  • 訊息定義: support/proto/mizugo/msg-cs/msgs-json/Json.cs

func NewJson

func NewJson() *Json

NewJson 建立json處理器

func (*Json) Decode

func (this *Json) Decode(input any) (output any, err error)

Decode 封包解碼

func (*Json) Encode

func (this *Json) Encode(input any) (output any, err error)

Encode 封包編碼

func (*Json) Process

func (this *Json) Process(input any) error

Process 訊息處理

type Process

type Process func(message any)

Process 訊息處理函式類型

type Processor

type Processor interface {
	// Encode 封包編碼
	Encode(input any) (output any, err error)

	// Decode 封包解碼
	Decode(input any) (output any, err error)

	// Process 訊息處理
	Process(input any) error

	// Add 新增訊息處理
	Add(messageID int32, process Process)

	// Del 刪除訊息處理
	Del(messageID int32)
}

Processor 處理介面, 負責以下功能

  • 封包編碼: 在 Encode 中實現
  • 封包解碼: 在 Decode 中實現
  • 收到訊息時的處理: 在 Process 中實現
  • 管理訊息處理函式: 在 Add, Del 中實現

如果想要建立新的處理結構, 需要遵循以下流程

  • 定義訊息結構, 訊息結構必須包含 messageID, 類型為 int32
  • 訊息結構如果要使用protobuf, 可以把定義檔放在 support/proto-mizugo 中
  • 定義處理結構, 處理結構需要繼承 Processor 介面, 並實現所有函式; 在處理結構中包含 Procmgr 結構來實現訊息處理功能, 這樣只要實作 Encode, Decode, Process 三個函式就可以了

mizugo提供的預設處理器有 Json, Proto, Raven

type Procmgr

type Procmgr struct {
	// contains filtered or unexported fields
}

Procmgr 管理器, 負責管理訊息處理函式

func NewProcmgr

func NewProcmgr() *Procmgr

NewProcmgr 建立管理器

func (*Procmgr) Add

func (this *Procmgr) Add(messageID int32, process Process)

Add 新增處理函式

func (*Procmgr) Del

func (this *Procmgr) Del(messageID int32)

Del 刪除處理函式

func (*Procmgr) Get

func (this *Procmgr) Get(messageID int32) Process

Get 取得處理函式

type Proto

type Proto struct {
	*Procmgr // 管理器
}

Proto proto處理器, 封包結構使用msgs.Proto

  • 訊息定義: support/proto/mizugo/proto.proto

func NewProto

func NewProto() *Proto

NewProto 建立proto處理器

func (*Proto) Decode

func (this *Proto) Decode(input any) (output any, err error)

Decode 封包解碼

func (*Proto) Encode

func (this *Proto) Encode(input any) (output any, err error)

Encode 封包編碼

func (*Proto) Process

func (this *Proto) Process(input any) error

Process 訊息處理

type Raven added in v1.1.1

type Raven struct {
	*Procmgr // 管理器
}

Raven raven處理器, 封包結構使用msgs.RavenS, msgs.RavenC

  • 訊息定義: support/proto/mizugo/raven.proto

func NewRaven added in v1.1.1

func NewRaven() *Raven

NewRaven 建立raven處理器

func (*Raven) Decode added in v1.1.1

func (this *Raven) Decode(input any) (output any, err error)

Decode 封包解碼

func (*Raven) Encode added in v1.1.1

func (this *Raven) Encode(input any) (output any, err error)

Encode 封包編碼

func (*Raven) Process added in v1.1.1

func (this *Raven) Process(input any) error

Process 訊息處理

type RavenCData added in v1.1.1

type RavenCData[H, Q any] struct {
	MessageID int32           // 訊息編號
	ErrID     int32           // 錯誤編號
	Header    *H              // 標頭資料
	Request   *Q              // 要求資料
	Respond   []proto.Message // 回應列表
}

RavenCData RavenC資料

func RavenCParser added in v1.1.1

func RavenCParser[H, Q any](input any) (output *RavenCData[H, Q], err error)

RavenCParser 解析RavenC訊息

func (*RavenCData[H, Q]) Detail added in v1.1.1

func (this *RavenCData[H, Q]) Detail() string

Detail 取得詳細資訊

func (*RavenCData[H, Q]) Size added in v1.1.1

func (this *RavenCData[H, Q]) Size() int

Size 取得訊息大小

type RavenClient added in v1.1.1

type RavenClient struct {
	*Procmgr // 管理器
}

RavenClient raven客戶端處理器, 封包結構使用msgs.RavenS, msgs.RavenC; 這個處理器提供給客戶端使用

  • 訊息定義: support/proto/mizugo/raven.proto

func NewRavenClient added in v1.1.1

func NewRavenClient() *RavenClient

NewRavenClient 建立raven客戶端處理器

func (*RavenClient) Decode added in v1.1.1

func (this *RavenClient) Decode(input any) (output any, err error)

Decode 封包解碼

func (*RavenClient) Encode added in v1.1.1

func (this *RavenClient) Encode(input any) (output any, err error)

Encode 封包編碼

func (*RavenClient) Process added in v1.1.1

func (this *RavenClient) Process(input any) error

Process 訊息處理

type RavenSData added in v1.1.1

type RavenSData[H, Q any] struct {
	MessageID int32 // 訊息編號
	Header    *H    // 標頭資料
	Request   *Q    // 要求資料
}

RavenSData RavenS資料

func RavenSParser added in v1.1.1

func RavenSParser[H, Q any](input any) (output *RavenSData[H, Q], err error)

RavenSParser 解析RavenS訊息

func (*RavenSData[H, Q]) Detail added in v1.1.1

func (this *RavenSData[H, Q]) Detail() string

Detail 取得訊息資訊

func (*RavenSData[H, Q]) Size added in v1.1.1

func (this *RavenSData[H, Q]) Size() int

Size 取得訊息大小

Jump to

Keyboard shortcuts

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