protocol

package
v0.0.0-...-bf94cd9 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

通讯协议处理,主要处理封包和解包的过程

Index

Constants

View Source
const TypeBroatcast = "3"
View Source
const TypeError = "5"
View Source
const TypePing = "7"
View Source
const TypePush = "4"
View Source
const TypeReply = "6"
View Source
const TypeReq = "1"
View Source
const TypeResp = "2"

Variables

This section is empty.

Functions

func DecodePacket

func DecodePacket(r *bufio.Reader) (uint32, []byte, []byte, []byte, error)

func EncodePacket

func EncodePacket(_type string, header []byte, payload []byte) ([]byte, error)

func HubPack

func HubPack(cmd, sid, callback_seq string, payload []byte) ([]byte, error)

func HubUnPack

func HubUnPack(r *bufio.Reader) ([]byte, []byte, []byte, []byte, error)

Types

type BaseRoot

type BaseRoot struct {
	Type   string      `json:"type"`
	Header interface{} `json:"header"`
	Data   []byte      `json:"data"`
}

type BroatcastHeader

type BroatcastHeader struct {
	AreaId string `json:"area_id"`
	Sid    string `json:"sid"`
}

type BroatcastRoot

type BroatcastRoot struct {
	Type   string          `json:"type"`
	Header BroatcastHeader `json:"header"`
	Data   interface{}     `json:"data"`
}

type ClientPacket

type ClientPacket struct {
	TotalSize  uint32 //4
	Type       uint8
	HeaderSize uint32 //4
	Header     []byte
	Payload    []byte
	Checksum   uint32 //4
}

|总长度4|type4|头长度4|header|data|checksum

type Json

type Json struct {
	ProtocolObj ProtocolType
	Data        []byte
}

func (*Json) GetBroatcastObj

func (this *Json) GetBroatcastObj(data []byte) (*BroatcastRoot, error)

func (*Json) GetPushObj

func (this *Json) GetPushObj(data []byte) (*PushRoot, error)

func (*Json) GetReqObj

func (this *Json) GetReqObj(data []byte) (*ReqRoot, error)

func (*Json) GetRespObj

func (this *Json) GetRespObj(data []byte) (*ResponseRoot, error)

func (*Json) Init

func (this *Json) Init() *Json

func (*Json) WrapBroatcastRespObj

func (this *Json) WrapBroatcastRespObj(area_id string, from_sid string, data []byte) BroatcastRoot

func (*Json) WrapPushResp

func (this *Json) WrapPushResp(to_sid string, from_sid string, data []byte) []byte

func (*Json) WrapPushRespObj

func (this *Json) WrapPushRespObj(to_sid string, from_sid string, data []byte) PushRoot

func (*Json) WrapResp

func (this *Json) WrapResp(header []byte, data []byte, status int, msg string) []byte

func (*Json) WrapRespErr

func (this *Json) WrapRespErr(err string) []byte

*

  • 封包返回客户端错误的消息

func (*Json) WrapRespObj

func (this *Json) WrapRespObj(req_obj *ReqRoot, invoker_ret []byte, status int) ResponseRoot

type Pack

type Pack struct {
	ProtocolObj ProtocolType
	Data        []byte
}

func (*Pack) GetBroatcastHeaderObj

func (this *Pack) GetBroatcastHeaderObj(header []byte) (*BroatcastHeader, error)

func (*Pack) GetBroatcastObj

func (this *Pack) GetBroatcastObj(data []byte) (*BroatcastRoot, error)

func (*Pack) GetPushObj

func (this *Pack) GetPushObj(data []byte) (*PushRoot, error)

func (*Pack) GetReqHeaderObj

func (this *Pack) GetReqHeaderObj(header []byte) (*ReqHeader, error)

func (*Pack) GetReqObj

func (this *Pack) GetReqObj(_type uint32, header []byte, data []byte) (*ReqRoot, error)

func (*Pack) GetReqObjByReader

func (this *Pack) GetReqObjByReader(reader *bufio.Reader) (*ReqRoot, error)

func (*Pack) GetRespHeaderObj

func (this *Pack) GetRespHeaderObj(header []byte) (*RespHeader, error)

func (*Pack) GetRespObj

func (this *Pack) GetRespObj(_type uint32, header []byte, data []byte) (*ResponseRoot, error)

func (*Pack) Init

func (this *Pack) Init() *Pack

func (*Pack) WrapBroatcastResp

func (this *Pack) WrapBroatcastResp(area_id, from_sid string, data []byte) ([]byte, error)

func (*Pack) WrapBroatcastRespObj

func (this *Pack) WrapBroatcastRespObj(area_id, from_sid string, data []byte) BroatcastRoot

func (*Pack) WrapPushResp

func (this *Pack) WrapPushResp(to_sid string, from_sid string, data_buf []byte) ([]byte, error)

func (*Pack) WrapPushRespObj

func (this *Pack) WrapPushRespObj(to_sid string, from_sid string, data []byte) PushRoot

func (*Pack) WrapReq

func (this *Pack) WrapReq(cmd, sid, token string, seq int, data []byte) ([]byte, error)

func (*Pack) WrapReqWithHeader

func (this *Pack) WrapReqWithHeader(req_header *ReqHeader, data []byte) ([]byte, error)

func (*Pack) WrapResp

func (this *Pack) WrapResp(cmd, req_sid string, seq int, status int, data []byte) ([]byte, error)

func (*Pack) WrapRespErr

func (this *Pack) WrapRespErr(err string) ([]byte, error)

*

  • 封包返回客户端错误的消息

func (*Pack) WrapRespObj

func (this *Pack) WrapRespObj(req_obj *ReqRoot, invoker_ret []byte, status int) ResponseRoot

type ProtocolType

type ProtocolType struct {
	ReqObj       ReqRoot
	RespObj      ResponseRoot
	BroatcastObj BroatcastRoot
	PushObj      PushRoot
	Init         func()
}

type PushHeader

type PushHeader struct {
	Sid string `json:"sid"`
}

type PushRoot

type PushRoot struct {
	Type   string      `json:"type"`
	Header PushHeader  `json:"header"`
	Data   interface{} `json:"data"`
}

type ReqHeader

type ReqHeader struct {
	Cmd     string `json:"cmd"`
	SeqId   int    `json:"seq_id"`
	Sid     string `json:"sid"`
	NoResp  bool   `json:"no_resp"`
	Token   string `json:"token"`
	Version string `json:"version"`
	Gzip    bool   `json:"gzip"`
}

type ReqRoot

type ReqRoot struct {
	Type   string      `json:"type"`
	Header ReqHeader   `json:"header"`
	WsData interface{} `json:"data"`
	Data   []byte
}

type RespHeader

type RespHeader struct {
	Cmd    string `json:"cmd"`
	SeqId  int    `json:"seq_id"`
	Sid    string `json:"sid"`
	Gzip   bool   `json:"gzip"`
	Status int    `json:"status"`
}

type ResponseRoot

type ResponseRoot struct {
	Type   string     `json:"type"`
	Header RespHeader `json:"header"`
	Data   []byte     `json:"data"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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