protocol

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2022 License: MIT Imports: 4 Imported by: 4

Documentation

Index

Constants

View Source
const (
	PACKAGE_ERROR = iota
	PACKAGE_FULL
	PACKAGE_LESS
)
View Source
const (
	INVALID_MSG      uint32 = iota //0 无效类型
	RequestMsg                     // 1 调用请求
	ResponseMsg                    // 2 调用返回
	ProxyRequestMsg                // 3 proxy模式调用请求
	ProxyResponseMsg               // 4 proxy 模式请求回调
	NotRpcMsg                      // 5 非RPC协议
	RpcEventSub                    // 6 订阅事件
	RpcEventPub                    // 7 发布事件
	RpcEventCancel                 // 8 取消订阅
)
View Source
const (
	IDL_SUCCESS uint32 = iota + 1
	IDL_SERVICE_NOT_FOUND
	IDL_SERVICE_ERROR
	IDL_RPC_TIME_OUT
	IDL_RPC_LIMIT
)

Variables

View Source
var (
	RpcHeadSize       int
	CallHeadSize      int
	RespHeadSize      int
	ProxyCallHeadSize int
	ProxyRetHeadSize  int
	SubHeaderSize     int
	PubHeaderSize     int
	CancelHeaderSize  int
)

Functions

func BuildProxyRespHeader

func BuildProxyRespHeader(resp *ProxyRespPackage, srvID uint32, callID uint32, errcode uint32, globalIndex GlobalIndexType)

func BuildRespHeader

func BuildRespHeader(resp *ResponsePackage, srvID uint32, callID uint32, errcode uint32)

func PackProxyReqMsg

func PackProxyReqMsg(req *ProxyRequestPackage) ([]byte, int)

func PackProxyRespMsg

func PackProxyRespMsg(resp *ProxyRespPackage) ([]byte, int)

func PackReqMsg

func PackReqMsg(req *RequestPackage) ([]byte, int)

func PackRespMsg

func PackRespMsg(resp *ResponsePackage) ([]byte, int)

func SetProtocl

func SetProtocl(cus_proto Protocol)

Types

type GlobalIndexType

type GlobalIndexType uint32 //global index type

RpcMsgHeader 协议包头 协议类型 协议长度

type Protocol

type Protocol interface {
	ReadHeader(pkg []byte, header *RpcMsgHeader) bool
	ParseReqMsg(pkg []byte, header *RpcCallHeader) bool
	ParseProxyReqMsg([]byte, *RpcProxyCallHeader) bool
	ParseRespMsg(pkg []byte, header *RpcCallRetHeader) bool
	ParseProxyRespMsg([]byte, *RpcProxyCallRetHeader) bool
	ParseSubMsg([]byte, *RpcSubHeader) bool
	ParsePubMsg([]byte, *RpcPubHeader) bool
	ParseCancelMsg([]byte, *RpcCancelSubHeader) bool
	PackRespMsg(resp *ResponsePackage) ([]byte, int)
	PackReqMsg(req *RequestPackage) ([]byte, int)
	PackProxyReqMsg(req *ProxyRequestPackage) ([]byte, int)
	PackProxyRespMsg(resp *ProxyRespPackage) ([]byte, int)
	PackSubMsg(header *RpcSubPackage) ([]byte, int)
	PackPubMsg(header *RpcPubPackage) ([]byte, int)
	PackCancelMsg(header *RpcCancelPackage) ([]byte, int)
}

type ProxyRequestPackage

type ProxyRequestPackage struct {
	Header *RpcProxyCallHeader
	Buffer []byte
}

type ProxyRespPackage

type ProxyRespPackage struct {
	Header *RpcProxyCallRetHeader
	Buffer []byte
}

func BuildProxyNotFound

func BuildProxyNotFound(req *RpcProxyCallHeader) (resp *ProxyRespPackage)

type RequestPackage

type RequestPackage struct {
	Header *RpcCallHeader //请求协议头
	Buffer []byte         //协议提二进制数据, 可以对接pb 或者自己的结构体
}

type ResponsePackage

