frame

package
v3.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2021 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

View Source
const FRAME_OPTIONS_MAX_SIZE = 40 //nolint:stylecheck,golint
View Source
const WORD = 4 //nolint:stylecheck,golint

Variables

This section is empty.

Functions

This section is empty.

Types

type Flag

type Flag byte
const (
	CONTROL       Flag = 0x01
	CODEC_RAW     Flag = 0x04 //nolint:stylecheck,golint
	CODEC_JSON    Flag = 0x08 //nolint:stylecheck,golint
	CODEC_MSGPACK Flag = 0x10 //nolint:stylecheck,golint
	CODEC_GOB     Flag = 0x20 //nolint:stylecheck,golint
	ERROR         Flag = 0x40 //nolint:stylecheck,golint
	RESERVED1     Flag = 0x80
)

BYTE flags, it means, that we can set multiply flags from this group using bitwise OR For example CONTEXT_SEPARATOR | CODEC_RAW

const (
	RESERVED2 Flag = 0x81
	RESERVED3 Flag = 0x82
	RESERVED4 Flag = 0x83
	RESERVED5 Flag = 0x84
)

COMPLEX flags can't be used with Byte flags, because it's value more than 128

type Frame

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

Frame defines new user level package format.

func From

func From(header []byte, payload []byte) *Frame

MergeHeader merge header from other frame with original payload

func NewFrame

func NewFrame() *Frame

func ReadFrame

func ReadFrame(data []byte) *Frame

func ReadHeader

func ReadHeader(data []byte) *Frame

ReadHeader reads only header, without payload

func (*Frame) AppendOptions

func (f *Frame) AppendOptions(opts []byte)

AppendOptions appends options to the header

func (*Frame) Bytes

func (f *Frame) Bytes() []byte

Bytes returns header with payload

func (*Frame) Header

func (f *Frame) Header() []byte

Header returns frame header

func (*Frame) Payload

func (f *Frame) Payload() []byte

Payload returns frame payload without header

func (*Frame) ReadFlags

func (f *Frame) ReadFlags() byte

Flags is full 1st byte

func (*Frame) ReadHL

func (f *Frame) ReadHL() byte

The lower 4 bits of the 0th octet occupies our header len data. We should erase upper 4 bits, which contain information about Version To erase, we applying bitwise AND to the upper 4 bits and returning result

func (*Frame) ReadOptions

func (f *Frame) ReadOptions() []uint32

f.readHL() - 2 needed to know actual options size we know, that 2 WORDS is minimal header len extra WORDS will add extra 32bits to the options (4 bytes)

func (*Frame) ReadPayloadLen

func (f *Frame) ReadPayloadLen() uint32

LE format used to write Payload Using 4 bytes (2,3,4,5 bytes in the header)

func (*Frame) ReadVersion

func (f *Frame) ReadVersion() byte

To read version, we should return our 4 upper bits to their original place 1111_0000 -> 0000_1111 (15)

func (*Frame) VerifyCRC

func (f *Frame) VerifyCRC() bool

Reading info from 6th byte and verifying it with calculated in-place. Should be equal. If not - drop the frame as incorrect.

func (*Frame) WriteCRC

func (f *Frame) WriteCRC()

Calculating CRC and writing it to the 6th byte (7th reserved)

func (*Frame) WriteFlags

func (f *Frame) WriteFlags(flags ...Flag)

func (*Frame) WriteOptions

func (f *Frame) WriteOptions(options ...uint32)

Options slice len should not be more than 10 (40 bytes)

func (*Frame) WritePayload

func (f *Frame) WritePayload(data []byte)

func (*Frame) WritePayloadLen

func (f *Frame) WritePayloadLen(len uint32)

LE format used to write Payload Using 4 bytes (2,3,4,5 bytes in the header)

func (*Frame) WriteVersion

func (f *Frame) WriteVersion(version Version)

To write version, we should made the following: 1. For example we have version 15 it's 0000_1111 (1 byte) 2. We should shift 4 lower bits to upper and write that to the 0th byte 3. The 0th byte should become 1111_0000, but it's not 240, it's only 15, because version only 4 bits len

type Version

type Version byte
const (
	VERSION_1 Version = 0x01 //nolint:stylecheck,golint
)

Jump to

Keyboard shortcuts

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