aminojson

package
v0.0.0-...-095f669 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const MaxDurationSeconds = int64(math.MaxInt64/int(1e9)) - 1

MaxDurationSeconds the maximum number of seconds (when expressed as nanoseconds) which can fit in an int64. gogoproto encodes google.protobuf.Duration as a time.Duration, which is 64-bit signed integer.

Variables

This section is empty.

Functions

This section is empty.

Types

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

Encoder is a JSON encoder that uses the Amino JSON encoding rules for protobuf messages.

func NewAminoJSON

func NewAminoJSON() Encoder

NewAminoJSON returns a new Encoder capable of serializing protobuf messages to JSON using the Amino JSON encoding rules.

func (Encoder) DefineFieldEncoding

func (enc Encoder) DefineFieldEncoding(name string, encoder FieldEncoder) Encoder

DefineFieldEncoding defines a custom encoding for a protobuf field. The `name` field must match a usage of an (amino.encoding) option in the protobuf message as in the following example. This encoding will be used instead of the default encoding for all usages of the tagged field.

message Balance {
  repeated cosmos.base.v1beta1.Coin coins = 2 [
    (amino.encoding)         = "legacy_coins",
    (gogoproto.castrepeated) = "github.com/verzth/cosmos-sdk/types.Coins",
    (gogoproto.nullable)     = false,
    (amino.dont_omitempty)   = true
  ];
  ...
}

func (Encoder) DefineMessageEncoding

func (enc Encoder) DefineMessageEncoding(name string, encoder MessageEncoder) Encoder

DefineMessageEncoding defines a custom encoding for a protobuf message. The `name` field must match a usage of an (amino.message_encoding) option in the protobuf message as in the following example. This encoding will be used instead of the default encoding for all usages of the tagged message.

message ModuleAccount {
  option (amino.name)                        = "cosmos-sdk/ModuleAccount";
  option (amino.message_encoding)            = "module_account";
  ...
}

func (Encoder) Marshal

func (enc Encoder) Marshal(message proto.Message) ([]byte, error)

Marshal serializes a protobuf message to JSON.

type FieldEncoder

type FieldEncoder func(*Encoder, protoreflect.Value, io.Writer) error

FieldEncoder is a function that can encode a protobuf protoreflect.Value to JSON.

type MessageEncoder

type MessageEncoder func(*Encoder, protoreflect.Message, io.Writer) error

MessageEncoder is a function that can encode a protobuf protoreflect.Message to JSON.

Directories

Path Synopsis
internal
testpb
Code generated by protoc-gen-go-pulsar.
Code generated by protoc-gen-go-pulsar.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL