echoprotocol

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NetPackHeadSize head size, fixed 12 bytes
	NetPackHeadSize = 12
	// NetPackBeginstrSize head begin string size
	NetPackBeginstrSize = 4
	// NetPackTimestampSize head timestamp size
	NetPackTimestampSize = 4
	// NetPackDataLenSize head DataLen size
	NetPackDataLenSize = 4
)

Variables

This section is empty.

Functions

func Depack

func Depack(rawData []byte) (rawDataLocal []byte, outPacks []interface{}, bOk bool, strErrMsg string)

Depack depack

@param rawData []byte : origin data @return []byte : data left after depack @return *list.List[]NetPacket : depacked package lists @return bool : is depack success

true -- success
false -- have error, check errMsg

@return string : err msgs when depack

func Htonl32

func Htonl32(iNum uint32) []byte

Htonl32 host to net long 32bit

func Htonll64

func Htonll64(iNum uint64) []byte

Htonll64 host to net long long 64bit

func Ntohl32

func Ntohl32(byData []byte) (uint32, bool)

Ntohl32 net to host long 32bit

func Ntohll64

func Ntohll64(byData []byte) (uint64, bool)

Ntohll64 net to host long long 64bit

func Pack

func Pack(msg interface{}, timestamp uint32) ([]byte, bool, string)

Pack pack

@param msg string : msg content @param timestamp uint32 : timestamp,when not 0, use incoming timestamp @return []byte : []byte after pack @return bool : is pack success

true -- success
false -- have error, check errMsg

@return string : err msgs when pack

Types

type EchoMsg

type EchoMsg struct {
	// BeginString 4byte 0-3
	BeginString [4]byte
	// Timestamp 4byte 4-7
	Timestamp uint32
	// DataLen RawData length 8-11
	DataLen uint32
	// RawData
	RawData []byte
}

EchoMsg message sends between client and server

it will be like

0             11    DataLen
| --  HEAD -- | --  RawData -- |

Jump to

Keyboard shortcuts

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