proto

package
v0.0.0-...-3bf600c Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const HeaderLength = 25

HeaderLength header packet length

Variables

View Source
var (
	ErrHeaderIsNil = errors.New("heaser is nil")
	ErrPkgNoEnough = errors.New("pkg no enough")
)

errors

Functions

func DecodeBody

func DecodeBody(body []byte, i interface{}) error

DecodeBody decode body

func Encode

func Encode(header *Header, i interface{}) ([]byte, error)

Encode encode header and object to buffer

func EncodeBody

func EncodeBody(i interface{}) ([]byte, error)

EncodeBody encode body

func EncodeHeader

func EncodeHeader(header *Header) ([]byte, error)

EncodeHeader encode the header use network byte order

func Write

func Write(conn net.Conn, header *Header, i interface{}) error

Write write header and i to conn

Types

type Command1Req

type Command1Req struct {
	Name string
}

type Command1Rsp

type Command1Rsp struct {
	Error error
	Greet string
}

type Command2Req

type Command2Req struct {
	NumLeft  int
	NumRight int
	OpType   OpType
}

type Command2Rsp

type Command2Rsp struct {
	Error  error
	Result int
}
type Header struct {
	Len       uint32 // header len plus body len
	Command   uint32
	Maybe0    uint64
	Maybe1    uint32
	Result    uint32
	IsRequest byte
}

Header proto header

func DecodeHeader

func DecodeHeader(pkg []byte) (*Header, error)

DecodeHeader decode the network byte order packet to Header

func Read

func Read(c net.Conn) (header *Header, body []byte, err error)

Read read header and body

type OpType

type OpType int
const (
	OpTypeAdd OpType = iota
	OpTypeMinus
	OpTypeMul
	OpTypeDiv
	OpTypeMod
)

Jump to

Keyboard shortcuts

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