packing

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2021 License: MIT Imports: 5 Imported by: 1

Documentation

Index

Constants

View Source
const (
	UnknownType = iota
	OKType
	ErrType
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultPacker

type DefaultPacker struct {
	// MaxDataSize represents the max size of `data`
	MaxDataSize int
}

DefaultPacker is the default Packer used in session. Treats the packet with the format:

dataSize(4)|id(4)|data(n)

| segment | type | size | remark | | ---------- | ------ | ------- | ----------------------- | | `dataSize` | uint32 | 4 | the size of `data` only | | `id` | uint32 | 4 | | | `flag` | uint16 | 2 | | | `data` | []byte | dynamic | | .

func NewDefaultPacker

func NewDefaultPacker() *DefaultPacker

NewDefaultPacker create a *DefaultPacker with initial field value.

func (*DefaultPacker) Pack

func (d *DefaultPacker) Pack(msg *message.Message) ([]byte, error)

Pack implements the Packer Pack method.

func (*DefaultPacker) Unpack

func (d *DefaultPacker) Unpack(reader io.Reader) (*message.Message, error)

Unpack implements the Packer Unpack method. Unpack returns the msg whose ID is type of int. So we need use int id to register routes.

type Packer

type Packer interface {
	// Pack packs Message into the packet to be written.
	Pack(msg *message.Message) ([]byte, error)

	// Unpack unpacks the message packet from reader,
	// returns the Message, and error if error occurred.
	Unpack(reader io.Reader) (*message.Message, error)
}

Packer is a generic interface to pack and unpack message packet.

Jump to

Keyboard shortcuts

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