protocol

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PACKAGE_ERROR = iota
	PACKAGE_FULL
	PACKAGE_LESS
)
View Source
const (
	INVALID_MSG   uint32 = iota //0 无效类型
	REQUEST_MSG                 // 1 调用请求
	RESPONESE_MSG               // 2 调用返回
	NOTRPC_MSG                  // 3 非RPC协议
)
View Source
const (
	IDL_SUCCESS uint32 = iota + 1
	IDL_SERVICE_NOT_FOUND
	IDL_SERVICE_ERROR
	IDL_RPC_TIME_OUT
)
View Source
const (
	SERVICE_RESOLVED = iota + 1 //状态
	SERVICE_UPDATING
)

Variables

View Source
var (
	RpcHeadSize  int
	CallHeadSize int
	RespHeadSize int
)

Functions

func BuildRespHeader

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

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 Protocol

type Protocol interface {
	ReadHeader(pkg []byte, header *RpcMsgHeader) bool
	ParseReqMsg(pkg []byte, header *RpcCallHeader) bool
	ParseRespMsg(pkg []byte, header *RpcCallRetHeader) bool
	PackRespMsg(resp *ResponsePackage) ([]byte, int)
	PackReqMsg(req *RequestPackage) ([]byte, int)
}

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 BuildNotFount

func BuildNotFount(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
}

func ReadCallHeader

func ReadCallHeader(pkg []byte) *RpcCallHeader

type RpcCallRetHeader

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

func ReadRetHeader

func ReadRetHeader(pkg []byte) *RpcCallRetHeader

type RpcMsgHeader

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

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

func ReadHeader

func ReadHeader(pkg []byte) *RpcMsgHeader

Jump to

Keyboard shortcuts

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