siabin

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: MIT Imports: 8 Imported by: 8 modules, 23 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package siabin converts arbitrary objects into byte slices, and visa versa. It also contains helper functions for reading and writing length- prefixed data. See doc/encoding/SiaEncoding.md for the full encoding specification.

Index

Constants

View Source
const (
	// MaxObjectSize refers to the maximum size an object could have.
	// Limited to 12 MB.
	MaxObjectSize = 12e6

	// MaxSliceSize refers to the maximum size slice could have. Limited
	// to 5 MB.
	MaxSliceSize = 5e6 // 5 MB
)

Variables

View Source
var (

	// ErrObjectTooLarge is an error when encoded object exceeds size limit.
	ErrObjectTooLarge = errors.New("encoded object exceeds size limit")
	// ErrSliceTooLarge is an error when encoded slice is too large.
	ErrSliceTooLarge = errors.New("encoded slice is too large")
)

Functions

func DecInt64

func DecInt64(b []byte) int64

DecInt64 decodes a slice of 8 bytes into an int64. If len(b) < 8, the slice is padded with zeros.

func DecUint64

func DecUint64(b []byte) uint64

DecUint64 decodes a slice of 8 bytes into a uint64. If len(b) < 8, the slice is padded with zeros.

func EncInt64

func EncInt64(i int64) (b []byte)

EncInt64 encodes an int64 as a slice of 8 bytes.

func EncUint64

func EncUint64(i uint64) (b []byte)

EncUint64 encodes a uint64 as a slice of 8 bytes.

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal returns the encoding of v. For encoding details, see the package docstring.

func MarshalAll

func MarshalAll(vs ...interface{}) ([]byte, error)

MarshalAll encodes all of its inputs and returns their concatenation.

func ReadFile

func ReadFile(filename string, v interface{}) error

ReadFile reads the contents of a file and decodes them into v.

func ReadObject

func ReadObject(r io.Reader, obj interface{}, maxLen uint64) error

ReadObject reads and decodes a length-prefixed and marshalled object.

func ReadPrefix

func ReadPrefix(r io.Reader, maxLen uint64) ([]byte, error)

ReadPrefix reads an 8-byte length prefixes, followed by the number of bytes specified in the prefix. The operation is aborted if the prefix exceeds a specified maximum length.

func Unmarshal

func Unmarshal(b []byte, v interface{}) error

Unmarshal decodes the encoded value b and stores it in v, which must be a pointer. The decoding rules are the inverse of those specified in the package docstring for marshaling.

func UnmarshalAll

func UnmarshalAll(b []byte, vs ...interface{}) error

UnmarshalAll decodes the encoded values in b and stores them in vs, which must be pointers.

func WriteFile

func WriteFile(filename string, v interface{}) error

WriteFile writes v to a file. The file will be created if it does not exist.

func WriteInt

func WriteInt(w io.Writer, i int) error

WriteInt writes i to w.

func WriteObject

func WriteObject(w io.Writer, v interface{}) error

WriteObject writes a length-prefixed object to w.

func WritePrefix

func WritePrefix(w io.Writer, data []byte) error

WritePrefix writes a length-prefixed byte slice to w.

func WriteUint64

func WriteUint64(w io.Writer, u uint64) error

WriteUint64 writes u to w.

Types

type Decoder

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

A Decoder reads and decodes values from an input stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new decoder that reads from r.

func (*Decoder) Decode

func (d *Decoder) Decode(v interface{}) (err error)

Decode reads the next encoded value from its input stream and stores it in v, which must be a pointer. The decoding rules are the inverse of those specified in the package docstring.

func (*Decoder) DecodeAll

func (d *Decoder) DecodeAll(vs ...interface{}) error

DecodeAll decodes a variable number of arguments.

func (*Decoder) Read

func (d *Decoder) Read(p []byte) (int, error)

Read implements the io.Reader interface. It also keeps track of the total number of bytes decoded, and panics if that number exceeds a global maximum.

type Encoder

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

An Encoder writes objects to an output stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

func (*Encoder) Encode

func (e *Encoder) Encode(v interface{}) error

Encode writes the encoding of v to the stream. For encoding details, see the package docstring.

func (*Encoder) EncodeAll

func (e *Encoder) EncodeAll(vs ...interface{}) error

EncodeAll encodes a variable number of arguments.

type SiaMarshaler

type SiaMarshaler interface {
	MarshalSia(io.Writer) error
}

A SiaMarshaler can encode and write itself to a stream.

type SiaUnmarshaler

type SiaUnmarshaler interface {
	UnmarshalSia(io.Reader) error
}

A SiaUnmarshaler can read and decode itself from a stream.

Jump to

Keyboard shortcuts

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