kaitai

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2022 License: MIT Imports: 11 Imported by: 19

Documentation

Index

Constants

View Source
const APIVersion = 0x0001

APIVersion defines the currently used API version.

Variables

This section is empty.

Functions

func BytesStripRight

func BytesStripRight(s []byte, pad byte) []byte

BytesStripRight strips bytes of a given value off the end of the byte slice.

func BytesTerminate

func BytesTerminate(s []byte, term byte, includeTerm bool) []byte

BytesTerminate terminates the given byte slice using the provided sentinel, optionally including the sentinel itself in the terminated byte slice.

func BytesToStr

func BytesToStr(in []byte, decoder *encoding.Decoder) (string, error)

BytesToStr returns a string decoded by the given decoder.

func ProcessRotateLeft

func ProcessRotateLeft(data []byte, amount int) []byte

ProcessRotateLeft returns the single bytes in data rotated left by amount bits.

func ProcessRotateRight

func ProcessRotateRight(data []byte, amount int) []byte

ProcessRotateRight returns the single bytes in data rotated right by amount bits.

func ProcessXOR

func ProcessXOR(data []byte, key []byte) []byte

ProcessXOR returns data xored with the key.

func ProcessZlib

func ProcessZlib(in []byte) ([]byte, error)

ProcessZlib decompresses the given bytes as specified in RFC 1950.

func StringReverse

func StringReverse(s string) string

StringReverse returns the string s in reverse order.

Types

type EndOfStreamError

type EndOfStreamError struct{}

EndOfStreamError is returned when the stream unexpectedly ends.

func (EndOfStreamError) Error

func (EndOfStreamError) Error() string

type Stream

type Stream struct {
	io.ReadSeeker
	// contains filtered or unexported fields
}

A Stream represents a sequence of bytes. It encapsulates reading from files and memory, stores pointer to its current position, and allows reading/writing of various primitives.

func NewStream

func NewStream(r io.ReadSeeker) *Stream

NewStream creates and initializes a new Buffer based on r.

func (*Stream) AlignToByte

func (k *Stream) AlignToByte()

AlignToByte discards the remaining bits and starts reading bits at the next byte.

func (*Stream) EOF

func (k *Stream) EOF() (bool, error)

EOF returns true when the end of the Stream is reached.

func (*Stream) Pos

func (k *Stream) Pos() (int64, error)

Pos returns the current position of the stream.

func (*Stream) ReadBitsArray

func (k *Stream) ReadBitsArray(n uint) error

ReadBitsArray is not implemented yet.

func (*Stream) ReadBitsInt deprecated

func (k *Stream) ReadBitsInt(n uint8) (res uint64, err error)

ReadBitsInt reads n-bit integer in big-endian byte order and returns it as uint64.

Deprecated: Use ReadBitsIntBe instead.

func (*Stream) ReadBitsIntBe

func (k *Stream) ReadBitsIntBe(n int) (res uint64, err error)

ReadBitsIntBe reads n-bit integer in big-endian byte order and returns it as uint64.

func (*Stream) ReadBitsIntLe

func (k *Stream) ReadBitsIntLe(n int) (res uint64, err error)

ReadBitsIntLe reads n-bit integer in little-endian byte order and returns it as uint64.

func (*Stream) ReadBytes

func (k *Stream) ReadBytes(n int) (b []byte, err error)

ReadBytes reads n bytes and returns those as a byte array.

func (*Stream) ReadBytesFull

func (k *Stream) ReadBytesFull() ([]byte, error)

ReadBytesFull reads all remaining bytes and returns those as a byte array.

func (*Stream) ReadBytesPadTerm

func (k *Stream) ReadBytesPadTerm(size int, term, pad byte, includeTerm bool) ([]byte, error)

ReadBytesPadTerm reads up to size bytes. pad bytes are discarded. It terminates reading, when the term byte occurs. The term byte is included in the returned byte array when includeTerm is set.

func (*Stream) ReadBytesTerm

