frame

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package frame contains utilities to implement various network protocols and describe their relationship within Lucius. Each supported network protocol implements the interface protocol.Handler and registers a parse and (an optional) add handler.

Index

Constants

View Source
const ByteBitCount = 8

ByteBitCount is the number of bits in a byte.

View Source
const Uint32BitCount = 4 * ByteBitCount

Uint32BitCount is the number of bits in a uint32.

View Source
const Uint64BitCount = 8 * ByteBitCount

Uint64BitCount is the number of bits in a uint64.

Variables

This section is empty.

Functions

func Resize

func Resize(field []byte, size int) []byte

Resize returns a slice of bytes either padded or truncated to the specified number of bytes. The intent of resize is to be used with the frame utilities which operate on bytes that represent data in network order. For padding data, zeroes are added at the MSB and when truncating data, the MSB is stripped.

Types

type Field

type Field []byte

A Field is a slice of bytes within a header. Fields of certain sizes may contain numeric data in BigEndian format.

func (Field) BitField

func (f Field) BitField(bitpos, bitcount uint8) Field

BitField creates a new field using bitcount bits at position bitpos in a numeric field.

func (Field) Copy

func (f Field) Copy() Field

Copy returns a copy of the field.

func (Field) Set

func (f Field) Set(value []byte) error

Set sets all the bytes of the field.

func (Field) SetBits

func (f Field) SetBits(bitpos, bitcount uint8, bitmask uint64)

SetBits sets bitcount bits at position bitpos in a numeric field.

func (Field) SetValue

func (f Field) SetValue(value uint)

SetValue sets a numeric field's value.

func (Field) Value

func (f Field) Value() uint

Value gets a numeric field's value.

type Frame

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

A Frame is a set of bytes that can be read sequentially (or parsed) as a series of packet headers.

func NewFrame

func NewFrame(buffer []byte) *Frame

NewFrame creates a new frame from a slice of bytes.

func (*Frame) Len

func (f *Frame) Len() int

Len returns the number of unread bytes in the frame.

func (*Frame) Peek

func (f *Frame) Peek(off, n int) (Field, error)

Peek creates a field of n bytes at offset off from the read position. If the specified bytes do not exist, an error is returned.

func (*Frame) ReadHeader

func (f *Frame) ReadHeader(n int) (Header, error)

ReadHeader reads a header of n bytes from the read position. If the specified bytes do not exist, an error is returned.

func (*Frame) String

func (f *Frame) String() string

String formats unread bytes in a frame as a string.

func (*Frame) StripTrailing

func (f *Frame) StripTrailing(n int) error

StripTrailing strips the trailing 'n' bytes from the buffer. Note that there must be at-least 'n' unread bytes in the frame.

type Header []byte

A Header is a sequence of fields of a protocol within a frame.

func (Header) Field

func (h Header) Field(off, n int) Field

Field returns a field of n bytes at offset off within the header.

Jump to

Keyboard shortcuts

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