gap

package
v0.1.42 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2024 License: LGPL-2.1 Imports: 8 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 (
	ErrNotRegistered = errors.New("gap: msg not registered") // 消息未注册
)

Functions

func Marshal added in v0.1.36

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

func Unmarshal added in v0.1.36

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

Types

type IMsgCreator

type IMsgCreator interface {
	// Register 注册消息
	Register(msg Msg)
	// Deregister 取消注册消息
	Deregister(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 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   = 128        // 自定义消息起点
)

type MsgOneWayRPC

type MsgOneWayRPC struct {
	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  Msg     // 消息
}

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 大小

func (*MsgPacket) Write

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

Write implements io.Writer

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等异步模型
	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 MsgRaw added in v0.1.32

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

MsgRaw 原始消息

func (MsgRaw) MsgId added in v0.1.32

func (m MsgRaw) MsgId() MsgId

MsgId 消息Id

func (MsgRaw) Read added in v0.1.32

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

Read implements io.Reader

func (MsgRaw) Size added in v0.1.32

func (m MsgRaw) Size() int

Size 大小

func (*MsgRaw) Write added in v0.1.32

func (m *MsgRaw) 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