Documentation ¶
Index ¶
- Constants
- Variables
- func AnyFromJSON(v interface{}) (interface{}, error)
- func AnyToJSON(v interface{}) interface{}
- func AsBytes(v interface{}) []byte
- func BigintBinarySize(v *big.Int) int
- func BigintCopy(v *big.Int) *big.Int
- func BigintFromJSON(s *string) (*big.Int, error)
- func BigintMarshalBinary(v *big.Int) []byte
- func BigintToJSON(b *big.Int) *string
- func BigintUnmarshalBinary(b []byte) (*big.Int, error)
- func BoolBinarySize(_ bool) int
- func BoolMarshalBinary(v bool) []byte
- func BoolUnmarshalBinary(b []byte) (bool, error)
- func BytesBinarySize(b []byte) int
- func BytesCopy(v []byte) []byte
- func BytesFromJSON(s *string) ([]byte, error)
- func BytesMarshalBinary(b []byte) []byte
- func BytesToJSON(v []byte) *string
- func BytesUnmarshalBinary(b []byte) ([]byte, error)
- func ChainBinarySize(v *[32]byte) int
- func ChainFromJSON(s string) ([32]byte, error)
- func ChainMarshalBinary(v *[32]byte) []byte
- func ChainSetBinarySize(v [][32]byte) int
- func ChainSetFromJSON(s []string) ([][32]byte, error)
- func ChainSetMarshalBinary(v [][32]byte) []byte
- func ChainSetToJSON(v [][32]byte) []string
- func ChainSetUnmarshalBinary(b []byte) ([][32]byte, error)
- func ChainToJSON(v [32]byte) string
- func ChainUnmarshalBinary(b []byte) ([32]byte, error)
- func DurationBinarySize(d time.Duration) int
- func DurationFromJSON(v interface{}) (time.Duration, error)
- func DurationMarshalBinary(d time.Duration) []byte
- func DurationToJSON(v time.Duration) interface{}
- func DurationUnmarshalBinary(b []byte) (time.Duration, error)
- func SetPtr(value, target interface{}) (err error)
- func SplitDuration(d time.Duration) (sec, ns uint64)
- func StringBinarySize(s string) int
- func StringMarshalBinary(s string) []byte
- func StringUnmarshalBinary(b []byte) (string, error)
- func TimeBinarySize(v time.Time) int
- func TimeMarshalBinary(v time.Time) []byte
- func TimeUnmarshalBinary(b []byte) (time.Time, error)
- func UnmarshalEnumType(r io.Reader, value EnumValueSetter) error
- func UvarintBinarySize(v uint64) int
- func UvarintMarshalBinary(v uint64) []byte
- func UvarintUnmarshalBinary(b []byte) (uint64, error)
- func VarintBinarySize(v int64) int
- func VarintMarshalBinary(v int64) []byte
- func VarintUnmarshalBinary(b []byte) (int64, error)
- type BinaryValue
- type Byter
- type DurationFields
- type EnumValueGetter
- type EnumValueSetter
- type JsonList
- type JsonUnmarshalListWith
- type JsonUnmarshalWith
- type Reader
- func (r *Reader) ReadAll() ([]byte, error)
- func (r *Reader) ReadBigInt(n uint) (*big.Int, bool)
- func (r *Reader) ReadBool(n uint) (bool, bool)
- func (r *Reader) ReadBytes(n uint) ([]byte, bool)
- func (r *Reader) ReadDuration(n uint) (time.Duration, bool)
- func (r *Reader) ReadEnum(n uint, v EnumValueSetter) bool
- func (r *Reader) ReadFloat(n uint) (float64, bool)
- func (r *Reader) ReadHash(n uint) (*[32]byte, bool)
- func (r *Reader) ReadInt(n uint) (int64, bool)
- func (r *Reader) ReadString(n uint) (string, bool)
- func (r *Reader) ReadTime(n uint) (time.Time, bool)
- func (r *Reader) ReadTxid(n uint) (*url.TxID, bool)
- func (r *Reader) ReadUint(n uint) (uint64, bool)
- func (r *Reader) ReadUrl(n uint) (*url.URL, bool)
- func (r *Reader) ReadValue(n uint, unmarshal func([]byte) error) bool
- func (r *Reader) Reset(fieldNames []string) (seen []bool, err error)
- type Writer
- func (w *Writer) Reset(fieldNames []string) (written int, lastField uint, err error)
- func (w *Writer) WriteBigInt(n uint, v *big.Int)
- func (w *Writer) WriteBool(n uint, v bool)
- func (w *Writer) WriteBytes(n uint, v []byte)
- func (w *Writer) WriteDuration(n uint, v time.Duration)
- func (w *Writer) WriteEnum(n uint, v EnumValueGetter)
- func (w *Writer) WriteFloat(n uint, v float64)
- func (w *Writer) WriteHash(n uint, v *[32]byte)
- func (w *Writer) WriteInt(n uint, v int64)
- func (w *Writer) WriteString(n uint, v string)
- func (w *Writer) WriteTime(n uint, v time.Time)
- func (w *Writer) WriteTxid(n uint, v *url.TxID)
- func (w *Writer) WriteUint(n uint, v uint64)
- func (w *Writer) WriteUrl(n uint, v *url.URL)
- func (w *Writer) WriteValue(n uint, v encoding.BinaryMarshaler)
Constants ¶
const EmptyObject = 0x80
EmptyObject is written when an object would otherwise be empty.
Variables ¶
var ErrFieldsOutOfOrder = errors.New("fields are out of order")
var ErrInvalidFieldNumber = errors.New("field number is invalid")
ErrInvalidFieldNumber is returned when an invalid field number is encountered.
var ErrMalformedBigInt = errors.New("invalid big integer string")
var ErrNotEnoughData = errors.New("not enough data")
var ErrOverflow = errors.New("overflow")
Functions ¶
func AnyFromJSON ¶
func AnyFromJSON(v interface{}) (interface{}, error)
AnyFromJSON converts v to a duration if it appears to be a duration. AnyFromJSON never returns an error.
func BigintBinarySize ¶
func BigintMarshalBinary ¶
func BigintToJSON ¶
func BoolBinarySize ¶
func BoolMarshalBinary ¶
func BoolUnmarshalBinary ¶
func BytesBinarySize ¶
func BytesFromJSON ¶
func BytesMarshalBinary ¶
func BytesToJSON ¶
func BytesUnmarshalBinary ¶
func ChainBinarySize ¶
ToDo: Why a parameter? It does nothing...
func ChainFromJSON ¶
func ChainMarshalBinary ¶
func ChainSetBinarySize ¶
func ChainSetFromJSON ¶
func ChainSetMarshalBinary ¶
func ChainSetToJSON ¶
func ChainSetUnmarshalBinary ¶
func ChainToJSON ¶
func ChainUnmarshalBinary ¶
func DurationBinarySize ¶
func DurationFromJSON ¶
func DurationMarshalBinary ¶
func DurationToJSON ¶
func SetPtr ¶ added in v0.5.1
func SetPtr(value, target interface{}) (err error)
SetPtr sets *target = value
func SplitDuration ¶
func StringBinarySize ¶
func StringMarshalBinary ¶
func StringUnmarshalBinary ¶
func TimeBinarySize ¶
func TimeMarshalBinary ¶
func UnmarshalEnumType ¶
func UnmarshalEnumType(r io.Reader, value EnumValueSetter) error
func UvarintBinarySize ¶
func UvarintMarshalBinary ¶
func UvarintUnmarshalBinary ¶
func VarintBinarySize ¶
func VarintMarshalBinary ¶
func VarintUnmarshalBinary ¶
Types ¶
type BinaryValue ¶
type BinaryValue interface { encoding.BinaryMarshaler encoding.BinaryUnmarshaler CopyAsInterface() interface{} UnmarshalBinaryFrom(io.Reader) error }
type Byter ¶
type Byter interface {
Bytes() []byte
}
Byter is implemented by any value that has a Bytes method.
type DurationFields ¶
type EnumValueGetter ¶ added in v0.5.1
type EnumValueGetter interface {
GetEnumValue() uint64
}
type EnumValueSetter ¶ added in v0.5.1
type JsonList ¶ added in v0.6.0
type JsonList[T any] []T
JsonList attempts to unmarshal JSON into a slice of T and falls back to unmarshalling it into a single value of type T. Thus, fields of type JsonList can be unmarshaled from a single value or a list.
func (*JsonList[T]) UnmarshalJSON ¶ added in v0.6.0
type JsonUnmarshalListWith ¶ added in v0.6.0
JsonUnmarshalListWith combines the functionality of JsonList and JsonUnmarshalWith, using the given function to unmarshal JSON into a slice of T and falls back to unmarshalling it into a single value of type T.
func (*JsonUnmarshalListWith[T]) MarshalJSON ¶ added in v0.6.0
func (j *JsonUnmarshalListWith[T]) MarshalJSON() ([]byte, error)
func (*JsonUnmarshalListWith[T]) UnmarshalJSON ¶ added in v0.6.0
func (j *JsonUnmarshalListWith[T]) UnmarshalJSON(data []byte) error
type JsonUnmarshalWith ¶ added in v0.6.0
JsonUnmarshalWith uses the given function to unmarshal JSON into a value of type T.
func (*JsonUnmarshalWith[T]) MarshalJSON ¶ added in v0.6.0
func (j *JsonUnmarshalWith[T]) MarshalJSON() ([]byte, error)
func (*JsonUnmarshalWith[T]) UnmarshalJSON ¶ added in v0.6.0
func (j *JsonUnmarshalWith[T]) UnmarshalJSON(data []byte) error
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
func (*Reader) ReadBigInt ¶
ReadBigInt reads the value as a big-endian byte slice.
func (*Reader) ReadBool ¶
ReadBool reads the value as a varint-encoded unsigned integer. An error is recorded if the value is not 0 or 1.
func (*Reader) ReadBytes ¶
ReadBytes reads the length of the value as a varint-encoded unsigned integer followed by the value.
func (*Reader) ReadDuration ¶
ReadDuration reads the value as seconds and nanoseconds, each as a varint-encoded unsigned integer.
func (*Reader) ReadFloat ¶ added in v0.6.0
ReadFloat reads the value as a varint-encoded unsigned integer.
func (*Reader) ReadString ¶
ReadString reads the length of the value as a varint-encoded unsigned integer followed by the value.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
A Writer is used to binary-encode a struct and write it to a io.Writer.
If any attempt to write fails, all subsequent write methods are no-ops until Err is called.
func (*Writer) Reset ¶
Reset returns the total number of bytes written, the last field written, and an error, if one occurred, and resets the writer.
If a list of field names is provided, the error will be formatted as "field <name>: <err>".
func (*Writer) WriteBigInt ¶
WriteBigInt writes the value as a big-endian byte slice.
func (*Writer) WriteBytes ¶
WriteBytes writes the length of the value as a varint-encoded unsigned integer followed by the value.
func (*Writer) WriteDuration ¶
WriteDuration writes the value as seconds and nanoseconds, each as a varint-encoded unsigned integer.
func (*Writer) WriteEnum ¶
func (w *Writer) WriteEnum(n uint, v EnumValueGetter)
WriteEnum writes the value as a varint-encoded unsigned integer.
func (*Writer) WriteFloat ¶ added in v0.6.0
WriteFloat writes the value as a IEEE 754 encoded floating point number.
func (*Writer) WriteString ¶
WriteString writes the length of the value as a varint-encoded unsigned integer followed by the value.
func (*Writer) WriteTime ¶
WriteTime writes the value as a varint-encoded UTC Unix timestamp (signed).
func (*Writer) WriteValue ¶
func (w *Writer) WriteValue(n uint, v encoding.BinaryMarshaler)
WriteValue marshals the value and writes it as a byte slice.