proto

package
v1.0.1-0...-bf1a125 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2021 License: MIT Imports: 3 Imported by: 0

README

proto

This is a protocol to tansfer the TCP message from client to server, or server to client.

EXample

Documentation

Overview

Package proto .

Index

Constants

View Source
const (
	// OpRequest .
	OpRequest uint16 = iota + 1
	// OpResponse .
	OpResponse
)
View Source
const (
	// Ver1 .
	Ver1 uint16 = 1
	// Ver2 .
	Ver2 = 2
)

Variables

View Source
var (
	// ErrProtoHeaderLen .
	ErrProtoHeaderLen = errors.New("not matched proto header len")
	// ErrEmptyReader .
	ErrEmptyReader = errors.New("empty reader")
)

Functions

func ReadNBytes

func ReadNBytes(rr *bufio.Reader, N int) ([]byte, error)

ReadNBytes . read limitted `N` bytes from bufio.Reader.

Types

type Proto

type Proto struct {
	Ver  uint16
	Op   uint16 // Type of Proto
	Seq  uint16 // Seq of message, 0 means done, else means not finished
	Body []byte // Body of Proto
}

Proto .

func New

func New() *Proto

New .

func (*Proto) ReadTCP

func (p *Proto) ReadTCP(rr *bufio.Reader) (err error)

ReadTCP .

func (*Proto) WriteTCP

func (p *Proto) WriteTCP(wr *bufio.Writer) (err error)

WriteTCP . packLen(32bit):headerLen(16bit):ver(16bit):op(16bit):body

Jump to

Keyboard shortcuts

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