tape

package
v0.0.0-...-874ae2e Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2025 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const MaxInt int = int(^uint(0) >> 1)

MaxInt is the maximum value an int can hold. This varies depending on the system.

Variables

View Source
var MaxStructureLength = 1024 * 1024

MaxStructureLength determines how long a TAPE data structure can be. This applies to:

  • OTA
  • SBA/LBA
  • KTV

By default it is set at 2^20 (about a million). You shouldn't need to change this. If you do, it should only be set once at the start of the program.

Functions

func DecodeAny

func DecodeAny(decoder *Decoder, tag Tag) (value any, n int, err error)

DecodeAny is like DecodeAnyInto, but it automatically creates the destination from the tag and data. The head of the decoder must be at the start of the payload.

func DecodeAnyInto

func DecodeAnyInto(decoder *Decoder, destination any, tag Tag) (n int, err error)

DecodeAnyInto decodes data and places it into destination, which must be a pointer to a supported type. See EncodeAny for a list of supported types. The head of the decoder must be at the start of the payload.

func EncodeAny

func EncodeAny(encoder *Encoder, value any, tag Tag) (n int, err error)

EncodeAny encodes an "any" value. Returns an error if the underlying type is unsupported. Supported types are:

  • int
  • int<N>
  • uint
  • uint<N>
  • string
  • []<supported type>
  • map[uint16]<supported type>

func IntBytes

func IntBytes(value uint64) int

IntBytes returns the number of bytes required to hold a given unsigned integer.

func Skim

func Skim(decoder *Decoder, tag Tag) (n int, err error)

Skim uses up data from a decoder to "skim" over one value (and all else contained within it) without actually putting the data anywhere.

func Uint64ToIntSafe

func Uint64ToIntSafe(input uint64) (int, error)

Uint64ToIntSafe casts the input to an int if it can be done without overflow, or returns an error otherwise.

Types

type Decodable

type Decodable interface {
	// Decode reads data from decoder, replacing the data of the object. It
	// returns the amount of bytes written, and an error if the write
	// stopped early.
	Decode(decoder *Decoder) (n int, err error)
}

Decodable is any type that can decode itself from a decoder.

type Decoder

type Decoder struct {
	bufio.Reader
}

Decoder decodes data from an io.Reader.

func NewDecoder

func NewDecoder(reader io.Reader) *Decoder

NewDecoder creates a new decoder that reads from reader.

func (*Decoder) ReadFloat16

func (this *Decoder) ReadFloat16() (value float32, n int, err error)

ReadFloat16 decodes a 16-bit floating point value from the input reader.

func (*Decoder) ReadFloat32

func (this *Decoder) ReadFloat32() (value float32, n int, err error)

ReadFloat32 decldes a 32-bit floating point value from the input reader.

func (*Decoder) ReadFloat64

func (this *Decoder) ReadFloat64() (value float64, n int, err error)

ReadFloat64 decldes a 64-bit floating point value from the input reader.

func (*Decoder) ReadFull

func (this *Decoder) ReadFull(buffer []byte) (n int, err error)

ReadFull calls io.ReadFull on the reader.

func (*Decoder) ReadInt8

func (this *Decoder) ReadInt8() (value int8, n int, err error)

ReadInt8 decodes an 8-bit signed integer from the input reader.

func (*Decoder) ReadInt16

func (this *Decoder) ReadInt16() (value int16, n int, err error)

ReadInt16 decodes an 16-bit signed integer from the input reader.

func (*Decoder) ReadInt32

func (this *Decoder) ReadInt32() (value int32, n int, err error)

ReadInt32 decodes an 32-bit signed integer from the input reader.

func (*Decoder) ReadInt64

func (this *Decoder) ReadInt64() (value int64, n int, err error)

ReadInt64 decodes an 64-bit signed integer from the input reader.

func (*Decoder) ReadIntN

func (this *Decoder) ReadIntN(bytes int) (value int64, n int, err error)

ReadIntN decodes an N-byte signed integer from the input reader.

func (*Decoder) ReadTag

func (this *Decoder) ReadTag() (value Tag, n int, err error)

ReadTag decodes a Tag from the input reader.

func (*Decoder) ReadUint8

func (this *Decoder) ReadUint8() (value uint8, n int, err error)

ReadUint8 decodes an 8-bit unsigned integer from the input reader.

func (*Decoder) ReadUint16

func (this *Decoder) ReadUint16() (value uint16, n int, err error)

ReadUint16 decodes an 16-bit unsigned integer from the input reader.

func (*Decoder) ReadUint32

func (this *Decoder) ReadUint32() (value uint32, n int, err error)

ReadUint32 decodes an 32-bit unsigned integer from the input reader.

func (*Decoder) ReadUint64

func (this *Decoder) ReadUint64() (value uint64, n int, err error)

ReadUint64 decodes an 64-bit unsigned integer from the input reader.

func (*Decoder) ReadUintN

