encoding

package
v0.0.0-...-f8e07d0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2024 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSize     = errors.New("invalid size")
	ErrInvalidChecksum = errors.New("invalid checksum")
)
View Source
var ErrPoolStopped = errors.New("file handle pool is stopped")

Functions

This section is empty.

Types

type Decbuf

type Decbuf struct {
	E error
	// contains filtered or unexported fields
}

Decbuf provides safe methods to extract data from a binary file. It does all necessary bounds checking and advancing of the binary file. Several datums can be extracted without checking for errors. However, before using any datum, the Err() method must be checked. New file-backed Decbuf instances must be created via DecbufFactory

func (*Decbuf) Be32

func (d *Decbuf) Be32() uint32

func (*Decbuf) Be32int

func (d *Decbuf) Be32int() int

func (*Decbuf) Be64

func (d *Decbuf) Be64() uint64

func (*Decbuf) Byte

func (d *Decbuf) Byte() byte

func (*Decbuf) CheckCrc32

func (d *Decbuf) CheckCrc32(castagnoliTable *crc32.Table)

CheckCrc32 checks the integrity of the contents of this Decbuf, comparing the contents with the CRC32 checksum stored in the last four bytes. CheckCrc32 consumes the contents of this Decbuf.

func (*Decbuf) Close

func (d *Decbuf) Close() error

func (*Decbuf) Err

func (d *Decbuf) Err() error

func (*Decbuf) Len

func (d *Decbuf) Len() int

Len returns the remaining number of bytes in the underlying fileReader.

func (*Decbuf) Position

func (d *Decbuf) Position() int

Position returns the current position of the underlying fileReader. Calling d.ResetAt(d.Position()) is effectively a no-op.

func (*Decbuf) ResetAt

func (d *Decbuf) ResetAt(off int)

ResetAt sets the pointer of the underlying fileReader to the absolute offset and discards any buffered data. If E is non-nil, this method has no effect. ResetAt-ing beyond the end of the underlying fileReader will set E to an error and not advance the pointer of fileReader.

func (*Decbuf) Skip

func (d *Decbuf) Skip(l int)

Skip advances the pointer of the underlying fileReader by the given number of bytes. If E is non-nil, this method has no effect. Skip-ing beyond the end of the underlying fileReader will set E to an error and not advance the pointer of the fileReader.

func (*Decbuf) SkipUvarintBytes

func (d *Decbuf) SkipUvarintBytes()

SkipUvarintBytes advances the pointer of the underlying fileReader past the next varint-prefixed bytes. If E is non-nil, this method has no effect.

func (*Decbuf) UnsafeUvarintBytes

func (d *Decbuf) UnsafeUvarintBytes() []byte

UnsafeUvarintBytes reads varint prefixed bytes into a byte slice consuming them but without allocating. The bytes returned are NO LONGER VALID after subsequent reads from the Decbuf. If E is non-nil, this method returns an empty byte slice.

func (*Decbuf) Uvarint

func (d *Decbuf) Uvarint() int

func (*Decbuf) Uvarint64

func (d *Decbuf) Uvarint64() uint64

func (*Decbuf) UvarintStr

func (d *Decbuf) UvarintStr() string

UvarintStr reads varint prefixed bytes into a string and consumes them. The string returned allocates its own memory may be used after subsequent reads from the Decbuf. If E is non-nil, this method returns an empty string.

type DecbufFactory

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

DecbufFactory creates new file-backed decoding buffer instances for a specific index-header file.

func NewDecbufFactory

func NewDecbufFactory(path string, maxIdleFileHandles uint, metrics *DecbufFactoryMetrics) *DecbufFactory

func (*DecbufFactory) NewDecbufAtChecked

func (df *DecbufFactory) NewDecbufAtChecked(offset int, table *crc32.Table) Decbuf

NewDecbufAtChecked returns a new file-backed decoding buffer positioned at offset + 4 bytes. It expects the first 4 bytes after offset to hold the big endian encoded content length, followed by the contents and the expected checksum. This method checks the CRC of the content and will return an error Decbuf if it does not match the expected CRC.

func (*DecbufFactory) NewDecbufAtUnchecked

func (df *DecbufFactory) NewDecbufAtUnchecked(offset int) Decbuf

NewDecbufAtUnchecked returns a new file-backed decoding buffer positioned at offset + 4 bytes. It expects the first 4 bytes after offset to hold the big endian encoded content length, followed by the contents and the expected checksum. This method does NOT compute the CRC of the content. To check the CRC of the content, use NewDecbufAtChecked.

func (*DecbufFactory) NewRawDecbuf

func (df *DecbufFactory) NewRawDecbuf() Decbuf

NewRawDecbuf returns a new file-backed decoding buffer positioned at the beginning of the file, spanning the entire length of the file. It does not make any assumptions about the contents of the file, nor does it perform any form of integrity check. To create a decoding buffer for some subset of the file or perform integrity checks use NewDecbufAtUnchecked or NewDecbufAtChecked.

func (*DecbufFactory) Stop

func (df *DecbufFactory) Stop()

Stop cleans up resources associated with this DecbufFactory

type DecbufFactoryMetrics

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

func NewDecbufFactoryMetrics

func NewDecbufFactoryMetrics(reg prometheus.Registerer) *DecbufFactoryMetrics

Jump to

Keyboard shortcuts

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