Documentation ¶
Overview ¶
An implementation of the BARE message format for Go.
https://git.sr.ht/~sircmpwn/bare
See the git repository for usage examples:
Index ¶
- Variables
- func Marshal(val interface{}) ([]byte, error)
- func MarshalWriter(w *Writer, val interface{}) error
- func MaxArrayLength(length uint64)
- func MaxMapSize(size uint64)
- func MaxUnmarshalBytes(bytes uint64)
- func Unmarshal(data []byte, val interface{}) error
- func UnmarshalBareReader(r *Reader, val interface{}) error
- func UnmarshalReader(r io.Reader, val interface{}) error
- type Int
- type Marshalable
- type Reader
- func (r *Reader) ReadBool() (bool, error)
- func (r *Reader) ReadData() ([]byte, error)
- func (r *Reader) ReadDataFixed(dest []byte) error
- func (r *Reader) ReadF32() (float32, error)
- func (r *Reader) ReadF64() (float64, error)
- func (r *Reader) ReadI16() (int16, error)
- func (r *Reader) ReadI32() (int32, error)
- func (r *Reader) ReadI64() (int64, error)
- func (r *Reader) ReadI8() (int8, error)
- func (r *Reader) ReadInt() (int64, error)
- func (r *Reader) ReadString() (string, error)
- func (r *Reader) ReadU16() (uint16, error)
- func (r *Reader) ReadU32() (uint32, error)
- func (r *Reader) ReadU64() (uint64, error)
- func (r *Reader) ReadU8() (uint8, error)
- func (r *Reader) ReadUint() (uint64, error)
- type Uint
- type Union
- type UnionTags
- type Unmarshalable
- type UnsupportedTypeError
- type Writer
- func (w *Writer) WriteBool(b bool) error
- func (w *Writer) WriteData(data []byte) error
- func (w *Writer) WriteDataFixed(data []byte) error
- func (w *Writer) WriteF32(f float32) error
- func (w *Writer) WriteF64(f float64) error
- func (w *Writer) WriteI16(i int16) error
- func (w *Writer) WriteI32(i int32) error
- func (w *Writer) WriteI64(i int64) error
- func (w *Writer) WriteI8(i int8) error
- func (w *Writer) WriteInt(i int64) error
- func (w *Writer) WriteString(str string) error
- func (w *Writer) WriteU16(i uint16) error
- func (w *Writer) WriteU32(i uint32) error
- func (w *Writer) WriteU64(i uint64) error
- func (w *Writer) WriteU8(i uint8) error
- func (w *Writer) WriteUint(i uint64) error
Constants ¶
This section is empty.
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.
Functions ¶
func Marshal ¶
Marshals a value (val, which must be a pointer) into a BARE message.
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 ¶
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 ¶
func MaxArrayLength(length uint64)
MaxArrayLength sets maximum number of elements in array. Defaults to 4096 elements
func MaxMapSize ¶
func MaxMapSize(size uint64)
MaxMapSize sets maximum size of map. Defaults to 1024 key/value pairs
func MaxUnmarshalBytes ¶
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 ¶
Unmarshals a BARE message into val, which must be a pointer to a value of the message type.
func UnmarshalBareReader ¶
func UnmarshalReader ¶
Unmarshals a BARE message into value (val, which must be a pointer), from a reader. See Unmarshal for details.
Types ¶
type Marshalable ¶
A type which implements this interface will be responsible for marshaling itself when encountered.
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
A Reader for BARE primitive types.
func (*Reader) ReadDataFixed ¶
Reads a fixed amount of arbitrary data, defined by the length of the slice.
func (*Reader) ReadString ¶
type Union ¶
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 ¶
type UnionTags struct {
// contains filtered or unexported fields
}
func RegisterUnion ¶
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.
type Unmarshalable ¶
A type which implements this interface will be responsible for unmarshaling itself when encountered.
type UnsupportedTypeError ¶
func (*UnsupportedTypeError) Error ¶
func (e *UnsupportedTypeError) Error() string
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
A Writer for BARE primitive types.
func (*Writer) WriteDataFixed ¶
Writes a fixed amount of arbitrary data, defined by the length of the slice.