Documentation ¶
Index ¶
- Constants
- Variables
- func ByteSliceSize(bz []byte) int
- func BytesToStr(b []byte) string
- func CalcBigIntTextSize(bi *big.Int) int
- func DecodeBool(bz []byte) (b bool, n int, err error)
- func DecodeByte(bz []byte) (b byte, n int, err error)
- func DecodeByteSlice(bz []byte) (bz2 []byte, n int, err error)
- func DecodeByteSliceToWriter(writer io.Writer, bz []byte) (n int, err error)
- func DecodeDisambPrefixBytes(bz []byte) (db DisambBytes, hasDb bool, pb PrefixBytes, hasPb bool, n int, err error)
- func DecodeFloat32(bz []byte) (f float32, n int, err error)
- func DecodeFloat64(bz []byte) (f float64, n int, err error)
- func DecodeInt16(bz []byte) (i int16, n int, err error)
- func DecodeInt32(bz []byte) (i int32, n int, err error)
- func DecodeInt64(bz []byte) (i int64, n int, err error)
- func DecodeInt8(bz []byte) (i int8, n int, err error)
- func DecodeString(bz []byte) (s string, n int, err error)
- func DecodeTime(bz []byte) (t time.Time, n int, err error)
- func DecodeUint16(bz []byte) (u uint16, n int, err error)
- func DecodeUint32(bz []byte) (u uint32, n int, err error)
- func DecodeUint64(bz []byte) (u uint64, n int, err error)
- func DecodeUint8(bz []byte) (u uint8, n int, err error)
- func DecodeUvarint(bz []byte) (u uint64, n int, err error)
- func DecodeVarint(bz []byte) (i int64, n int, err error)
- func EncodeBool(w io.Writer, b bool) (err error)
- func EncodeBoolToBuffer(w *bytes.Buffer, b bool) (err error)
- func EncodeBoolWithKeyToBuffer(w *bytes.Buffer, b bool, key ...byte) error
- func EncodeByte(w io.Writer, b byte) (err error)
- func EncodeByteSlice(w io.Writer, bz []byte) (err error)
- func EncodeByteSliceToBuffer(w *bytes.Buffer, bz []byte) (err error)
- func EncodeByteSliceWithKeyToBuffer(w *bytes.Buffer, bz []byte, key ...byte) error
- func EncodeByteToBuffer(w *bytes.Buffer, b byte) (err error)
- func EncodeFloat32(w io.Writer, f float32) (err error)
- func EncodeFloat32ToBuffer(w *bytes.Buffer, f float32) (err error)
- func EncodeFloat64(w io.Writer, f float64) (err error)
- func EncodeFloat64ToBuffer(w *bytes.Buffer, f float64) (err error)
- func EncodeInt16(w io.Writer, i int16) (err error)
- func EncodeInt16ToBuffer(w *bytes.Buffer, i int16) (err error)
- func EncodeInt32(w io.Writer, i int32) (err error)
- func EncodeInt32ToBuffer(w *bytes.Buffer, i int32) (err error)
- func EncodeInt64(w io.Writer, i int64) (err error)
- func EncodeInt64ToBuffer(w *bytes.Buffer, i int64) (err error)
- func EncodeInt8(w io.Writer, i int8) (err error)
- func EncodeInt8ToBuffer(w *bytes.Buffer, i int8) (err error)
- func EncodeProtoPosAndTypeMustOneByte(pos int, typ Typ3) (byte, error)
- func EncodeString(w io.Writer, s string) (err error)
- func EncodeStringToBuffer(buf *bytes.Buffer, s string) (err error)
- func EncodeStringWithKeyToBuffer(w *bytes.Buffer, s string, key ...byte) (err error)
- func EncodeTime(w io.Writer, t time.Time) (err error)
- func EncodeTimeToBuffer(w *bytes.Buffer, t time.Time) (err error)
- func EncodeTimeWithKeyToBuffer(w *bytes.Buffer, t time.Time, key ...byte) error
- func EncodeUint16(w io.Writer, u uint16) (err error)
- func EncodeUint16ToBuffer(w *bytes.Buffer, u uint16) (err error)
- func EncodeUint32(w io.Writer, u uint32) (err error)
- func EncodeUint32ToBuffer(w *bytes.Buffer, u uint32) (err error)
- func EncodeUint64(w io.Writer, u uint64) (err error)
- func EncodeUint64ToBuffer(w *bytes.Buffer, u uint64) (err error)
- func EncodeUint8(w io.Writer, u uint8) (err error)
- func EncodeUint8ToBuffer(w *bytes.Buffer, u uint8) (err error)
- func EncodeUvarint(w io.Writer, u uint64) (err error)
- func EncodeUvarintToBuffer(w *bytes.Buffer, u uint64) (err error)
- func EncodeUvarintWithKeyToBuffer(w *bytes.Buffer, u uint64, key ...byte) (err error)
- func EncodeVarint(w io.Writer, i int64) (err error)
- func EncodeVarintToBuffer(w *bytes.Buffer, i int64) (err error)
- func EncodedStringSize(s string) int
- func GetBinaryBareFromBinaryLengthPrefixed(bz []byte) ([]byte, error)
- func GetBytesBufferCopy(buf *bytes.Buffer) []byte
- func HexEncodeToString(src []byte) string
- func HexEncodeToStringUpper(src []byte) string
- func MarshalBigIntToText(bi *big.Int) (string, error)
- func NameToDisfix(name string) (db DisambBytes, pb PrefixBytes)
- func NewSizerError(value interface{}, expectSize, actualSize int) error
- func PutBuffer(b *Buffer)
- func StrToBytes(s string) []byte
- func TimeSize(t time.Time) int
- func UnmarshalBigIntBase10(bz []byte) (*big.Int, error)
- func UvarintSize(u uint64) int
- func VarintSize(i int64) int
- type Buffer
- type BufferPool
- type Codec
- func (cdc *Codec) EnableBufferMarshaler(o MarshalBufferSizer)
- func (cdc *Codec) GetTypePrefix(o interface{}, dst []byte) (int, error)
- func (cdc *Codec) MarshalBinaryBare(o interface{}) ([]byte, error)
- func (cdc *Codec) MarshalBinaryBareToWriter(writer io.Writer, o interface{}) error
- func (cdc *Codec) MarshalBinaryBareWithRegisteredMarshaller(o interface{}) ([]byte, error)
- func (cdc *Codec) MarshalBinaryLengthPrefixed(o interface{}) ([]byte, error)
- func (cdc *Codec) MarshalBinaryLengthPrefixedWithRegisteredMarshaller(o interface{}) ([]byte, error)
- func (cdc *Codec) MarshalBinaryLengthPrefixedWriter(w io.Writer, o interface{}) (n int64, err error)
- func (cdc *Codec) MarshalBinaryLengthPrefixedWriterWithRegiteredMarshaller(w io.Writer, o interface{}) (n int64, err error)
- func (cdc *Codec) MarshalBinaryWithSizer(o MarshalBufferSizer, withLengthPrefix bool) ([]byte, error)
- func (cdc *Codec) MarshalJSON(o interface{}) ([]byte, error)
- func (cdc *Codec) MarshalJSONIndent(o interface{}, prefix, indent string) ([]byte, error)
- func (cdc *Codec) MustMarshalBinaryBare(o interface{}) []byte
- func (cdc *Codec) MustMarshalBinaryBareToWriter(writer io.Writer, o interface{})
- func (cdc *Codec) MustMarshalBinaryLengthPrefixed(o interface{}) []byte
- func (cdc *Codec) MustMarshalBinaryWithSizer(o MarshalBufferSizer, withLengthPrefix bool) []byte
- func (cdc *Codec) MustMarshalJSON(o interface{}) []byte
- func (cdc *Codec) MustUnmarshalBinaryBare(bz []byte, ptr interface{})
- func (cdc *Codec) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr interface{})
- func (cdc *Codec) MustUnmarshalJSON(bz []byte, ptr interface{})
- func (cdc *Codec) PrintTypes(out io.Writer) error
- func (cdc *Codec) RegisterConcrete(o interface{}, name string, copts *ConcreteOptions)
- func (cdc *Codec) RegisterConcreteMarshaller(name string, marshaller ConcreteMarshaller)
- func (cdc *Codec) RegisterConcreteUnmarshaller(name string, unmarshaller ConcreteUnmarshaller)
- func (cdc *Codec) RegisterInterface(ptr interface{}, iopts *InterfaceOptions)
- func (cdc *Codec) Seal() *Codec
- func (cdc *Codec) UnmarshalBinaryBare(bz []byte, ptr interface{}) error
- func (cdc *Codec) UnmarshalBinaryBareWithRegisteredUnmarshaller(bz []byte, ptr interface{}) (interface{}, error)
- func (cdc *Codec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr interface{}) error
- func (cdc *Codec) UnmarshalBinaryLengthPrefixedReader(r io.Reader, ptr interface{}, maxSize int64) (n int64, err error)
- func (cdc *Codec) UnmarshalBinaryLengthPrefixedWithRegisteredUbmarshaller(bz []byte, ptr interface{}) (interface{}, error)
- func (cdc *Codec) UnmarshalJSON(bz []byte, ptr interface{}) error
- type ConcreteInfo
- type ConcreteMarshaller
- type ConcreteOptions
- type ConcreteUnmarshaller
- type DisambBytes
- type DisfixBytes
- type FieldInfo
- type FieldOptions
- type InterfaceInfo
- type InterfaceOptions
- type InvalidTimeErr
- type MarshalBufferSizer
- type Marshaller
- type PrefixBytes
- type Sizer
- type StructInfo
- type Typ3
- type TypeInfo
- type Unmarshaller
Constants ¶
const ( // Typ3 types Typ3_Varint = Typ3(0) Typ3_8Byte = Typ3(1) Typ3_ByteLength = Typ3(2) //Typ3_Struct = Typ3(3) //Typ3_StructTerm = Typ3(4) Typ3_4Byte = Typ3(5) )
const ( PrefixBytesLen = 4 DisambBytesLen = 3 DisfixBytesLen = PrefixBytesLen + DisambBytesLen )
Lengths
Variables ¶
var (
ErrOverflowInt = errors.New("encoded integer value overflows int(32)")
)
var GCodec = NewCodec()
var ZeroTime time.Time
Functions ¶
func ByteSliceSize ¶
func BytesToStr ¶
BytesToStr is meant to make a zero allocation conversion from []byte -> string to speed up operations, it is not meant to be used generally, but for a specific pattern to delete keys from a map.
func CalcBigIntTextSize ¶
func DecodeByteSliceToWriter ¶
func DecodeDisambPrefixBytes ¶
func DecodeDisambPrefixBytes(bz []byte) (db DisambBytes, hasDb bool, pb PrefixBytes, hasPb bool, n int, err error)
func DecodeTime ¶
DecodeTime decodes seconds (int64) and nanoseconds (int32) since January 1, 1970 UTC, and returns the corresponding time. If nanoseconds is not in the range [0, 999999999], or if seconds is too large, the behavior is undefined. TODO return error if behavior is undefined.
func EncodeFloat32ToBuffer ¶
NOTE: UNSAFE
func EncodeFloat64ToBuffer ¶
NOTE: UNSAFE
func EncodeTime ¶
EncodeTime writes the number of seconds (int64) and nanoseconds (int32), with millisecond resolution since January 1, 1970 UTC to the Writer as an UInt64. Milliseconds are used to ease compatibility with Javascript, which does not support finer resolution.
func EncodeTimeToBuffer ¶
EncodeTimeToBuffer writes the number of seconds (int64) and nanoseconds (int32), with millisecond resolution since January 1, 1970 UTC to the bytes.Buffer as an UInt64. Milliseconds are used to ease compatibility with Javascript, which does not support finer resolution.
func EncodeUvarint ¶
EncodeUvarint is used to encode golang's int, int32, int64 by default. unless specified differently by the `binary:"fixed32"`, `binary:"fixed64"`, or `binary:"zigzag32"` `binary:"zigzag64"` tags. It matches protobufs varint encoding.
func EncodedStringSize ¶
func GetBytesBufferCopy ¶
func HexEncodeToString ¶
func HexEncodeToStringUpper ¶
func NameToDisfix ¶
func NameToDisfix(name string) (db DisambBytes, pb PrefixBytes)
Return the DisambBytes and the PrefixBytes for a given name.
func NewSizerError ¶
func StrToBytes ¶
StrToBytes is meant to make a zero allocation conversion from string -> []byte to speed up operations, it is not meant to be used generally
func UvarintSize ¶
func VarintSize ¶
Types ¶
type Buffer ¶
func GetBuffer ¶
func GetBuffer() *Buffer
GetBuffer returns a new bytes.Buffer from the pool. you must call PutBuffer on the buffer when you are done with it.
func NewBufferString ¶
type BufferPool ¶
type BufferPool struct {
// contains filtered or unexported fields
}
func NewBufferPool ¶
func NewBufferPool() *BufferPool
func (*BufferPool) Get ¶
func (p *BufferPool) Get() *bytes.Buffer
func (*BufferPool) Put ¶
func (p *BufferPool) Put(buf *bytes.Buffer)
type Codec ¶
type Codec struct {
// contains filtered or unexported fields
}
func (*Codec) EnableBufferMarshaler ¶
func (cdc *Codec) EnableBufferMarshaler(o MarshalBufferSizer)
func (*Codec) GetTypePrefix ¶
GetTypePrefix copy type prefix bytes of o into dst len(dst) must >= 8 return (length of prefix, error)
func (*Codec) MarshalBinaryBare ¶
MarshalBinaryBare encodes the object o according to the Amino spec. MarshalBinaryBare doesn't prefix the byte-length of the encoding, so the caller must handle framing.
func (*Codec) MarshalBinaryBareToWriter ¶
func (*Codec) MarshalBinaryBareWithRegisteredMarshaller ¶
func (*Codec) MarshalBinaryLengthPrefixed ¶
MarshalBinaryLengthPrefixed encodes the object o according to the Amino spec, but prefixed by a uvarint encoding of the object to encode. Use MarshalBinaryBare if you don't want byte-length prefixing.
For consistency, MarshalBinaryLengthPrefixed will first dereference pointers before encoding. MarshalBinaryLengthPrefixed will panic if o is a nil-pointer, or if o is invalid.
func (*Codec) MarshalBinaryLengthPrefixedWithRegisteredMarshaller ¶
func (*Codec) MarshalBinaryLengthPrefixedWriter ¶
func (cdc *Codec) MarshalBinaryLengthPrefixedWriter(w io.Writer, o interface{}) (n int64, err error)
MarshalBinaryLengthPrefixedWriter writes the bytes as would be returned from MarshalBinaryLengthPrefixed to the writer w.
func (*Codec) MarshalBinaryLengthPrefixedWriterWithRegiteredMarshaller ¶
func (*Codec) MarshalBinaryWithSizer ¶
func (cdc *Codec) MarshalBinaryWithSizer(o MarshalBufferSizer, withLengthPrefix bool) ([]byte, error)
func (*Codec) MarshalJSON ¶
func (*Codec) MarshalJSONIndent ¶
MarshalJSONIndent calls json.Indent on the output of cdc.MarshalJSON using the given prefix and indent string.
func (*Codec) MustMarshalBinaryBare ¶
Panics if error.
func (*Codec) MustMarshalBinaryBareToWriter ¶
func (*Codec) MustMarshalBinaryLengthPrefixed ¶
Panics if error.
func (*Codec) MustMarshalBinaryWithSizer ¶
func (cdc *Codec) MustMarshalBinaryWithSizer(o MarshalBufferSizer, withLengthPrefix bool) []byte
func (*Codec) MustMarshalJSON ¶
MustMarshalJSON panics if an error occurs. Besides tha behaves exactly like MarshalJSON.
func (*Codec) MustUnmarshalBinaryBare ¶
Panics if error.
func (*Codec) MustUnmarshalBinaryLengthPrefixed ¶
Panics if error.
func (*Codec) MustUnmarshalJSON ¶
MustUnmarshalJSON panics if an error occurs. Besides tha behaves exactly like UnmarshalJSON.
func (*Codec) PrintTypes ¶
PrintTypes writes all registered types in a markdown-style table. The table's header is:
| Type | Name | Prefix | Notes |
Where Type is the golang type name and Name is the name the type was registered with.
func (*Codec) RegisterConcrete ¶
func (cdc *Codec) RegisterConcrete(o interface{}, name string, copts *ConcreteOptions)
This function should be used to register concrete types that will appear in interface fields/elements to be encoded/decoded by go-amino. Usage: `amino.RegisterConcrete(MyStruct1{}, "com.tendermint/MyStruct1", nil)`
func (*Codec) RegisterConcreteMarshaller ¶
func (cdc *Codec) RegisterConcreteMarshaller(name string, marshaller ConcreteMarshaller)
RegisterConcreteMarshaller registers a custom marshaller for a concrete type
func (*Codec) RegisterConcreteUnmarshaller ¶
func (cdc *Codec) RegisterConcreteUnmarshaller(name string, unmarshaller ConcreteUnmarshaller)
RegisterConcreteUnmarshaller registers a custom unmarshaller for a concrete type
func (*Codec) RegisterInterface ¶
func (cdc *Codec) RegisterInterface(ptr interface{}, iopts *InterfaceOptions)
This function should be used to register all interfaces that will be encoded/decoded by go-amino. Usage: `amino.RegisterInterface((*MyInterface1)(nil), nil)`
func (*Codec) UnmarshalBinaryBare ¶
UnmarshalBinaryBare will panic if ptr is a nil-pointer.
func (*Codec) UnmarshalBinaryBareWithRegisteredUnmarshaller ¶
func (cdc *Codec) UnmarshalBinaryBareWithRegisteredUnmarshaller(bz []byte, ptr interface{}) (interface{}, error)
UnmarshalBinaryBareInterfaceWithRegisteredUbmarshaller try to unmarshal the data with custom unmarshaller if it exists
func (*Codec) UnmarshalBinaryLengthPrefixed ¶
Like UnmarshalBinaryBare, but will first decode the byte-length prefix. UnmarshalBinaryLengthPrefixed will panic if ptr is a nil-pointer. Returns an error if not all of bz is consumed.
func (*Codec) UnmarshalBinaryLengthPrefixedReader ¶
func (cdc *Codec) UnmarshalBinaryLengthPrefixedReader(r io.Reader, ptr interface{}, maxSize int64) (n int64, err error)
Like UnmarshalBinaryBare, but will first read the byte-length prefix. UnmarshalBinaryLengthPrefixedReader will panic if ptr is a nil-pointer. If maxSize is 0, there is no limit (not recommended).
func (*Codec) UnmarshalBinaryLengthPrefixedWithRegisteredUbmarshaller ¶
func (cdc *Codec) UnmarshalBinaryLengthPrefixedWithRegisteredUbmarshaller(bz []byte, ptr interface{}) (interface{}, error)
Like UnmarshalBinaryBareWithRegisteredUnmarshaller, but will first decode the byte-length prefix.
func (*Codec) UnmarshalJSON ¶
type ConcreteInfo ¶
type ConcreteInfo struct { // These fields are only set when registered (as implementing an interface). Registered bool // Registered with RegisterConcrete(). PointerPreferred bool // Deserialize to pointer type if possible. // NilPreferred bool // Deserialize to nil for empty structs if PointerPreferred. Name string // Registered name. Disamb DisambBytes // Disambiguation bytes derived from name. Prefix PrefixBytes // Prefix bytes derived from name. ConcreteOptions // Registration options. // These fields get set for all concrete types, // even those not manually registered (e.g. are never interface values). IsAminoMarshaler bool // Implements MarshalAmino() (<ReprObject>, error). AminoMarshalReprType reflect.Type // <ReprType> IsAminoUnmarshaler bool // Implements UnmarshalAmino(<ReprObject>) (error). AminoUnmarshalReprType reflect.Type // <ReprType> MarshalBufferSizerEnabled bool }
func (ConcreteInfo) GetDisfix ¶
func (cinfo ConcreteInfo) GetDisfix() DisfixBytes
type ConcreteMarshaller ¶
type ConcreteOptions ¶
type ConcreteOptions struct { }
type ConcreteUnmarshaller ¶
type DisambBytes ¶
type DisambBytes [DisambBytesLen]byte
Prefix types
func (DisambBytes) Bytes ¶
func (db DisambBytes) Bytes() []byte
func (DisambBytes) EqualBytes ¶
func (db DisambBytes) EqualBytes(bz []byte) bool
type DisfixBytes ¶
type DisfixBytes [DisfixBytesLen]byte // Disamb+Prefix
Prefix types
func (DisfixBytes) Bytes ¶
func (df DisfixBytes) Bytes() []byte
func (DisfixBytes) EqualBytes ¶
func (df DisfixBytes) EqualBytes(bz []byte) bool
type FieldInfo ¶
type FieldInfo struct { Name string // Struct field name Type reflect.Type // Struct field type Index int // Struct field index ZeroValue reflect.Value // Could be nil pointer unlike TypeInfo.ZeroValue. UnpackedList bool // True iff this field should be encoded as an unpacked list. FieldOptions // Encoding options }
type FieldOptions ¶
type FieldOptions struct { JSONName string // (JSON) field name JSONOmitEmpty bool // (JSON) omitempty BinFixed64 bool // (Binary) Encode as fixed64 BinFixed32 bool // (Binary) Encode as fixed32 BinFieldNum uint32 // (Binary) max 1<<29-1 Unsafe bool // e.g. if this field is a float. WriteEmpty bool // write empty structs and lists (default false except for pointers) EmptyElements bool // Slice and Array elements are never nil, decode 0x00 as empty struct. }
type InterfaceInfo ¶
type InterfaceInfo struct { Priority []DisfixBytes // Disfix priority. Implementers map[PrefixBytes][]*TypeInfo // Mutated over time. InterfaceOptions }
type InterfaceOptions ¶
type InvalidTimeErr ¶
type InvalidTimeErr string
func (InvalidTimeErr) Error ¶
func (e InvalidTimeErr) Error() string
type MarshalBufferSizer ¶
type Marshaller ¶
type PrefixBytes ¶
type PrefixBytes [PrefixBytesLen]byte
Prefix types
func (PrefixBytes) Bytes ¶
func (pb PrefixBytes) Bytes() []byte
func (PrefixBytes) EqualBytes ¶
func (pb PrefixBytes) EqualBytes(bz []byte) bool
type StructInfo ¶
type StructInfo struct {
Fields []FieldInfo // If a struct.
}
type Typ3 ¶
type Typ3 uint8
func ParseProtoPosAndTypeMustOneByte ¶
ParseProtoPosAndTypeMustOneByte Parse field number and type from one byte, if original field number and type encode to multiple bytes, you should not use this function.
type TypeInfo ¶
type TypeInfo struct { Type reflect.Type // Interface type. PtrToType reflect.Type ZeroValue reflect.Value ZeroProto interface{} InterfaceInfo ConcreteInfo StructInfo }