go-bare: git.sr.ht/~sircmpwn/go-bare Index | Files | Directories

package bare

import "git.sr.ht/~sircmpwn/go-bare"

An implementation of the BARE message format for Go.

https://git.sr.ht/~sircmpwn/bare

See the git repository for usage examples:

https://git.sr.ht/~sircmpwn/go-bare

Index

Package Files

errors.go limit.go marshal.go package.go reader.go unions.go unmarshal.go writer.go

Variables

var ErrInvalidStr = errors.New("String contains invalid UTF-8 sequences")
var ErrLimitExceeded = errors.New("Maximum message size exceeded")

Use MaxUnmarshalBytes to prevent this error from occuring on messages which are large by design.

func Marshal Uses

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

Marshals a value (val, which must be a pointer) into a BARE message.

Go "int" and "uint" types are represented as BARE u32 and i32 types respectively, for message compatibility with both 32-bit and 64-bit systems.

The encoding of each struct field can be customized by the format string stored under the "bare" key in the struct field's tag.

As a special case, if the field tag is "-", the field is always omitted.

func MarshalWriter Uses

func MarshalWriter(w *Writer, val interface{}) error

Marshals a value (val, which must be a pointer) into a BARE message and writes it to a Writer. See Marshal for details.

func MaxArrayLength Uses

func MaxArrayLength(length uint64)

MaxArrayLength sets maximum number of elements in array. Defaults to 4096 elements

func MaxMapSize Uses

func MaxMapSize(size uint64)

MaxMapSize sets maximum size of map. Defaults to 1024 key/value pairs

func MaxUnmarshalBytes Uses

func MaxUnmarshalBytes(bytes uint64)

MaxUnmarshalBytes sets the maximum size of a message decoded by unmarshal. By default, this is set to 32 MiB.

func Unmarshal Uses

func Unmarshal(data []byte, val interface{}) error

Unmarshals a BARE message into val, which must be a pointer to a value of the message type.

Go "int" and "uint" types are represented as BARE u32 and i32 types respectively, for message compatibility with both 32-bit and 64-bit systems.

func UnmarshalReader Uses

func UnmarshalReader(r io.Reader, val interface{}) error

Unmarshals a BARE message into value (val, which must be a pointer), from a reader. See Unmarshal for details.

type Marshalable Uses

type Marshalable interface {
    Marshal(w *Writer) error
}

A type which implements this interface will be responsible for marshaling itself when encountered.

type Reader Uses

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

A Reader for BARE primitive types.

func NewReader Uses

func NewReader(base io.Reader) *Reader

Returns a new BARE primitive reader wrapping the given io.Reader.

func (*Reader) ReadBool Uses

func (r *Reader) ReadBool() (bool, error)

func (*Reader) ReadData Uses

func (r *Reader) ReadData() ([]byte, error)

Reads arbitrary data whose length is read from the message.

func (*Reader) ReadDataFixed Uses

func (r *Reader) ReadDataFixed(dest []byte) error

Reads a fixed amount of arbitrary data, defined by the length of the slice.

func (*Reader) ReadF32 Uses

func (r *Reader) ReadF32() (float32, error)

func (*Reader) ReadF64 Uses

func (r *Reader) ReadF64() (float64, error)

func (*Reader) ReadI16 Uses

func (r *Reader) ReadI16() (int16, error)

func (*Reader) ReadI32 Uses

func (r *Reader) ReadI32() (int32, error)

func (*Reader) ReadI64 Uses

func (r *Reader) ReadI64() (int64, error)

func (*Reader) ReadI8 Uses

func (r *Reader) ReadI8() (int8, error)

func (*Reader) ReadInt Uses

func (r *Reader) ReadInt() (int64, error)

func (*Reader) ReadString Uses

func (r *Reader) ReadString() (string, error)

func (*Reader) ReadU16 Uses

func (r *Reader) ReadU16() (uint16, error)

func (*Reader) ReadU32 Uses

func (r *Reader) ReadU32() (uint32, error)

func (*Reader) ReadU64 Uses

func (r *Reader) ReadU64() (uint64, error)

func (*Reader) ReadU8 Uses

func (r *Reader) ReadU8() (uint8, error)

func (*Reader) ReadUint Uses

func (r *Reader) ReadUint() (uint64, error)

type Union Uses

type Union interface {
    IsUnion()
}

Any type which is a union member must implement this interface. You must also call RegisterUnion for go-bare to marshal or unmarshal messages which utilize your union type.

type UnionTags Uses

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

func RegisterUnion Uses

func RegisterUnion(iface interface{}) *UnionTags

Registers a union type in this context. Pass the union interface and the list of types associated with it, sorted ascending by their union tag.

func (*UnionTags) Member Uses

func (ut *UnionTags) Member(t interface{}, tag uint64) *UnionTags

func (*UnionTags) TagFor Uses

func (ut *UnionTags) TagFor(v interface{}) (uint64, bool)

func (*UnionTags) TypeFor Uses

func (ut *UnionTags) TypeFor(tag uint64) (reflect.Type, bool)

type Unmarshalable Uses

type Unmarshalable interface {
    Unmarshal(r *Reader) error
}

A type which implements this interface will be responsible for unmarshaling itself when encountered.

type UnsupportedTypeError Uses

type UnsupportedTypeError struct {
    Type reflect.Type
}

func (*UnsupportedTypeError) Error Uses

func (e *UnsupportedTypeError) Error() string

type Writer Uses

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

A Writer for BARE primitive types.

func NewWriter Uses

func NewWriter(base io.Writer) *Writer

Returns a new BARE primitive writer wrapping the given io.Writer.

func (*Writer) WriteBool Uses

func (w *Writer) WriteBool(b bool) error

func (*Writer) WriteData Uses

func (w *Writer) WriteData(data []byte) error

Writes arbitrary data whose length is encoded into the message.

func (*Writer) WriteDataFixed Uses

func (w *Writer) WriteDataFixed(data []byte) error

Writes a fixed amount of arbitrary data, defined by the length of the slice.

func (*Writer) WriteF32 Uses

func (w *Writer) WriteF32(f float32) error

func (*Writer) WriteF64 Uses

func (w *Writer) WriteF64(f float64) error

func (*Writer) WriteI16 Uses

func (w *Writer) WriteI16(i int16) error

func (*Writer) WriteI32 Uses

func (w *Writer) WriteI32(i int32) error

func (*Writer) WriteI64 Uses

func (w *Writer) WriteI64(i int64) error

func (*Writer) WriteI8 Uses

func (w *Writer) WriteI8(i int8) error

func (*Writer) WriteInt Uses

func (w *Writer) WriteInt(i int64) error

func (*Writer) WriteString Uses

func (w *Writer) WriteString(str string) error

func (*Writer) WriteU16 Uses

func (w *Writer) WriteU16(i uint16) error

func (*Writer) WriteU32 Uses

func (w *Writer) WriteU32(i uint32) error

func (*Writer) WriteU64 Uses

func (w *Writer) WriteU64(i uint64) error

func (*Writer) WriteU8 Uses

func (w *Writer) WriteU8(i uint8) error

func (*Writer) WriteUint Uses

func (w *Writer) WriteUint(i uint64) error

Directories

PathSynopsis
example
example/basic
example/stream
schema

Package bare imports 9 packages (graph) and is imported by 7 packages. Updated 2020-12-14. Refresh now. Tools for package owners.