func (k *Stream) ReadBytesTerm(term byte, includeTerm, consumeTerm, eosError bool) ([]byte, error)

ReadBytesTerm reads bytes until the term byte is reached. If includeTerm is set the term bytes is included in the returned byte array. If consumeTerm is set the stream continues after the term byte. If eosError is set EOF errors result in an error.

func (*Stream) ReadF4be

func (k *Stream) ReadF4be() (v float32, err error)

ReadF4be reads 4 bytes in big-endian order and returns those as float32.

func (*Stream) ReadF4le

func (k *Stream) ReadF4le() (v float32, err error)

ReadF4le reads 4 bytes in little-endian order and returns those as float32.

func (*Stream) ReadF8be

func (k *Stream) ReadF8be() (v float64, err error)

ReadF8be reads 8 bytes in big-endian order and returns those as float64.

func (*Stream) ReadF8le

func (k *Stream) ReadF8le() (v float64, err error)

ReadF8le reads 8 bytes in little-endian order and returns those as float64.

func (*Stream) ReadS1

func (k *Stream) ReadS1() (v int8, err error)

ReadS1 reads 1 byte and returns this as int8.

func (*Stream) ReadS2be

func (k *Stream) ReadS2be() (v int16, err error)

ReadS2be reads 2 bytes in big-endian order and returns those as int16.

func (*Stream) ReadS2le

func (k *Stream) ReadS2le() (v int16, err error)

ReadS2le reads 2 bytes in little-endian order and returns those as int16.

func (*Stream) ReadS4be

func (k *Stream) ReadS4be() (v int32, err error)

ReadS4be reads 4 bytes in big-endian order and returns those as int32.

func (*Stream) ReadS4le

func (k *Stream) ReadS4le() (v int32, err error)

ReadS4le reads 4 bytes in little-endian order and returns those as int32.

func (*Stream) ReadS8be

func (k *Stream) ReadS8be() (v int64, err error)

ReadS8be reads 8 bytes in big-endian order and returns those as int64.

func (*Stream) ReadS8le

func (k *Stream) ReadS8le() (v int64, err error)

ReadS8le reads 8 bytes in little-endian order and returns those as int64.

func (*Stream) ReadStrByteLimit

func (k *Stream) ReadStrByteLimit(limit int, encoding string) (string, error)

ReadStrByteLimit reads limit number of bytes and returns those as a string.

func (*Stream) ReadStrEOS

func (k *Stream) ReadStrEOS(encoding string) (string, error)

ReadStrEOS reads the remaining bytes as a string.

func (*Stream) ReadU1

func (k *Stream) ReadU1() (v uint8, err error)

ReadU1 reads 1 byte and returns this as uint8.

func (*Stream) ReadU2be

func (k *Stream) ReadU2be() (v uint16, err error)

ReadU2be reads 2 bytes in big-endian order and returns those as uint16.

func (*Stream) ReadU2le

func (k *Stream) ReadU2le() (v uint16, err error)

ReadU2le reads 2 bytes in little-endian order and returns those as uint16.

func (*Stream) ReadU4be

func (k *Stream) ReadU4be() (v uint32, err error)

ReadU4be reads 4 bytes in big-endian order and returns those as uint32.

func (*Stream) ReadU4le

func (k *Stream) ReadU4le() (v uint32, err error)

ReadU4le reads 4 bytes in little-endian order and returns those as uint32.

func (*Stream) ReadU8be

func (k *Stream) ReadU8be() (v uint64, err error)

ReadU8be reads 8 bytes in big-endian order and returns those as uint64.

func (*Stream) ReadU8le

func (k *Stream) ReadU8le() (v uint64, err error)

ReadU8le reads 8 bytes in little-endian order and returns those as uint64.

func (*Stream) Size

func (k *Stream) Size() (int64, error)

Size returns the number of bytes of the stream.

type UndecidedEndiannessError

type UndecidedEndiannessError struct{}

