Documentation ¶
Index ¶
- Constants
- Variables
- func AnyFromJSON(v interface{}) (interface{}, error)
- func AnyToJSON(v interface{}) interface{}
- func BigintCopy(v *big.Int) *big.Int
- func BigintFromJSON(s *string) (*big.Int, error)
- func BigintToJSON(b *big.Int) *string
- func BytesCopy(v []byte) []byte
- func BytesFromJSON(s *string) ([]byte, error)
- func BytesToJSON(v []byte) *string
- func ChainFromJSON(s string) ([32]byte, error)
- func ChainToJSON(v [32]byte) string
- func DurationFromJSON(v interface{}) (time.Duration, error)
- func DurationToJSON(v time.Duration) interface{}
- func SplitDuration(d time.Duration) (sec, ns uint64)
- type BinaryValue
- type DurationFields
- type EnumValueGetter
- type EnumValueSetter
- type Error
- 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, marshal func() ([]byte, error))
- func (w *Writer) WriteValueOld(n uint, v encoding.BinaryMarshaler)
Constants ¶
const EmptyObject = 0x80
EmptyObject is written when an object would otherwise be empty.
const MaxValueSize = 1 << 24
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 BigintToJSON ¶
func BytesFromJSON ¶
func BytesToJSON ¶
func ChainFromJSON ¶
func ChainToJSON ¶
func DurationFromJSON ¶
func DurationToJSON ¶
func SplitDuration ¶
Types ¶
type BinaryValue ¶
type BinaryValue interface { encoding.BinaryMarshaler encoding.BinaryUnmarshaler CopyAsInterface() interface{} UnmarshalBinaryFrom(io.Reader) error }
type DurationFields ¶
type EnumValueGetter ¶
type EnumValueGetter interface {
GetEnumValue() uint64
}
type EnumValueSetter ¶
type JsonList ¶
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 ¶
type JsonUnmarshalListWith ¶
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 ¶
func (j *JsonUnmarshalListWith[T]) MarshalJSON() ([]byte, error)
func (*JsonUnmarshalListWith[T]) UnmarshalJSON ¶
func (j *JsonUnmarshalListWith[T]) UnmarshalJSON(data []byte) error
type JsonUnmarshalWith ¶
JsonUnmarshalWith uses the given function to unmarshal JSON into a value of type T.
func (*JsonUnmarshalWith[T]) MarshalJSON ¶
func (j *JsonUnmarshalWith[T]) MarshalJSON() ([]byte, error)
func (*JsonUnmarshalWith[T]) UnmarshalJSON ¶
func (j *JsonUnmarshalWith[T]) UnmarshalJSON(data []byte) error
type Reader ¶
type Reader struct { IgnoreSizeLimit bool // 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) ReadString ¶
ReadString reads the length of the value as a varint-encoded unsigned integer followed by the value.
type Writer ¶
type Writer struct { IgnoreSizeLimit bool // 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 ¶
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 ¶
WriteValue marshals the value and writes it as a byte slice.
func (*Writer) WriteValueOld ¶
func (w *Writer) WriteValueOld(n uint, v encoding.BinaryMarshaler)
WriteValue marshals the value and writes it as a byte slice.