framer

package
v0.0.0-...-701ea4a Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package framer supports efficiently breaking chunks of binary data into frames.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Utf16leEOL is the bytes sequence for UTF-16 Little-Endian end-of-line char
	Utf16leEOL = []byte{'\n', 0x00}
	// Utf16beEOL is the bytes sequence for UTF-16 Big-Endian end-of-line char
	Utf16beEOL = []byte{0x00, '\n'}
)

Functions

This section is empty.

Types

type FrameMatcher

type FrameMatcher interface {
	// Find a frame in a prefix of buf, and return the slice containing the content
	// of that frame, together with the total number of bytes in that frame.  Return
	// `nil, 0` when no complete frame is present in buf.
	//
	// The `seen` argument is the length of `buf` last time this function was called,
	// and can be used to avoid repeating work when looking for a frame terminator.
	FindFrame(buf []byte, seen int) ([]byte, int)
}

FrameMatcher finds frames in a buffer

type Framer

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

Framer gets chunks of bytes (via Process(..)) and uses an EndLineMatcher to break those into frames, passing the results to its outputFn.

func NewFramer

func NewFramer(
	outputFn func(input *message.Message, rawDataLen int),
	framing Framing,
	contentLenLimit int,
) *Framer

NewFramer initializes a Framer.

The framer will break the input stream into messages using the given framing.

Content longer than the given limit will be broken into frames at that length, regardless of framing.

Each frame will be passed to outputFn, including both the content of the frame itself and the number of raw bytes matched to represent that frame. In general, the content does not contain framing data like newlines.

func (*Framer) GetFrameCount

func (fr *Framer) GetFrameCount() int64

GetFrameCount gets the number of frames this framer has processed. This is safe to call from any goroutine.

func (*Framer) Process

func (fr *Framer) Process(input *message.Message)

Process handles an incoming chunk of data. It will call outputFn for any recognized frames. Partial frames are maintained between calls to Process. The passed buffer is not used after return.

type Framing

type Framing int

Framing describes the kind of framing applied to the byte stream being broken.

const (
	// Newline-terminated text in UTF-8.  This also applies to ASCII and
	// single-byte extended ASCII encodings such as latin-1.
	UTF8Newline Framing = iota

	// Newline-terminated text in UTF-16-BE.
	UTF16BENewline

	// Newline-terminated text in UTF-16-LE.
	UTF16LENewline

	// Newline-terminated text in SHIFT-JIS.
	SHIFTJISNewline

	// NoFraming considers the given input as already framed.
	NoFraming

	// Docker log-stream format.
	//
	// WARNING: This bundles multiple docker frames together into a single "log
	// frame", looking for a utf-8 newline in the output.  All 8-byte binary
	// headers are included in the log frame.  The size in those headers is not
	// consulted.  The result does not include the trailing newlines.
	DockerStream
)

Framing values.

Jump to

Keyboard shortcuts

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