frame

package
v3.8.2 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 1 Imported by: 20

Documentation

Index

Constants

View Source
const (
	CONTROL      byte = 0x01
	CodecRaw     byte = 0x04
	CodecJSON    byte = 0x08
	CodecMsgpack byte = 0x10
	CodecGob     byte = 0x20
	ERROR        byte = 0x40
	CodecProto   byte = 0x80

	// Version1 byte
	Version1 byte = 0x01

	// STREAM bit
	STREAM byte = 0x01
	// STOP command
	STOP byte = 0x02
	// PING command
	PING byte = 0x04
	// PONG command
	PONG byte = 0x08
)

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

View Source
const OptionsMaxSize = 40

OptionsMaxSize represents header's options maximum size

View Source
const WORD = 4

WORD represents 32bit word

Variables

This section is empty.

Functions

This section is empty.

Types

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

From will represent header and payload as a Frame

func NewFrame

func NewFrame() *Frame

NewFrame initializes new frame with 12-byte header and 100-byte reserved space for the payload

func ReadFrame

func ReadFrame(data []byte) *Frame

ReadFrame produces Frame from the RAW bytes first 12 bytes will be a header the rest - payload

func ReadHeader

func ReadHeader(data []byte) *Frame

ReadHeader reads only header, without payload

func (*Frame) AppendOptions

func (*Frame) AppendOptions(header *[]byte, options []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) HeaderPtr

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

HeaderPtr returns frame header pointer

func (*Frame) IsPing added in v3.8.0

func (*Frame) IsPing(header []byte) bool

func (*Frame) IsPong added in v3.8.0

func (*Frame) IsPong(header []byte) bool

func (*Frame) IsStop added in v3.4.0

func (*Frame) IsStop(header []byte) bool

func (*Frame) IsStream added in v3.4.0

func (*Frame) IsStream(header []byte) bool

func (*Frame) Payload

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

Payload returns frame payload without header

func (*Frame) ReadFlags

func (f *Frame) ReadFlags() byte

ReadFlags Flags is full 1st byte

func (*Frame) ReadHL

func (*Frame) ReadHL(header []byte) byte

ReadHL 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 are applying bitwise AND to the upper 4 bits and returning result

func (*Frame) ReadOptions

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

ReadOptions 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) cannot inline, cost 117 vs 80

func (*Frame) ReadPayloadLen

func (*Frame) ReadPayloadLen(header []byte) uint32

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

func (*Frame) ReadVersion

func (*Frame) ReadVersion(header []byte) byte

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

func (*Frame) Reset

func (f *Frame) Reset()

Reset a frame

func (*Frame) SetPingBit added in v3.8.0

func (*Frame) SetPingBit(header []byte)

func (*Frame) SetPongBit added in v3.8.0

func (*Frame) SetPongBit(header []byte)

func (*Frame) SetStopBit added in v3.4.0

func (*Frame) SetStopBit(header []byte)

func (*Frame) SetStreamFlag added in v3.4.0

func (*Frame) SetStreamFlag(header []byte)

func (*Frame) VerifyCRC

func (*Frame) VerifyCRC(header []byte) bool

VerifyCRC ... 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 (*Frame) WriteCRC(header []byte)

WriteCRC will calculate and write CRC32 4-bytes it to the 6th byte (7th reserved)

func (*Frame) WriteFlags

func (*Frame) WriteFlags(header []byte, flags ...byte)

func (*Frame) WriteOptions

func (f *Frame) WriteOptions(header *[]byte, options ...uint32)

WriteOptions Options slice len should not be more than 10 (40 bytes) we need a pointer to the header because we are reallocating the slice

func (*Frame) WritePayload

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

WritePayload writes payload

func (*Frame) WritePayloadLen

func (*Frame) WritePayloadLen(header []byte, payloadLen uint32)

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

func (*Frame) WriteVersion

func (*Frame) WriteVersion(header []byte, version byte)

WriteVersion To write version, we should do 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

Jump to

Keyboard shortcuts

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