func (this *Decoder) ReadUintN(bytes int) (value uint64, n int, err error)

ReadUintN decodes an N-byte unsigned integer from the input reader.

type Encodable

type Encodable interface {
	// Encode sends data to encoder. It returns the amount of bytes written,
	// and an error if the write stopped early.
	Encode(encoder *Encoder) (n int, err error)
}

Encodable is any type that can write itself to an encoder.

type Encoder

type Encoder struct {
	bufio.Writer
}

Encoder encodes data to an io.Writer.

func NewEncoder

func NewEncoder(writer io.Writer) *Encoder

NewEncoder creates a new encoder that writes to writer.

func (*Encoder) WriteFloat16

func (this *Encoder) WriteFloat16(value float32) (n int, err error)

WriteFloat16 encodes a 16-bit floating point value to the output writer.

func (*Encoder) WriteFloat32

func (this *Encoder) WriteFloat32(value float32) (n int, err error)

WriteFloat32 encodes a 32-bit floating point value to the output writer.

func (*Encoder) WriteFloat64

func (this *Encoder) WriteFloat64(value float64) (n int, err error)

WriteFloat64 encodes a 64-bit floating point value to the output writer.

func (*Encoder) WriteInt8

func (this *Encoder) WriteInt8(value int8) (n int, err error)

WriteInt8 encodes an 8-bit signed integer to the output writer.

func (*Encoder) WriteInt16

func (this *Encoder) WriteInt16(value int16) (n int, err error)

WriteInt16 encodes an 16-bit signed integer to the output writer.

func (*Encoder) WriteInt32

func (this *Encoder) WriteInt32(value int32) (n int, err error)

WriteInt32 encodes an 32-bit signed integer to the output writer.

func (*Encoder) WriteInt64

func (this *Encoder) WriteInt64(value int64) (n int, err error)

WriteInt64 encodes an 64-bit signed integer to the output writer.

func (*Encoder) WriteIntN

func (this *Encoder) WriteIntN(value int64, bytes int) (n int, err error)

WriteIntN encodes an N-byte signed integer to the output writer.

func (*Encoder) WriteTag

func (this *Encoder) WriteTag(value Tag) (n int, err error)

WriteTag encodes a Tag to the output writer.

func (*Encoder) WriteUint8

func (this *Encoder) WriteUint8(value uint8) (n int, err error)

WriteUint8 encodes an 8-bit unsigned integer to the output writer.

func (*Encoder) WriteUint16

func (this *Encoder) WriteUint16(value uint16) (n int, err error)

WriteUint16 encodes an 16-bit unsigned integer to the output writer.

func (*Encoder) WriteUint32

func (this *Encoder) WriteUint32(value uint32) (n int, err error)

WriteUint32 encodes an 32-bit unsigned integer to the output writer.

func (*Encoder) WriteUint64

func (this *Encoder) WriteUint64(value uint64) (n int, err error)

WriteUint64 encodes an 64-bit unsigned integer to the output writer.

func (*Encoder) WriteUintN

func (this *Encoder) WriteUintN(value uint64, bytes int) (n int, err error)

WriteUintN encodes an N-byte unsigned integer to the output writer.

type Error

type Error string

Error enumerates common errors in this package.

const (
	ErrTooLong  Error = "data structure too long"
	ErrTooLarge Error = "number too large"
)

func (Error) Error

func (err Error) Error() string

Error implements the error interface.

type Tag

type Tag byte
const (
	SI      Tag = 0 << 5 // Small integer
	LI      Tag = 1 << 5 // Large unsigned integer
	LSI     Tag = 2 << 5 // Large signed integer
	FP      Tag = 3 << 5 // Floating point
	SBA     Tag = 4 << 5 // Small byte array
	LBA     Tag = 5 << 5 // Large byte array
	OTA     Tag = 6 << 5 // One-tag array
	KTV     Tag = 7 << 5 // Key-tag-value table
	TNMask  Tag = 0xE0   // The entire TN bitfield
	CNMask  Tag = 0x1F   // The entire CN bitfield
	CNLimit Tag = 32     // All valid CNs are < CNLimit
)

func BufferTag

func BufferTag(value []byte) Tag

BufferTag returns the appropriate tag for a buffer.

func StringTag

func StringTag(value string) Tag

StringTag returns the appropriate tag for a string.

func TagAny

func TagAny(value any) (Tag, error)

TagAny returns the correct tag for an "any" value. Returns an error if the underlying type is unsupported. See EncodeAny for a list of supported types.

func (Tag) CN

func (tag Tag) CN() int

func (Tag) Is

func (tag Tag) Is(other Tag) bool

func (Tag) String

func (tag Tag) String() string

func (Tag) TN

func (tag Tag) TN() int

func (Tag) WithCN

func (tag Tag) WithCN(cn int) Tag

func (Tag) WithoutCN

func (tag Tag) WithoutCN() Tag

Jump to

Keyboard shortcuts

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