Documentation
¶
Overview ¶
TODO AMINO DOCS, for now see the main README file, or the code.
Example ¶
package main
import (
"fmt"
"reflect"
amino "github.com/gnolang/gno/tm2/pkg/amino"
)
func main() {
type Message any
type bcMessage struct {
Message string
Height int
}
type bcResponse struct {
Status int
Message string
}
type bcStatus struct {
Peers int
}
// amino.RegisterPackage registers globally.
amino.RegisterPackage(
amino.NewPackage(
reflect.TypeOf(bcMessage{}).PkgPath(),
"amino_test",
amino.GetCallersDirname(),
).
WithTypes(&bcMessage{}, &bcResponse{}, &bcStatus{}),
)
bm := &bcMessage{Message: "ABC", Height: 100}
msg := bm
var bz []byte // the marshalled bytes.
var err error
bz, err = amino.MarshalAnySized(msg)
fmt.Printf("Encoded: %X (err: %v)\n", bz, err)
var msg2 Message
err = amino.UnmarshalSized(bz, &msg2)
fmt.Printf("Decoded: %v (err: %v)\n", msg2, err)
bm2 := msg2.(*bcMessage)
fmt.Printf("Decoded successfully: %v\n", *bm == *bm2)
}
Output: Encoded: 210A152F616D696E6F5F746573742E62634D65737361676512080A0341424310C801 (err: <nil>) Decoded: &{ABC 100} (err: <nil>) Decoded successfully: true
Index ¶
- Constants
- Variables
- func AppendBoolReversed(buf []byte, b bool) []byte
- func AppendByteReversed(buf []byte, b byte) []byte
- func AppendByteSliceReversed(buf []byte, bz []byte) []byte
- func AppendBytesReversed(buf []byte, bz []byte) []byte
- func AppendDurationReversed(buf []byte, d time.Duration) ([]byte, error)
- func AppendDurationValueReversed(buf []byte, s int64, ns int32) ([]byte, error)
- func AppendFieldNumberAndTyp3Reversed(buf []byte, num uint32, typ Typ3) []byte
- func AppendFloat32Reversed(buf []byte, f float32) []byte
- func AppendFloat64Reversed(buf []byte, f float64) []byte
- func AppendInt32Reversed(buf []byte, i int32) []byte
- func AppendInt64Reversed(buf []byte, i int64) []byte
- func AppendStringReversed(buf []byte, s string) []byte
- func AppendTimeReversed(buf []byte, t time.Time) ([]byte, error)
- func AppendTimeValueReversed(buf []byte, s int64, ns int32) ([]byte, error)
- func AppendUint32Reversed(buf []byte, u uint32) []byte
- func AppendUint64Reversed(buf []byte, u uint64) []byte
- func AppendUvarintReversed(buf []byte, u uint64) []byte
- func AppendVarintReversed(buf []byte, i int64) []byte
- func ByteSliceSize(bz []byte) 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 DecodeDuration(bz []byte) (d time.Duration, n int, err error)
- func DecodeDurationValue(bz []byte) (s int64, ns int32, 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 DecodeInt32(bz []byte) (i int32, n int, err error)
- func DecodeInt64(bz []byte) (i int64, n int, err error)
- func DecodeJSONDuration(bz []byte, fopts FieldOptions) (d time.Duration, err error)
- func DecodeJSONPBDuration(bz []byte, fopts FieldOptions) (d durationpb.Duration, err error)
- func DecodeJSONPBTimestamp(bz []byte, fopts FieldOptions) (t timestamppb.Timestamp, err error)
- func DecodeJSONTime(bz []byte, fopts FieldOptions) (t time.Time, err error)
- func DecodeString(bz []byte) (s string, n int, err error)
- func DecodeTime(bz []byte) (t time.Time, n int, err error)
- func DecodeTimeValue(bz []byte) (s int64, ns int32, 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 DecodeUvarint(bz []byte) (u uint64, n int, err error)
- func DecodeUvarint8(bz []byte) (u uint8, n int, err error)
- func DecodeUvarint16(bz []byte) (u uint16, n int, err error)
- func DecodeUvarint32(bz []byte) (u uint32, n int, err error)
- func DecodeVarint(bz []byte) (i int64, n int, err error)
- func DecodeVarint8(bz []byte) (i int8, n int, err error)
- func DecodeVarint16(bz []byte) (i int16, n int, err error)
- func DeepCopy(o any) (r any)
- func DeepCopyToPtr(o any) (ptr any)
- func DeepEqual(a, b any) bool
- func DurationSize(d time.Duration) int
- func EncodeBool(w io.Writer, b bool) (err error)
- func EncodeByte(w io.Writer, b byte) (err error)
- func EncodeByteSlice(w io.Writer, bz []byte) (err error)
- func EncodeDuration(w io.Writer, d time.Duration) (err error)
- func EncodeDurationValue(w io.Writer, s int64, ns int32) (err error)
- func EncodeFieldNumberAndTyp3(w io.Writer, num uint32, typ Typ3) error
- func EncodeFloat32(w io.Writer, f float32) (err error)
- func EncodeFloat64(w io.Writer, f float64) (err error)
- func EncodeInt32(w io.Writer, i int32) (err error)
- func EncodeInt64(w io.Writer, i int64) (err error)
- func EncodeJSONDuration(w io.Writer, d time.Duration) (err error)
- func EncodeJSONDurationValue(w io.Writer, s int64, ns int32) (err error)
- func EncodeJSONPBDuration(w io.Writer, d *durationpb.Duration) (err error)
- func EncodeJSONPBTimestamp(w io.Writer, t *timestamppb.Timestamp) (err error)
- func EncodeJSONTime(w io.Writer, t time.Time) (err error)
- func EncodeJSONTimeValue(w io.Writer, s int64, ns int32) (err error)
- func EncodeString(w io.Writer, s string) (err error)
- func EncodeTime(w io.Writer, t time.Time) (err error)
- func EncodeTimeValue(w io.Writer, s int64, ns int32) (err error)
- func EncodeUint32(w io.Writer, u uint32) (err error)
- func EncodeUint64(w io.Writer, u uint64) (err error)
- func EncodeUvarint(w io.Writer, u uint64) (err error)
- func EncodeUvarint8(w io.Writer, i uint8) (err error)
- func EncodeUvarint16(w io.Writer, i uint16) (err error)
- func EncodeUvarint32(w io.Writer, i uint32) (err error)
- func EncodeVarint(w io.Writer, i int64) (err error)
- func EncodeVarint8(w io.Writer, i int8) (err error)
- func EncodeVarint16(w io.Writer, i int16) (err error)
- func EncodeVarint32(w io.Writer, i int32) (err error)
- func GetCallersDirname() string
- func GetTypeURL(o any) string
- func HasNativeGenproto2(rt reflect.Type) bool
- func HasNativePbbindings(rt reflect.Type) bool
- func IsASCIIText(s string) bool
- func IsEmpty(o any) bool
- func IsEmptyTime(t time.Time) bool
- func IsTypedNil(o any) bool
- func Marshal(o any) ([]byte, error)
- func MarshalAny(o any) ([]byte, error)
- func MarshalAnySized(o any) ([]byte, error)
- func MarshalAnySizedWriter(w io.Writer, o any) (n int64, err error)
- func MarshalJSON(o any) ([]byte, error)
- func MarshalJSONAny(o any) ([]byte, error)
- func MarshalJSONIndent(o any, prefix, indent string) ([]byte, error)
- func MarshalSized(o any) ([]byte, error)
- func MarshalSizedWriter(w io.Writer, o any) (n int64, err error)
- func MustMarshal(o any) []byte
- func MustMarshalAny(o any) []byte
- func MustMarshalAnySized(o any) []byte
- func MustMarshalJSON(o any) []byte
- func MustMarshalJSONAny(o any) []byte
- func MustMarshalSized(o any) []byte
- func MustUnmarshal(bz []byte, ptr any)
- func MustUnmarshalAny(bz []byte, ptr any)
- func MustUnmarshalJSON(bz []byte, ptr any)
- func MustUnmarshalSized(bz []byte, ptr any)
- func PrependBool(buf []byte, offset int, b bool) int
- func PrependByte(buf []byte, offset int, b byte) int
- func PrependByteSlice(buf []byte, offset int, bz []byte) int
- func PrependBytes(buf []byte, offset int, bz []byte) int
- func PrependDuration(buf []byte, offset int, d time.Duration) (int, error)
- func PrependDurationValue(buf []byte, offset int, s int64, ns int32) (int, error)
- func PrependFieldNumberAndTyp3(buf []byte, offset int, num uint32, typ Typ3) int
- func PrependFloat32(buf []byte, offset int, f float32) int
- func PrependFloat64(buf []byte, offset int, f float64) int
- func PrependInt32(buf []byte, offset int, i int32) int
- func PrependInt64(buf []byte, offset int, i int64) int
- func PrependString(buf []byte, offset int, s string) int
- func PrependTime(buf []byte, offset int, t time.Time) (int, error)
- func PrependTimeValue(buf []byte, offset int, s int64, ns int32) (int, error)
- func PrependUint32(buf []byte, offset int, u uint32) int
- func PrependUint64(buf []byte, offset int, u uint64) int
- func PrependUvarint(buf []byte, offset int, u uint64) int
- func PrependVarint(buf []byte, offset int, i int64) int
- func RegisterGenproto2Type(rt reflect.Type)
- func RegisterPbbindingsType(rt reflect.Type)
- func SkipField(bz []byte, typ Typ3) (n int, err error)
- func TimeSize(t time.Time) int
- func Unmarshal(bz []byte, ptr any) error
- func UnmarshalAny(bz []byte, ptr any) error
- func UnmarshalAny2(typeURL string, value []byte, ptr any) error
- func UnmarshalAnySized(bz []byte, ptr any) error
- func UnmarshalJSON(bz []byte, ptr any) error
- func UnmarshalSized(bz []byte, ptr any) error
- func UnmarshalSizedReader(r io.Reader, ptr any, maxSize int64) (n int64, err error)
- func UvarintSize(u uint64) int
- func VarintSize(i int64) int
- type Codec
- func (cdc *Codec) Autoseal() *Codec
- func (cdc *Codec) GetPackages() pkg.PackageSet
- func (cdc *Codec) GetStats() *codecStats
- func (cdc *Codec) GetTypeInfo(rt reflect.Type) (info *TypeInfo, err error)
- func (cdc *Codec) GetTypeURL(o any) string
- func (cdc *Codec) JSONMarshal(o any) ([]byte, error)
- func (cdc *Codec) JSONUnmarshal(bz []byte, ptr any) error
- func (cdc *Codec) Marshal(o any) ([]byte, error)
- func (cdc *Codec) MarshalAny(o any) ([]byte, error)
- func (cdc *Codec) MarshalAnyBinary2(o any, buf []byte, offset int) (int, error)
- func (cdc *Codec) MarshalAnySized(o any) ([]byte, error)
- func (cdc *Codec) MarshalAnySizedWriter(w io.Writer, o any) (n int64, err error)
- func (cdc *Codec) MarshalBinary2(pbm2 PBMarshaler2) ([]byte, error)
- func (cdc *Codec) MarshalJSONAny(o any) ([]byte, error)
- func (cdc *Codec) MarshalJSONIndent(o any, prefix, indent string) ([]byte, error)
- func (cdc *Codec) MarshalPBBindings(pbm PBMessager) ([]byte, error)
- func (cdc *Codec) MarshalReflect(o any) ([]byte, error)
- func (cdc *Codec) MarshalSized(o any) ([]byte, error)
- func (cdc *Codec) MarshalSizedWriter(w io.Writer, o any) (n int64, err error)
- func (cdc *Codec) MustMarshal(o any) []byte
- func (cdc *Codec) MustMarshalAny(o any) []byte
- func (cdc *Codec) MustMarshalAnySized(o any) []byte
- func (cdc *Codec) MustMarshalJSON(o any) []byte
- func (cdc *Codec) MustMarshalJSONAny(o any) []byte
- func (cdc *Codec) MustMarshalSized(o any) []byte
- func (cdc *Codec) MustUnmarshal(bz []byte, ptr any)
- func (cdc *Codec) MustUnmarshalAny(bz []byte, ptr any)
- func (cdc *Codec) MustUnmarshalJSON(bz []byte, ptr any)
- func (cdc *Codec) MustUnmarshalSized(bz []byte, ptr any)
- func (cdc *Codec) PrintTypes(out io.Writer) error
- func (cdc *Codec) RegisterPackage(pkg *Package)
- func (cdc *Codec) RegisterTypeFrom(rt reflect.Type, pkg *Package)
- func (cdc *Codec) Seal() *Codec
- func (cdc *Codec) SizeAnyBinary2(o any) (int, error)
- func (cdc *Codec) Unmarshal(bz []byte, ptr any) error
- func (cdc *Codec) UnmarshalAny(bz []byte, ptr any) (err error)
- func (cdc *Codec) UnmarshalAny2(typeURL string, value []byte, ptr any) (err error)
- func (cdc *Codec) UnmarshalAnyBinary2(bz []byte, ptr any, anyDepth int) error
- func (cdc *Codec) UnmarshalAnySized(bz []byte, ptr any) error
- func (cdc *Codec) UnmarshalReflect(bz []byte, ptr any) error
- func (cdc *Codec) UnmarshalSized(bz []byte, ptr any) error
- func (cdc *Codec) UnmarshalSizedReader(r io.Reader, ptr any, maxSize int64) (n int64, err error)
- func (cdc *Codec) WithPBBindings() *Codec
- type ConcreteInfo
- type FieldInfo
- type FieldOptions
- type InterfaceInfo
- type InvalidDurationError
- type InvalidTimeError
- type Object
- type PBMarshaler2
- type PBMessager
- type PBMessager2
- type Package
- type StructInfo
- type Typ3
- type Type
- type TypeInfo
Examples ¶
Constants ¶
const ( // Typ3 types Typ3Varint = Typ3(0) Typ38Byte = Typ3(1) Typ3ByteLength = Typ3(2) // Typ3_Struct = Typ3(3) // Typ3_StructTerm = Typ3(4) Typ34Byte = Typ3(5) )
const ( GasEncodePerByte int64 = 3 // ~2.8 ns/byte amino marshal GasDecodePerByte int64 = 3 // ~2.8 ns/byte amino unmarshal (assumed) )
Gas constants for amino serialization compute cost. Calibrated from Binary2 (genproto2) benchmarks: ~2.8 ns/byte + 427 ns flat (see gnovm/adr/STORAGE_CHARGING_AMINO_HEURISTIC.png). The per-byte slope is used; the flat component is small relative to typical serialized sizes. Same slope assumed for decode pending separate benchmarks. These constants assume amino2 (Binary2).
const Version = "1.0.0-rc.10"
Version
Variables ¶
var ( // ErrNoPointer is thrown when you call a method that expects a pointer, e.g. Unmarshal ErrNoPointer = errors.New("expected a pointer") )
Functions ¶
func AppendBoolReversed ¶
func AppendByteReversed ¶
func AppendByteSliceReversed ¶
func AppendBytesReversed ¶
func AppendDurationReversed ¶
func AppendFloat32Reversed ¶
func AppendFloat64Reversed ¶
func AppendInt32Reversed ¶
func AppendInt64Reversed ¶
func AppendStringReversed ¶
func AppendTimeValueReversed ¶
func AppendUint32Reversed ¶
func AppendUint64Reversed ¶
func AppendUvarintReversed ¶
func AppendVarintReversed ¶
func ByteSliceSize ¶
func DecodeDurationValue ¶
func DecodeJSONDuration ¶
func DecodeJSONDuration(bz []byte, fopts FieldOptions) (d time.Duration, err error)
func DecodeJSONPBDuration ¶
func DecodeJSONPBDuration(bz []byte, fopts FieldOptions) (d durationpb.Duration, err error)
func DecodeJSONPBTimestamp ¶
func DecodeJSONPBTimestamp(bz []byte, fopts FieldOptions) (t timestamppb.Timestamp, err error)
func DecodeJSONTime ¶
func DecodeJSONTime(bz []byte, fopts FieldOptions) (t time.Time, err error)
func DecodeTimeValue ¶
DecodeTimeValue 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, an error is returned.
func DeepCopy ¶
Deeply copies an object. If anything implements `.DeepCopy() <any>` along the way, the result of that function will be used. Otherwise, if it implements `.MarshalAmino() (<any>, error)` and `.UnmarshalAmino(<any>) error`, the pair will be used to copy. If .MarshalAmino() or .UnmarshalAmino() returns an error, this function will panic.
func DeepCopyToPtr ¶
Like DeepCopy, but returns a pointer to the copy.
func DeepEqual ¶
DeepEqual returns true if the types are the same and the binary amino encoding would be the same. TODO: optimize, and support genproto.
func DurationSize ¶
DurationSize returns the encoded byte size of a time.Duration value (the bare content, without field key or length prefix).
func EncodeByte ¶
Unlike EncodeUint8, writes a single byte.
func EncodeDurationValue ¶
The binary encoding of Duration is the same as Timestamp, but the validation checks are different.
See https://godoc.org/google.golang.org/protobuf/types/known/durationpb#Duration
type Duration struct {
// Signed seconds of the span of time. Must be from -315,576,000,000
// to +315,576,000,000 inclusive. Note: these bounds are computed from:
// 60 sec/min * 60 min/hr * 24 hr/day * 365.25 days/year * 10000 years
Seconds int64 `protobuf:"varint,1,opt,name=seconds,proto3" json:"seconds,omitempty"`
// Signed fractions of a second at nanosecond resolution of the span
// of time. Durations less than one second are represented with a 0
// `seconds` field and a positive or negative `nanos` field. For durations
// of one second or more, a non-zero value for the `nanos` field must be
// of the same sign as the `seconds` field. Must be from -999,999,999
// to +999,999,999 inclusive.
Nanos int32 `protobuf:"varint,2,opt,name=nanos,proto3" json:"nanos,omitempty"`
// contains filtered or unexported fields
}
func EncodeFieldNumberAndTyp3 ¶
EncodeFieldNumberAndTyp3 writes a protobuf field key (field number + wire type). This is the exported wrapper around encodeFieldNumberAndTyp3 for use by generated code (genproto2).
func EncodeJSONDurationValue ¶
func EncodeJSONPBDuration ¶
func EncodeJSONPBDuration(w io.Writer, d *durationpb.Duration) (err error)
func EncodeJSONPBTimestamp ¶
func EncodeJSONPBTimestamp(w io.Writer, t *timestamppb.Timestamp) (err error)
func EncodeTimeValue ¶
EncodeTimeValue 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.
See https://godoc.org/google.golang.org/protobuf/types/known/timestamppb#Timestamp
type Timestamp struct {
// Represents seconds of UTC time since Unix epoch
// 1970-01-01T00:00:00Z. Must be from 0001-01-01T00:00:00Z to
// 9999-12-31T23:59:59Z inclusive.
Seconds int64 `protobuf:"varint,1,opt,name=seconds,proto3" json:"seconds,omitempty"`
// Non-negative fractions of a second at nanosecond resolution. Negative
// second values with fractions must still have non-negative nanos values
// that count forward in time. Must be from 0 to 999,999,999
// inclusive.
Nanos int32 `protobuf:"varint,2,opt,name=nanos,proto3" json:"nanos,omitempty"`
// contains filtered or unexported fields
}
func GetCallersDirname ¶
func GetCallersDirname() string
Get caller's package directory. Implementation uses `filepath.Dir(runtime.Caller(1))`. NOTE: duplicated in pkg/pkg.go; given what it does and how, both are probably needed.
func HasNativeGenproto2 ¶
HasNativeGenproto2 returns true if the type has its own genproto2 methods (not just promoted from an embedded struct).
func HasNativePbbindings ¶
HasNativePbbindings returns true if the type has its own pbbindings methods (not just promoted from an embedded struct).
func IsASCIIText ¶
Returns true if s is a non-empty printable non-tab ascii character.
func IsEmptyTime ¶
func IsTypedNil ¶
Go lacks a simple and safe way to see if something is a typed nil. See:
func MarshalAny ¶
func MarshalAnySized ¶
func MarshalJSON ¶
func MarshalJSONAny ¶
func MarshalSized ¶
func MustMarshal ¶
func MustMarshalAny ¶
func MustMarshalAnySized ¶
func MustMarshalJSON ¶
func MustMarshalJSONAny ¶
func MustMarshalSized ¶
func MustUnmarshal ¶
func MustUnmarshalAny ¶
func MustUnmarshalJSON ¶
func MustUnmarshalSized ¶
func PrependDurationValue ¶
func PrependTimeValue ¶
PrependTimeValue writes Timestamp proto fields backward into buf.
func RegisterGenproto2Type ¶
RegisterGenproto2Type records that a type has native genproto2 methods. Called from init() in generated pb3_gen.go files. Logs a warning if the type was already registered — duplicate init() calls typically indicate a regenerated file pulled in twice, or two generated files claiming the same type.
func RegisterPbbindingsType ¶
RegisterPbbindingsType records that a type has native pbbindings methods. Called from init() in generated pbbindings.go files. Logs a warning if the type was already registered — see RegisterGenproto2Type for typical causes.
func SkipField ¶
SkipField skips over a field value given its wire type. Used by generated unmarshal code to skip unknown fields.
func TimeSize ¶
TimeSize returns the encoded byte size of a time.Time value (the bare content, without field key or length prefix).
func UnmarshalAny ¶
func UnmarshalAnySized ¶
func UnmarshalJSON ¶
func UnmarshalSized ¶
func UnmarshalSizedReader ¶
func UvarintSize ¶
func VarintSize ¶
Types ¶
type Codec ¶
type Codec struct {
// contains filtered or unexported fields
}
func (*Codec) GetPackages ¶
func (cdc *Codec) GetPackages() pkg.PackageSet
XXX TODO: make this safe so modifications don't affect runtime codec, and ensure that it stays safe. NOTE: do not modify the returned Packages.
func (*Codec) GetStats ¶
func (cdc *Codec) GetStats() *codecStats
GetStats returns a pointer to the codec's decode-path counters for testing and observability.
func (*Codec) GetTypeInfo ¶
This is used primarily for gengo. XXX TODO: make this safe so modifications don't affect runtime codec, and ensure that it stays safe. NOTE: do not modify the returned TypeInfo.
func (*Codec) GetTypeURL ¶
TODO: this does need the cdc receiver, as it should also work for non-pbbindings-optimized types. Returns the default type url for the given concrete type. NOTE: It must be fast, as it is used in pbbindings. XXX Unstable API.
func (*Codec) Marshal ¶
Marshal encodes the object o according to the Amino spec. Marshal doesn't prefix the byte-length of the encoding, so the caller must handle framing. Type information as in google.protobuf.Any isn't included, so manually wrap before calling if you need to decode into an interface. NOTE: nil-struct-pointers have no encoding. In the context of a struct, the absence of a field does denote a nil-struct-pointer, but in general this is not the case, so unlike MarshalJSON.
func (*Codec) MarshalAny ¶
MarshalAny encodes the registered object wrapped with google.protobuf.Any.
func (*Codec) MarshalAnyBinary2 ¶
MarshalAnyBinary2 writes a google.protobuf.Any envelope backward into buf at offset, using the same Prepend* backward encoding as generated code. For use within generated MarshalBinary2 methods.
func (*Codec) MarshalAnySizedWriter ¶
func (*Codec) MarshalBinary2 ¶
func (cdc *Codec) MarshalBinary2(pbm2 PBMarshaler2) ([]byte, error)
Use genproto2 direct encoding.
func (*Codec) MarshalJSONIndent ¶
MarshalJSONIndent calls json.Indent on the output of cdc.MarshalJSON using the given prefix and indent string.
func (*Codec) MarshalPBBindings ¶
func (cdc *Codec) MarshalPBBindings(pbm PBMessager) ([]byte, error)
Use pbbindings.
func (*Codec) MarshalReflect ¶
Use reflection.
func (*Codec) MarshalSized ¶
MarshalSized encodes the object o according to the Amino spec, but prefixed by a uvarint encoding of the object to encode. Use Marshal if you don't want byte-length prefixing.
For consistency, MarshalSized will first dereference pointers before encoding. MarshalSized will panic if o is a nil-pointer, or if o is invalid.
func (*Codec) MarshalSizedWriter ¶
MarshalSizedWriter writes the bytes as would be returned from MarshalSized to the writer w.
func (*Codec) MustMarshalAnySized ¶
func (*Codec) MustMarshalJSON ¶
MustMarshalJSON panics if an error occurs. Besides that behaves exactly like MarshalJSON.
func (*Codec) MustMarshalJSONAny ¶
MustMarshalJSONAny panics if an error occurs. Besides that behaves exactly like MarshalJSONAny.
func (*Codec) MustUnmarshalAny ¶
func (*Codec) MustUnmarshalJSON ¶
MustUnmarshalJSON panics if an error occurs. Besides that behaves exactly like UnmarshalJSON.
func (*Codec) MustUnmarshalSized ¶
Panics if error.
func (*Codec) PrintTypes ¶
PrintTypes writes all registered types in a markdown-style table. The table's header is:
| Type | TypeURL | Notes |
Where Type is the golang type name and TypeURL is the type_url the type was registered with.
func (*Codec) RegisterPackage ¶
The package isn't (yet) necessary besides to get the full name of concrete types. Registers all dependencies of pkg recursively. This operation is idempotent -- pkgs already registered may be registered again.
func (*Codec) RegisterTypeFrom ¶
This function should be used to register concrete types that will appear in interface fields/elements to be encoded/decoded by go-amino. You may want to use RegisterPackage() instead which registers everything in a package. Usage: `amino.RegisterTypeFrom(MyStruct1{}, "/tm.cryp.MyStruct1")`
func (*Codec) SizeAnyBinary2 ¶
SizeAnyBinary2 computes the encoded size of a google.protobuf.Any envelope arithmetically, without marshaling. For use in generated SizeBinary2 methods.
func (*Codec) UnmarshalAny ¶
UnmarshalAny decodes the registered object from an Any.
func (*Codec) UnmarshalAny2 ¶
like UnmarshalAny() but with typeURL and value destructured.
func (*Codec) UnmarshalAnyBinary2 ¶
UnmarshalAnyBinary2 decodes a google.protobuf.Any-wrapped value using genproto2. For use within generated UnmarshalBinary2 methods. Unlike unmarshalAnyBinary2, this errors (not falls through) if the concrete type does not implement PBMessager2. UnmarshalAnyBinary2 decodes a google.protobuf.Any-wrapped value. anyDepth is incremented by 1 (the sole increment point for depth tracking); exceeding maxAnyDepth returns an error.
func (*Codec) UnmarshalAnySized ¶
Like UnmarshalAny, but will first decode the byte-length prefix.
func (*Codec) UnmarshalReflect ¶
Use reflection.
func (*Codec) UnmarshalSized ¶
Like Unmarshal, but will first decode the byte-length prefix. UnmarshalSized will panic if ptr is a nil-pointer. Returns an error if not all of bz is consumed.
func (*Codec) UnmarshalSizedReader ¶
Like Unmarshal, but will first read the byte-length prefix. UnmarshalSizedReader will panic if ptr is a nil-pointer. If maxSize is 0, there is no limit (not recommended).
func (*Codec) WithPBBindings ¶
Returns a new codec that is optimized w/ pbbindings. The returned codec is sealed, but may be affected by modifications to the underlying codec.
type ConcreteInfo ¶
type ConcreteInfo struct {
Registered bool // Registered with Register*().
Name string // Registered name which may override default reflection name.
PointerPreferred bool // Deserialize to pointer type if possible.
TypeURL string // <domain and path>/<p3 package no slashes>.<Name>
IsAminoMarshaler bool // Implements MarshalAmino() (<ReprObject>, error) and UnmarshalAmino(<ReprObject>) (error).
ReprType *TypeInfo // <ReprType> if IsAminoMarshaler, that, or by default the identity Type.
IsJSONValueType bool // If true, the Any representation uses the "value" field (instead of embedding @type).
IsBinaryWellKnownType bool // If true, use built-in functions to encode/decode.
IsJSONWellKnownType bool // If true, use built-in functions to encode/decode.
IsJSONAnyValueType bool // If true, the interface/Any representation uses the "value" field.
Elem *TypeInfo // Set if Type.Kind() is Slice or Array.
ElemIsPtr bool // Set true iff Type.Elem().Kind() is Pointer.
}
type FieldInfo ¶
type FieldInfo struct {
Type reflect.Type // Struct field reflect.Type.
TypeInfo *TypeInfo // Dereferenced struct field TypeInfo
Name string // Struct field name
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
}
func (*FieldInfo) ValidateBasic ¶
func (finfo *FieldInfo) ValidateBasic()
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)
NilElements bool // Empty list elements are decoded as nil iff set, otherwise are never nil.
UseGoogleTypes bool // If true, decodes Any timestamp and duration to google types.
}
type InterfaceInfo ¶
type InterfaceInfo struct{}
type InvalidDurationError ¶
type InvalidDurationError string
func (InvalidDurationError) Error ¶
func (e InvalidDurationError) Error() string
type InvalidTimeError ¶
type InvalidTimeError string
func (InvalidTimeError) Error ¶
func (e InvalidTimeError) Error() string
type Object ¶
type Object interface {
GetTypeURL() string
}
All concrete types must implement the Object interface for genproto bindings. They are generated automatically by genproto/bindings.go
type PBMarshaler2 ¶
type PBMarshaler2 interface {
MarshalBinary2(cdc *Codec, buf []byte, offset int) (int, error)
SizeBinary2(cdc *Codec) (int, error)
}
PBMessager2 is implemented by types that can directly marshal/unmarshal protobuf3 wire bytes without intermediate protobuf structs. Generated by genproto2. PBMarshaler2 is the encode-only subset of PBMessager2. Both methods have value receivers, so T (not just *T) satisfies this. Used by SizeAnyBinary2/MarshalAnyBinary2 for interface field encoding.
type PBMessager ¶
type PBMessager interface {
ToPBMessage(*Codec) (proto.Message, error)
EmptyPBMessage(*Codec) proto.Message
FromPBMessage(*Codec, proto.Message) error
}
Methods generated by genproto/bindings.go for faster encoding.
type PBMessager2 ¶
type PBMessager2 interface {
PBMarshaler2
UnmarshalBinary2(cdc *Codec, bz []byte, anyDepth int) error
}
type Package ¶
Package "pkg" exists So dependencies can create Packages. We export it here so this amino package can use it natively.
func NewPackage ¶
Create an unregistered amino package with args: - (gopkg string) The Go package path, e.g. "github.com/gnolang/gno/tm2/pkg/std" - (p3pkg string) The (shorter) Proto3 package path (no slashes), e.g. "std" - (dirname string) Package directory this is called from. Typical is to use `amino.GetCallersDirname()`
func RegisterPackage ¶
Given amino package `pi`, register it with the global codec. NOTE: do not modify the result.
type StructInfo ¶
type StructInfo struct {
Fields []FieldInfo // If a struct.
}
type Typ3 ¶
type Typ3 uint8
func DecodeFieldNumberAndTyp3 ¶
DecodeFieldNumberAndTyp3 reads a protobuf field key (field number + wire type). This is the exported wrapper around decodeFieldNumberAndTyp3 for use by generated code (genproto2).
type Type ¶
Package "pkg" exists So dependencies can create Packages. We export it here so this amino package can use it natively.
type TypeInfo ¶
type TypeInfo struct {
Type reflect.Type // never a pointer kind.
Package *Package // package associated with Type.
PtrToType reflect.Type
ZeroValue reflect.Value
InterfaceInfo
ConcreteInfo
StructInfo
}
func GetTypeInfo ¶
Returns a new TypeInfo instance. NOTE: it uses a new codec for security's sake. (*TypeInfo of gcdc should not be exposed) Therefore it may be inefficient. If you need efficiency, implement with a new method that takes as argument a non-global codec instance.
func (*TypeInfo) GetTyp3 ¶
func (info *TypeInfo) GetTyp3(fopts FieldOptions) Typ3
func (*TypeInfo) GetUltimateElem ¶
If this is a slice or array, get .Elem.ReprType until no longer slice or array.
func (*TypeInfo) IsStructOrUnpacked ¶
func (info *TypeInfo) IsStructOrUnpacked(fopt FieldOptions) bool
Used to determine whether to create an implicit struct or not. Notice that the binary encoding of a list to be unpacked is indistinguishable from a struct that contains that list. NOTE: we expect info.Elem to be prepopulated, constructed within the scope of a Codec.
func (*TypeInfo) IsStructOrUnpackedTopLevel ¶
IsStructOrUnpackedTopLevel is the top-level (non-struct-field) variant of IsStructOrUnpacked. Top-level contexts (e.g. MarshalReflect / MarshalBinary2 entry points, writeReprMarshal / writeReprUnmarshal) have no field-level BinFixed tag, so fopts is zero. Calling this helper instead of passing a literal FieldOptions{} makes the invariant explicit and greppable.
NOTE: a future top-level list type whose element's typ3 depends on BinFixed (e.g. `type Fixed64s []int64` used directly as a top-level message) would need the caller to thread a real fopts; today no such type exists and typ3 for non-BinFixed Int64 is Varint anyway, so this helper's behavior is identical to IsStructOrUnpacked(FieldOptions{}). Callers must ensure they are genuinely in a top-level context before using this helper.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
aminoscan
command
|
|
|
goscan
command
|
|
|
example
command
|
|
|
cmd
command
|
|
|
fuzz/binary/debug
command
|
|
|
fuzz/binary/init-corpus
command
|
|
|
fuzz/json/debug
command
|
|