type ResponsePackage struct {
	Header *RpcCallRetHeader //回包结构体
	Buffer []byte            //协议体二进制数据, 可以对接pb 或者自己的结构体
}

func BuildException

func BuildException(callID uint32) (resp *ResponsePackage)

BuildException build run exception response

func BuildNotFound

func BuildNotFound(req *RpcCallHeader) (resp *ResponsePackage)

func BuildTimeOut

func BuildTimeOut(callID uint32) (resp *ResponsePackage)

BuildTimeOut TODO use static variables

type RpcCallHeader

type RpcCallHeader struct {
	RpcMsgHeader
	ServiceUUID uint64 //服务UUID
	ServerID    uint32 //服务器实例ID
	CallID      uint32 //代理调用id
	MethodID    uint32 //方法id
}

RpcMsgHeader 协议包头 协议类型 协议长度

func ReadCallHeader

func ReadCallHeader(pkg []byte) *RpcCallHeader

type RpcCallRetHeader

type RpcCallRetHeader struct {
	RpcMsgHeader
	ServerID  uint32
	CallID    uint32
	ErrorCode uint32
}

RpcMsgHeader 协议包头 协议类型 协议长度

func ReadRetHeader

func ReadRetHeader(pkg []byte) *RpcCallRetHeader

type RpcCancelPackage added in v0.4.0

type RpcCancelPackage struct {
	Header *RpcCancelSubHeader
	Buffer []byte
}

type RpcCancelSubHeader added in v0.4.0

type RpcCancelSubHeader struct {
	RpcMsgHeader
	SubId [16]byte //订阅id
}

RpcCancelSubHeader 取消订阅消息头

type RpcMsgHeader

type RpcMsgHeader struct {
	Length uint32 //整个包长,包含头
	Type   uint32 //调用 返回 非rpc 请求
}

RpcMsgHeader 协议包头 协议类型 协议长度

func ReadHeader

func ReadHeader(pkg []byte) *RpcMsgHeader

type RpcProxyCallHeader

type RpcProxyCallHeader struct {
	RpcMsgHeader
	ServiceUUID uint64          //服务UUID
	ServerID    uint32          //服务器实例ID
	CallID      uint32          //代理调用id
	MethodID    uint32          //方法id
	GlobalIndex GlobalIndexType //代理节点标识
	OneWay      uint16          // 是否是one way节点
}

RpcMsgHeader 协议包头 协议类型 协议长度

func BuildProxyCallHeader

func BuildProxyCallHeader(header *RpcCallHeader, globalIndex GlobalIndexType) *RpcProxyCallHeader

func ReadProxyCallHeader

func ReadProxyCallHeader(pkg []byte) *RpcProxyCallHeader

type RpcProxyCallRetHeader

type RpcProxyCallRetHeader struct {
	RpcMsgHeader
	ServerID    uint32          //服务实例id
	CallID      uint32          //调用id对端赋值
	ErrorCode   uint32          //错误代码
	GlobalIndex GlobalIndexType //代理节点标识
}

RpcMsgHeader 协议包头 协议类型 协议长度

func ReadProxyRetHeader

func ReadProxyRetHeader(pkg []byte) *RpcProxyCallRetHeader

type RpcPubHeader added in v0.4.0

type RpcPubHeader struct {
	RpcMsgHeader
	SubId    [16]byte //订阅id
	ProxyId  uint32   //代理id
	ValueLen uint32   //附带数据长度
}

RpcPubHeader 发布事件消息头

type RpcPubPackage added in v0.4.0

type RpcPubPackage struct {
	Header *RpcPubHeader
	Buffer []byte
}

type RpcSubHeader added in v0.4.0

type RpcSubHeader struct {
	RpcMsgHeader
	SubId       [16]byte //订阅id
	ProxyId     uint32   //代理id
	ServiceUUID uint64   //服务uid
	ServiceID   uint32   //服务势力id
	NameLen     uint32   //事件名称长度
	DataLen     uint32   //数目长度
}

RpcSubHeader 订阅事件消息头

type RpcSubPackage added in v0.4.0

type RpcSubPackage struct {
	Header *RpcSubHeader
	Buffer []byte
}

Jump to

Keyboard shortcuts

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