Documentation ¶
Overview ¶
Package encoding converts arbitrary objects into byte slices, and vis versa. It also contains helper functions for reading and writing length- prefixed data. See doc/Encoding.md for the full encoding specification.
Index ¶
- Constants
- Variables
- func DecInt64(b []byte) int64
- func DecUint64(b []byte) uint64
- func EncInt64(i int64) (b []byte)
- func EncUint64(i uint64) (b []byte)
- func Marshal(v interface{}) []byte
- func MarshalAll(vs ...interface{}) []byte
- func ReadFile(filename string, v interface{}) error
- func ReadObject(r io.Reader, obj interface{}, maxLen uint64) error
- func ReadPrefix(r io.Reader, maxLen uint64) ([]byte, error)
- func Unmarshal(b []byte, v interface{}) error
- func UnmarshalAll(b []byte, vs ...interface{}) error
- func WriteFile(filename string, v interface{}) error
- func WriteInt(w io.Writer, i int) error
- func WriteObject(w io.Writer, v interface{}) error
- func WritePrefix(w io.Writer, data []byte) error
- func WriteUint64(w io.Writer, u uint64) error
- type Decoder
- type Encoder
- type SiaMarshaler
- type SiaUnmarshaler
Constants ¶
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 ¶
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 ¶
DecInt64 decodes a slice of 8 bytes into an int64. If len(b) < 8, the slice is padded with zeros.
func DecUint64 ¶
DecUint64 decodes a slice of 8 bytes into a uint64. If len(b) < 8, the slice is padded with zeros.
func Marshal ¶
func Marshal(v interface{}) []byte
Marshal returns the encoding of v. For encoding details, see the package docstring.
func MarshalAll ¶
func MarshalAll(vs ...interface{}) []byte
MarshalAll encodes all of its inputs and returns their concatenation.
func ReadObject ¶
ReadObject reads and decodes a length-prefixed and marshalled object.
func ReadPrefix ¶
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 ¶
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 ¶
UnmarshalAll decodes the encoded values in b and stores them in vs, which must be pointers.
func WriteObject ¶
WriteObject writes a length-prefixed object to w.
func WritePrefix ¶
WritePrefix writes a length-prefixed byte slice 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 ¶
NewDecoder returns a new decoder that reads from r.
func (*Decoder) Decode ¶
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.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
An Encoder writes objects to an output stream.
func NewEncoder ¶
NewEncoder returns a new encoder that writes to w.
type SiaMarshaler ¶
A SiaMarshaler can encode and write itself to a stream.
type SiaUnmarshaler ¶
A SiaUnmarshaler can read and decode itself from a stream.