protocol

package
v0.0.0-...-ec06bad Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2023 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnexpectedMsgSize = errors.New("unexpected message size")
	ErrInvalidMsgType    = errors.New("invalid message type")
)

Functions

func WriteMsg

func WriteMsg(w io.Writer, e msg) error

Types

type Ack

type Ack struct {
	O bool
	M string
}

func NewAck

func NewAck(ok bool, msg string) *Ack

func (*Ack) Msg

func (a *Ack) Msg() string

func (*Ack) Ok

func (a *Ack) Ok() bool

func (*Ack) Type

func (a *Ack) Type() MsgType

type Handshake

type Handshake struct {
	Id string
}

func NewHandshake

func NewHandshake(id string) *Handshake

func (*Handshake) ID

func (h *Handshake) ID() string

func (*Handshake) Type

func (h *Handshake) Type() MsgType

type Msg

type Msg struct {
	// contains filtered or unexported fields
}

func ReadMsg

func ReadMsg(r io.Reader) (*Msg, error)

func (*Msg) Ack

func (m *Msg) Ack() (*Ack, error)

func (*Msg) Handshake

func (m *Msg) Handshake() (*Handshake, error)

func (*Msg) Request

func (m *Msg) Request() (*Request, error)

func (*Msg) Response

func (m *Msg) Response() (*Response, error)

func (*Msg) Type

func (m *Msg) Type() MsgType

type MsgType

type MsgType byte
const (
	TypeHandshake MsgType = 1
	TypeAck       MsgType = 2
	TypeRequest   MsgType = 3
	TypeResponse  MsgType = 4
)

type Request

type Request struct {
	D []byte
}

func NewRequest

func NewRequest(d []byte) *Request

func (*Request) Data

func (r *Request) Data() []byte

func (*Request) Type

func (r *Request) Type() MsgType

type Response

type Response struct {
	// Use string type instead of error type since the type is lost
	// after gob encoding/decoding
	E string
	D []byte
}

func NewResponse

func NewResponse(d []byte, e error) *Response

func (*Response) Data

func (r *Response) Data() []byte

func (*Response) Error

func (r *Response) Error() error

func (*Response) Type

func (r *Response) Type() MsgType

Jump to

Keyboard shortcuts

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