Documentation ¶
Overview ¶
Package rivbin converts arbitrary objects into byte slices, and vis versa. It also contains helper functions for reading and writing specific/specialised objects.
Index ¶
- Constants
- Variables
- func Marshal(v interface{}) ([]byte, error)
- func MarshalAll(vs ...interface{}) ([]byte, error)
- func MarshalBool(w io.Writer, b bool) error
- func MarshalTinySlice(w io.Writer, v interface{}) error
- func MarshalUint16(w io.Writer, x uint16) error
- func MarshalUint24(w io.Writer, x uint32) error
- func MarshalUint32(w io.Writer, x uint32) error
- func MarshalUint64(w io.Writer, x uint64) error
- func MarshalUint8(w io.Writer, x uint8) error
- func ReadDataSlice(r io.Reader, maxLen int) ([]byte, error)
- func ReadObject(r io.Reader, obj interface{}, maxLen int) error
- func Unmarshal(b []byte, v interface{}) error
- func UnmarshalAll(b []byte, vs ...interface{}) error
- func UnmarshalBool(r io.Reader) (bool, error)
- func UnmarshalTinySlice(r io.Reader, v interface{}) error
- func UnmarshalUint16(r io.Reader) (uint16, error)
- func UnmarshalUint24(r io.Reader) (uint32, error)
- func UnmarshalUint32(r io.Reader) (uint32, error)
- func UnmarshalUint64(r io.Reader) (uint64, error)
- func UnmarshalUint8(r io.Reader) (uint8, error)
- func WriteDataSlice(w io.Writer, data []byte) error
- func WriteObject(w io.Writer, v interface{}) error
- type Decoder
- type Encoder
- type RivineMarshaler
- type RivineUnmarshaler
Constants ¶
const ( // MaxSliceSize refers to the maximum size slice could have. Limited // to 5 MB. MaxSliceSize = 5e6 // 5 MB )
Variables ¶
var ( // ErrSliceTooLarge is an error when encoded slice is too large. ErrSliceTooLarge = errors.New("encoded slice is too large") )
Functions ¶
func MarshalAll ¶
MarshalAll encodes all of its inputs and returns their concatenation.
func MarshalBool ¶
MarshalBool writes a bool value as a single byte value.
func MarshalTinySlice ¶
MarshalTinySlice allows the marshaling of tiny slices, meaning slices with a length of maximum 255 (elements). All elements are encoded in the order given, using the encoder of this package.
Note that this specialised marshal function should only be used when also in complete control of the unmarshal process, otherwise it is better to use the regular dynamlic slice encoding, using the normal encoding process of this package.
Supported types: `[]byte`, `[]x` (where x can be of any type), `string`
func MarshalUint16 ¶
MarshalUint16 marshals an uint16 value as a 2-byte little-endian value.
func MarshalUint24 ¶
MarshalUint24 marshals an uint24 value as a 3-byte little-endian value.
func MarshalUint32 ¶
MarshalUint32 marshals an uint32 value as a 4-byte little-endian value.
func MarshalUint64 ¶
MarshalUint64 marshals an uint64 value as an 8-byte little-endian value.
func MarshalUint8 ¶
MarshalUint8 writes an uint8 value as a single byte value.
func ReadDataSlice ¶
ReadDataSlice reads a byte slice length of maximum 4 bytes followed by the number of bytes specified in the (length) prefix. The operation is aborted if the prefix exceeds a specified maximum length.
func ReadObject ¶
ReadObject reads and decodes a length-prefixed and marshalled object.
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 UnmarshalBool ¶
UnmarshalBool reads a bool value as a single byte value.
func UnmarshalTinySlice ¶
UnmarshalTinySlice allows the unmarshaling of tiny slices, meaning slices with a length of maximum 255 (elements). All elements are decoded in the order given, using the decoder of this package. Note that this can only decode values that were encoded using an equivalent algorithm as implemented in `MarshalTinySlice`.
Supported types: `*[]byte`, `*[]x` (where x can be of any type), `*string`
func UnmarshalUint16 ¶
UnmarshalUint16 unmarshals a 2-byte little-endian value as an uint16 value.
func UnmarshalUint24 ¶
UnmarshalUint24 unmarshals a 3-byte little-endian value as an uint32 value.
func UnmarshalUint32 ¶
UnmarshalUint32 unmarshals a 4-byte little-endian value as an uint32 value.
func UnmarshalUint64 ¶
UnmarshalUint64 unmarshals an 8-byte little-endian value as an uint64 value.
func UnmarshalUint8 ¶
UnmarshalUint8 reads a single byte and casts its to an uint8 value.
func WriteDataSlice ¶
WriteDataSlice writes a length-prefixed byte slice to w.
func WriteObject ¶
WriteObject writes a length-prefixed object 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.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder writes objects to an output stream.
A modified and improved Binary Encoder based upon the siabin Encoder, found in the <github.com/threefoldtech/rivine/pkg/encoding/siabin> package.
func NewEncoder ¶
NewEncoder returns a new encoder that writes to w.
type RivineMarshaler ¶
A RivineMarshaler can encode and write itself to a stream.
type RivineUnmarshaler ¶
A RivineUnmarshaler can read and decode itself from a stream.