codec

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2024 License: MIT Imports: 2 Imported by: 0

README

codec

generic set of tools build around a standard codec interface

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode1Byte

func Decode1Byte(byteOrder binary.ByteOrder, source []byte) int

func Decode2Byte

func Decode2Byte(byteOrder binary.ByteOrder, source []byte) int

func Decode4Byte

func Decode4Byte(byteOrder binary.ByteOrder, source []byte) int

func Decode8Byte

func Decode8Byte(byteOrder binary.ByteOrder, source []byte) int

func MakeSimpleDataFrame

func MakeSimpleDataFrame(data []byte) []byte

MakeSimpleDataFrame returns a new buffer with the length prepended as a 4 byte big endian unsigned integer. The length includes its own size in the calculation

Types

type Codec

type Codec interface {
	// Encodes a byte array and returns the encoded byte array.  If no encoded data is available, `nil` will be returned.
	// If an empty/null payload is passed to encode, the chain of codecs will be flushed for any remaining data which has not
	// yet been encoded.
	Encode(data []byte) ([]byte, error)

	// Decodes a byte array and returns the decoded byte array.  If a decoder buffers and/or insufficient data is
	// available, `nil` will be returned.
	Decode([]byte) ([]byte, error)
}

type CodecChain

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

CodecChain returns a Codec interface representing a chain of codecs

func NewCodecChain

func NewCodecChain(codecs ...Codec) *CodecChain

func (*CodecChain) Decode

func (cc *CodecChain) Decode(data []byte) ([]byte, error)

func (*CodecChain) Encode

func (cc *CodecChain) Encode(data []byte) ([]byte, error)

type Config

type Config struct {
	LengthOffset         int
	LengthFieldInBytes   int
	LengthFieldByteOrder binary.ByteOrder
	SizeBiasInBytes      int // The size bias is the number of bytes which should be added (including negative numbers) to the length in order to determine the entire frame size
	// contains filtered or unexported fields
}

type FrameBuffer

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

FrameBuffer is a buffer intended to parse and emit arbitrary framed data, where all that needs to be known is the length offset in the frame payload, the size of the length field, and the endianness of the data.

func NewFrameBuffer

func NewFrameBuffer(config Config) *FrameBuffer

func (*FrameBuffer) Read

func (fb *FrameBuffer) Read() []byte

func (*FrameBuffer) Write

func (fb *FrameBuffer) Write(data []byte)

Jump to

Keyboard shortcuts

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