gap

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2024 License: LGPL-2.1 Imports: 10 Imported by: 2

Documentation

Overview

Package gap Golaxy应用层协议(golaxy application protocol),适用于开发应用层通信消息,需要工作在GTP协议或MQ之上,支持消息判重,解决了幂等性问题。

  • 可以实现消息(Msg)接口新增自定义消息。
  • 支持可变类型(Variant),提供了一些常用的内置类型,也可以实现可变类型值(variant.Value)接口,新增自定义类型。
  • 支持自己实现消息(Msg)接口或可变类型值(variant.Value)接口,扩展支持protobuf(Protocol Buffers)等消息结构。
  • 支持消息判重,解决幂等性问题。

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotDeclared = errors.New("gap: msg not declared") // 消息未注册
)

Functions

func Marshal added in v0.1.36

func Marshal[T MsgReader](msg T) (binaryutil.RecycleBytes, error)

func Unmarshal added in v0.1.36

func Unmarshal[T MsgWriter](msg T, data []byte) error

Types

type IMsgCreator

type IMsgCreator interface {
	// Declare 注册消息
	Declare(msg Msg)
	// Undeclare 取消注册消息
	Undeclare(msgId MsgId)
	// New 创建消息指针
	New(msgId MsgId) (Msg, error)
}

IMsgCreator 消息对象构建器接口

func DefaultMsgCreator

func DefaultMsgCreator() IMsgCreator

DefaultMsgCreator 默认消息对象构建器

func NewMsgCreator

func NewMsgCreator() IMsgCreator

NewMsgCreator 创建消息对象构建器

type Msg

type Msg interface {
	MsgReader
	MsgWriter
}

Msg 消息接口

type MsgBuff added in v0.1.93

type MsgBuff struct {
	Id   MsgId  // 消息Id
	Data []byte // 消息内容(引用)
}

MsgBuff msg buff

func (*MsgBuff) MsgId added in v0.1.93

func (m *MsgBuff) MsgId() MsgId

MsgId 消息Id

func (*MsgBuff) Read added in v0.1.93

func (m *MsgBuff) Read(p []byte) (int, error)

Read implements io.Reader

func (*MsgBuff) Size added in v0.1.93

func (m *MsgBuff) Size() int

Size 大小

type MsgForward added in v0.1.32

type MsgForward struct {
	Transit   string // 中转地址
	Dst       string // 目标地址
	CorrId    int64  // 关联Id,用于支持Future等异步模型
	TransId   MsgId  // 传输消息Id
	TransData []byte // 传输消息内容(引用)
}

MsgForward 转发

func (MsgForward) MsgId added in v0.1.32

func (MsgForward) MsgId() MsgId

MsgId 消息Id

func (MsgForward) Read added in v0.1.32

func (m MsgForward) Read(p []byte) (int, error)

Read implements io.Reader

func (MsgForward) Size added in v0.1.32

func (m MsgForward) Size() int

Size 大小

func (*MsgForward) Write added in v0.1.32

func (m *MsgForward) Write(p []byte) (int, error)

Write implements io.Writer

type MsgHead

type MsgHead struct {
	Len   uint32 // 消息长度
	MsgId MsgId  // 消息Id
	Src   string // 来源地址
	Seq   int64  // 序号
}

MsgHead 消息头

func (MsgHead) Read

func (m MsgHead) Read(p []byte) (int, error)

Read implements io.Reader

func (MsgHead) Size

func (m MsgHead) Size() int

Size 大小

func (*MsgHead) Write

func (m *MsgHead) Write(p []byte) (int, error)

Write implements io.Writer

type MsgId

type MsgId = uint32

MsgId 消息Id

const (
	MsgId_None        MsgId = iota // 未设置
	MsgId_RPC_Request              // RPC请求
	MsgId_RPC_Reply                // RPC答复
	MsgId_OneWayRPC                // 单程RPC请求
	MsgId_Forward                  // 转发
	MsgId_Customize   = 32         // 自定义消息起点
)

func MakeMsgId added in v0.1.57

func MakeMsgId(msg Msg) MsgId

MakeMsgId 创建类型Id

func MakeMsgIdT added in v0.1.57

func MakeMsgIdT[T any]() MsgId

MakeMsgIdT 创建类型Id

type MsgOneWayRPC

type MsgOneWayRPC struct {
	CallChain variant.CallChain // 调用链
	Path      string            // 调用路径
	Args      variant.Array     // 参数列表
}

MsgOneWayRPC 单程RPC请求

func (MsgOneWayRPC) MsgId

func (MsgOneWayRPC) MsgId() MsgId

MsgId 消息Id

func (MsgOneWayRPC) Read

func (m MsgOneWayRPC) Read(p []byte) (int, error)

Read implements io.Reader

func (MsgOneWayRPC) Size

func (m MsgOneWayRPC) Size() int

Size 大小

func (*MsgOneWayRPC) Write

func (m *MsgOneWayRPC) Write(p []byte) (int, error)

Write implements io.Writer

type MsgPacket

type MsgPacket struct {
	Head MsgHead   // 消息头
	Msg  MsgReader // 消息
}

MsgPacket 消息包

func (MsgPacket) Read

func (mp MsgPacket) Read(p []byte) (int, error)

Read implements io.Reader

func (MsgPacket) Size

func (mp MsgPacket) Size() int

Size 大小

type MsgRPCReply

type MsgRPCReply struct {
	CorrId int64         // 关联Id,用于支持Future等异步模型
	Rets   variant.Array // 调用结果
	Error  variant.Error // 调用错误
}

MsgRPCReply RPC答复

func (MsgRPCReply) MsgId

func (MsgRPCReply) MsgId() MsgId

MsgId 消息Id

func (MsgRPCReply) Read

func (m MsgRPCReply) Read(p []byte) (int, error)

Read implements io.Reader

func (MsgRPCReply) Size

func (m MsgRPCReply) Size() int

Size 大小

func (*MsgRPCReply) Write

func (m *MsgRPCReply) Write(p []byte) (int, error)

Write implements io.Writer

type MsgRPCRequest

type MsgRPCRequest struct {
	CorrId    int64             // 关联Id,用于支持Future等异步模型
	CallChain variant.CallChain // 调用链
	Path      string            // 调用路径
	Args      variant.Array     // 参数列表
}

MsgRPCRequest RPC请求

func (MsgRPCRequest) MsgId

func (MsgRPCRequest) MsgId() MsgId

MsgId 消息Id

func (MsgRPCRequest) Read

func (m MsgRPCRequest) Read(p []byte) (int, error)

Read implements io.Reader

func (MsgRPCRequest) Size

func (m MsgRPCRequest) Size() int

Size 大小

func (*MsgRPCRequest) Write

func (m *MsgRPCRequest) Write(p []byte) (int, error)

Write implements io.Writer

type MsgReader

type MsgReader interface {
	io.Reader
	// Size 大小
	Size() int
	// MsgId 消息Id
	MsgId() MsgId
}

MsgReader 读取消息

type MsgWriter

type MsgWriter interface {
	io.Writer
	// Size 大小
	Size() int
	// MsgId 消息Id
	MsgId() MsgId
}

MsgWriter 写入消息

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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