UndecidedEndiannessError occurs when a value has calculated or inherited endianness, and the endianness could not be determined.

func (UndecidedEndiannessError) Error

type ValidationExprError

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

ValidationExprError signals validation failure: we required "Actual" value to match the expression, but it turned out that it doesn't.

func NewValidationExprError

func NewValidationExprError(actual interface{}, io *Stream, srcPath string) ValidationExprError

NewValidationExprError creates a new ValidationExprError instance.

func (ValidationExprError) Actual

func (e ValidationExprError) Actual() interface{}

Actual is a getter of the actual value associated with the validation error.

func (ValidationExprError) Error

func (e ValidationExprError) Error() string

func (ValidationExprError) Io

func (l ValidationExprError) Io() *Stream

func (ValidationExprError) SrcPath

func (l ValidationExprError) SrcPath() string

type ValidationFailedError

type ValidationFailedError interface {
	Actual() interface{}
	Io() *Stream
	SrcPath() string
}

ValidationFailedError is an interface that all "Validation*Error"s implement.

type ValidationGreaterThanError

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

ValidationGreaterThanError signals validation failure: we required "Actual" value to be less than or equal to "Max", but it turned out that it's not.

func NewValidationGreaterThanError

func NewValidationGreaterThanError(max interface{}, actual interface{}, io *Stream, srcPath string) ValidationGreaterThanError

NewValidationGreaterThanError creates a new ValidationGreaterThanError instance.

func (ValidationGreaterThanError) Actual

func (e ValidationGreaterThanError) Actual() interface{}

Actual is a getter of the actual value associated with the validation error.

func (ValidationGreaterThanError) Error

func (ValidationGreaterThanError) Io

func (l ValidationGreaterThanError) Io() *Stream

func (ValidationGreaterThanError) Max

func (e ValidationGreaterThanError) Max() interface{}

Max is a getter of the maximum value associated with the validation error.

func (ValidationGreaterThanError) SrcPath

func (l ValidationGreaterThanError) SrcPath() string

type ValidationLessThanError

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

ValidationLessThanError signals validation failure: we required "Actual" value to be greater than or equal to "Min", but it turned out that it's not.

func NewValidationLessThanError

func NewValidationLessThanError(min interface{}, actual interface{}, io *Stream, srcPath string) ValidationLessThanError

NewValidationLessThanError creates a new ValidationLessThanError instance.

func (ValidationLessThanError) Actual

func (e ValidationLessThanError) Actual() interface{}

Actual is a getter of the actual value associated with the validation error.

func (ValidationLessThanError) Error

func (e ValidationLessThanError) Error() string

func (ValidationLessThanError) Io

func (l ValidationLessThanError) Io() *Stream

func (ValidationLessThanError) Min

func (e ValidationLessThanError) Min() interface{}

Min is a getter of the minimum value associated with the validation error.

func (ValidationLessThanError) SrcPath

func (l ValidationLessThanError) SrcPath() string

type ValidationNotAnyOfError

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

ValidationNotAnyOfError signals validation failure: we required "Actual" value to be from the list, but it turned out that it's not.

func NewValidationNotAnyOfError

func NewValidationNotAnyOfError(actual interface{}, io *Stream, srcPath string) ValidationNotAnyOfError

NewValidationNotAnyOfError creates a new ValidationNotAnyOfError instance.

func (ValidationNotAnyOfError) Actual

func (e ValidationNotAnyOfError) Actual() interface{}

Actual is a getter of the actual value associated with the validation error.

func (ValidationNotAnyOfError) Error

func (e ValidationNotAnyOfError) Error() string

func (ValidationNotAnyOfError) Io

func (l ValidationNotAnyOfError) Io() *Stream

func (ValidationNotAnyOfError) SrcPath

func (l ValidationNotAnyOfError) SrcPath() string

type ValidationNotEqualError

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

ValidationNotEqualError signals validation failure: we required "Actual" value to be equal to "Expected", but it turned out that it's not.

func NewValidationNotEqualError

