utils

package
v0.0.0-...-c16d89f Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CODEC_MAGIC  = 0x3fd76c17
	FOOTER_MAGIC = 0xc02893e8
)
View Source
const (
	ID_LENGTH = 16
)

Variables

View Source
var (
	NEWLINE  = byte('\n')
	ESCAPE   = byte('\\')
	CHECKSUM = []byte("checksum ")
)

Functions

func CheckFooter

func CheckFooter(input store.ChecksumIndexInput) error

func CheckHeader

func CheckHeader(in store.DataInput, codec string, minVersion, maxVersion int) (int, error)

CheckHeader Reads and validates a header previously written with writeHeader(DataOutput, String, int). When reading a file, supply the expected codec and an expected version range (minVersion to maxVersion). Params: in – Input stream, positioned at the point where the header was previously written. Typically this is located at the beginning of the file. codec – The expected codec name. minVersion – The minimum supported expected version number. maxVersion – The maximum supported expected version number. Returns: The actual version found, when a valid header is found that matches codec, with an actual version where minVersion <= actual <= maxVersion. Otherwise an exception is thrown. Throws: CorruptIndexException – If the first four bytes are not CODEC_MAGIC, or if the actual codec found is not codec.

IndexFormatTooOldException – If the actual version is less than minVersion.
IndexFormatTooNewException – If the actual version is greater than maxVersion.
IOException – If there is an I/O error reading from the underlying medium.

See Also: writeHeader(DataOutput, String, int)

func CheckHeaderNoMagic

func CheckHeaderNoMagic(in store.DataInput, codec string, minVersion, maxVersion int) (int, error)

CheckHeaderNoMagic Like checkHeader(DataInput, String, int, int) except this version assumes the first int has already been read and validated from the input.

func CheckIndexHeaderSuffix

func CheckIndexHeaderSuffix(in store.DataInput, expectedSuffix string) (string, error)

func FooterLength

func FooterLength() int

FooterLength Computes the length of a codec footer. Returns: length of the entire codec footer. See Also: writeFooter(IndexOutput)

func NewLine

func NewLine(out store.DataOutput) error

func ParseInt

func ParseInt(scratch *bytes.Buffer, prefix []byte) (int, error)

func ReadLine

func ReadLine(in store.IndexInput, buf *bytes.Buffer) error

func ReadValue

func ReadValue(out store.IndexInput, label []byte, buf *bytes.Buffer) (string, error)

func WriteBytes

func WriteBytes(out store.DataOutput, bs []byte) error

func WriteChecksum

func WriteChecksum(out store.IndexOutput) error

func WriteFooter

func WriteFooter(out store.IndexOutput) error

WriteFooter Writes a codec footer, which records both a checksum algorithm ID and a checksum. This footer can be parsed and validated with checkFooter(). CodecFooter --> Magic,AlgorithmID,Checksum Magic --> Uint32. This identifies the start of the footer. It is always -1071082520. AlgorithmID --> Uint32. This indicates the checksum algorithm used. Currently this is always 0, for zlib-crc32. Checksum --> Uint64. The actual checksum value for all previous bytes in the stream, including the bytes from Magic and AlgorithmID. Params: out – Output stream Throws: IOException – If there is an I/O error writing to the underlying medium.

func WriteHeader

func WriteHeader(ctx context.Context, out store.DataOutput, codec string, version int) error

WriteHeader Writes a codec header, which records both a string to identify the file and a version number. This header can be parsed and validated with checkHeader(). CodecHeader --> Magic,CodecName,Version Magic --> Uint32. This identifies the start of the header. It is always 1071082519. CodecName --> String. This is a string to identify this file. Version --> Uint32. Records the version of the file. Note that the length of a codec header depends only upon the name of the codec, so this length can be computed at any time with headerLength(String). Params: out – Output stream codec – String to identify this file. It should be simple ASCII, less than 128 characters in length. version – Version number Throws: IOException – If there is an I/O error writing to the underlying medium.

IllegalArgumentException – If the codec name is not simple ASCII, or is more than 127 characters in length

func WriteIndexHeader

func WriteIndexHeader(ctx context.Context, out store.DataOutput, codec string, version int, id []byte, suffix string) error

func WriteString

func WriteString(out store.DataOutput, s string) error

Types

type Buffer

type Buffer struct {
	*bytes.Buffer
}

type TextReader

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

func NewTextReader

func NewTextReader(in store.IndexInput, buf *bytes.Buffer) *TextReader

func (*TextReader) ParseBoolPrefix

func (t *TextReader) ParseBoolPrefix(prefix []byte) (bool, error)

func (*TextReader) ParseBytes

func (t *TextReader) ParseBytes(label []byte) ([]byte, error)

func (*TextReader) ParseInt

func (t *TextReader) ParseInt(prefix []byte) (int, error)

func (*TextReader) ParseInt64

func (t *TextReader) ParseInt64(prefix []byte) (int64, error)

func (*TextReader) ParseString

func (t *TextReader) ParseString(label []byte) (string, error)

func (*TextReader) ReadLabel

func (t *TextReader) ReadLabel(label []byte) (string, error)

func (*TextReader) ReadLine

func (t *TextReader) ReadLine() error

func (*TextReader) StartsWith

func (t *TextReader) StartsWith(label []byte) (bool, error)

type TextWriter

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

func NewTextWriter

func NewTextWriter(out store.IndexOutput) *TextWriter

func (*TextWriter) Bytes

func (t *TextWriter) Bytes(bs []byte) error

func (*TextWriter) Checksum

func (t *TextWriter) Checksum() error

func (*TextWriter) Int

func (t *TextWriter) Int(v int) error

func (*TextWriter) Long

func (t *TextWriter) Long(v int64) error

func (*TextWriter) NewLine

func (t *TextWriter) NewLine() error

func (*TextWriter) String

func (t *TextWriter) String(v string) error

func (*TextWriter) Write

func (t *TextWriter) Write(v any) error

func (*TextWriter) WriteLabelBool

func (t *TextWriter) WriteLabelBool(label []byte, v bool) error

func (*TextWriter) WriteLabelBytes

func (t *TextWriter) WriteLabelBytes(label, v []byte) error

func (*TextWriter) WriteLabelInt

func (t *TextWriter) WriteLabelInt(label []byte, v int) error

func (*TextWriter) WriteLabelLong

func (t *TextWriter) WriteLabelLong(label []byte, v int64) error

func (*TextWriter) WriteLabelString

func (t *TextWriter) WriteLabelString(label []byte, v string) error

Jump to

Keyboard shortcuts

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