format

package
v0.3.26 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package format provides readers and writers for various binary formats used by Spy Cards Online.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrReachedEnd  = errors.New("format: reached end of buffer while reading")
	ErrExpectedEOF = errors.New("format: expected end of buffer, but additional data is present")
)

Errors that can be returned by format.Reader and format.Writer.

View Source
var (
	ErrShortFileID = errors.New("format: too short to be a file ID")
	ErrFileID      = errors.New("format: invalid file ID")
)

Errors that can be returned by FileID unmarshaling.

View Source
var Crockford32 = base32.NewEncoding("0123456789ABCDEFGHJKMNPQRSTVWXYZ").WithPadding(base32.NoPadding)

Crockford32 is an implementation of Crockford Base 32. See https://www.crockford.com/base32.html

Functions

func Catch

func Catch(err *error)

Catch is a deferred function that recovers an error passed to Throw in *err.

func Decode32

func Decode32(src string) ([]byte, error)

Decode32 decodes a Crockford Base 32 string, applying the recommended transformations to fix typos.

func Encode32

func Encode32(src []byte) string

Encode32 encodes a slice of bytes as a Crockford Base 32 string.

func Encode32Space

func Encode32Space(src []byte) string

Encode32Space encodes a slice of bytes as a Crockford Base 32 string with a space after every 4 characters.

func Throw

func Throw(err error)

Throw panics with the given error, which can then be recovered using Catch.

Types

type ErrVersion added in v0.3.7

type ErrVersion uint64

func (ErrVersion) Error added in v0.3.7

func (err ErrVersion) Error() string

type FileID

type FileID struct {
	Hash [8]byte
	ID   uint64
}

FileID is the decoded form of a file identifier for Spy Cards Online.FileID

It contains the first 8 bytes of the SHA-256 hash of the file, along with an opaque integer identifier.

func (FileID) IsMatch

func (f FileID) IsMatch(data []byte) bool

IsMatch verifies that the file ID matches the hash of the data.

func (FileID) MarshalBinary

func (f FileID) MarshalBinary() ([]byte, error)

MarshalBinary implements encoding.BinaryMarshaler.

func (FileID) MarshalText

func (f FileID) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler.

func (FileID) String

func (f FileID) String() string

String implements fmt.Stringer.

func (*FileID) UnmarshalBinary

func (f *FileID) UnmarshalBinary(b []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*FileID) UnmarshalText

func (f *FileID) UnmarshalText(b []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Reader

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

Reader decodes data from a binary format.

There should be a deferred call to Catch when Reader is in use.

func (*Reader) Byte

func (r *Reader) Byte() byte

Byte consumes the first byte remaining in the buffer.

func (*Reader) Bytes

func (r *Reader) Bytes(count int) []byte

Bytes returns the next count bytes from the Reader.

func (*Reader) Init

func (r *Reader) Init(b []byte)

Init sets the Reader's buffer to b.

func (*Reader) Len

func (r *Reader) Len() int

Len returns the remaining number of bytes in the buffer.

func (*Reader) Length added in v0.3.16

func (r *Reader) Length(minSize, divisor uint64) int

Length calls UVarInt and verifies that at least length*minSize bytes remain in the stream, and that the length fits within an int.

func (*Reader) Peek

func (r *Reader) Peek(n int) []byte

Peek returns the next n bytes in the buffer without consuming them.

Peek panics if n is greater than Len.

func (*Reader) Read

func (r *Reader) Read(v interface{})

Read decodes a fixed-size data structure from the Reader.

func (*Reader) SVarInt

func (r *Reader) SVarInt() int64

SVarInt decodes a signed varint from the Reader.

func (*Reader) String

func (r *Reader) String() string

String decodes a length-prefixed string from the Reader.

func (*Reader) String1

func (r *Reader) String1() string

String1 decodes a length-prefixed string from the Reader.

The maximum length of a string in this legacy format is 255 characters.

func (*Reader) SubReader

func (r *Reader) SubReader() *Reader

SubReader returns a Reader for a length-prefixed section of r.

func (*Reader) UVarInt

func (r *Reader) UVarInt() uint64

UVarInt decodes an unsigned varint from the Reader.

type Writer

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

Writer encodes data into a binary format.

There should be a deferred call to Catch when Writer is in use.

func (*Writer) Bytes

func (w *Writer) Bytes(b []byte)

Bytes appends raw bytes to the Writer.

func (*Writer) Data

func (w *Writer) Data() []byte

Data returns the buffer held by the Writer.

The buffer is not copied, so modifications to the buffer may result in modifications to the writer.

func (*Writer) SVarInt

func (w *Writer) SVarInt(n int64)

SVarInt appends a signed varint to the Writer.

func (*Writer) String

func (w *Writer) String(s string)

String appends a length-prefixed string to the Writer.

func (*Writer) String1

func (w *Writer) String1(s string)

String1 appends a length-prefixed string to the Writer.

The maximum length of a string in this legacy format is 255 characters.

func (*Writer) SubWriter

func (w *Writer) SubWriter() (sub *Writer, done func())

SubWriter returns a Writer that can be used to append a length-prefixed section of data.

done must be called before any methods are called on w.

func (*Writer) UVarInt

func (w *Writer) UVarInt(n uint64)

UVarInt appends an unsigned varint to the Writer.

func (*Writer) Write

func (w *Writer) Write(v interface{})

Write appends a fixed-size data structure to the Writer.

Jump to

Keyboard shortcuts

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