func NewValidationNotEqualError(expected interface{}, actual interface{}, io *Stream, srcPath string) ValidationNotEqualError

NewValidationNotEqualError creates a new ValidationNotEqualError instance.

func (ValidationNotEqualError) Actual

func (e ValidationNotEqualError) Actual() interface{}

Actual is a getter of the actual value associated with the validation error.

func (ValidationNotEqualError) Error

func (e ValidationNotEqualError) Error() string

func (ValidationNotEqualError) Expected

func (e ValidationNotEqualError) Expected() interface{}

Expected is a getter of the expected value associated with the validation error.

func (ValidationNotEqualError) Io

func (l ValidationNotEqualError) Io() *Stream

func (ValidationNotEqualError) SrcPath

func (l ValidationNotEqualError) SrcPath() string

type Writer

type Writer struct {
	io.Writer
	// contains filtered or unexported fields
}

A Writer encapsulates writing binary data to files and memory.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter creates and initializes a new Writer using w.

func (*Writer) WriteBytes

func (k *Writer) WriteBytes(b []byte) error

WriteBytes writes the byte slice b to the underlying writer.

func (*Writer) WriteF4be

func (k *Writer) WriteF4be(v float32) error

WriteF4be writes a float32 in big-endian order to the underlying writer.

func (*Writer) WriteF4le

func (k *Writer) WriteF4le(v float32) error

WriteF4le writes a float32 in little-endian order to the underlying writer.

func (*Writer) WriteF8be

func (k *Writer) WriteF8be(v float64) error

WriteF8be writes a float64 in big-endian order to the underlying writer.

func (*Writer) WriteF8le

func (k *Writer) WriteF8le(v float64) error

WriteF8le writes a float64 in little-endian order to the underlying writer.

func (*Writer) WriteS1

func (k *Writer) WriteS1(v int8) error

WriteS1 writes an int8 to the underlying writer.

func (*Writer) WriteS2be

func (k *Writer) WriteS2be(v int16) error

WriteS2be writes an int16 in big-endian order to the underlying writer.

func (*Writer) WriteS2le

func (k *Writer) WriteS2le(v int16) error

WriteS2le writes an int16 in little-endian order to the underlying writer.

func (*Writer) WriteS4be

func (k *Writer) WriteS4be(v int32) error

WriteS4be writes an in32 in big-endian order to the underlying writer.

func (*Writer) WriteS4le

func (k *Writer) WriteS4le(v int32) error

WriteS4le writes an int32 in little-endian order to the underlying writer.

func (*Writer) WriteS8be

func (k *Writer) WriteS8be(v int64) error

WriteS8be writes an int64 in big-endian order to the underlying writer.

func (*Writer) WriteS8le

func (k *Writer) WriteS8le(v int64) error

WriteS8le writes an int64 in little-endian order to the underlying writer.

func (*Writer) WriteU1

func (k *Writer) WriteU1(v uint8) error

WriteU1 writes a uint8 to the underlying writer.

func (*Writer) WriteU2be

func (k *Writer) WriteU2be(v uint16) error

WriteU2be writes a uint16 in big-endian order to the underlying writer.

func (*Writer) WriteU2le

func (k *Writer) WriteU2le(v uint16) error

WriteU2le writes a uint16 in little-endian order to the underlying writer.

func (*Writer) WriteU4be

func (k *Writer) WriteU4be(v uint32) error

WriteU4be writes a uint32 in big-endian order to the underlying writer.

func (*Writer) WriteU4le

func (k *Writer) WriteU4le(v uint32) error

WriteU4le writes a uint32 in little-endian order to the underlying writer.

func (*Writer) WriteU8be

func (k *Writer) WriteU8be(v uint64) error

WriteU8be writes a uint64 in big-endian order to the underlying writer.

func (*Writer) WriteU8le

func (k *Writer) WriteU8le(v uint64) error

WriteU8le writes a uint64 in little-endian order to the underlying writer.

Jump to

Keyboard shortcuts

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