Skip to content

Instantly share code, notes, and snippets.

@aaronc
Last active January 17, 2020 15:20
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save aaronc/5db093af9e39d765d7bf4fc0e2439714 to your computer and use it in GitHub Desktop.

Observations

  • for binary encoding we almost always want protobuf
  • for json we almost always want amino for querier backwards compatibility (protobuf json will happen elsewhere)
  • in some cases we want to allow amino as a fallback for interfaces

Marshaler

type Marshaler interface {
  // proto used for binary
	MarshalBinaryBare(o ProtoMarshaler) ([]byte, error)
	UnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler{}) error
  
  ...

  // amino json
	MarshalJSON(o interface{}) ([]byte, error) // nolint: stdmethods
	MustMarshalJSON(o interface{}) []byte

	UnmarshalJSON(bz []byte, ptr interface{}) error // nolint: stdmethods
	MustUnmarshalJSON(bz []byte, ptr interface{})
}

// ProtoMarshaler defines an interface a type must implement as protocol buffer
// defined message.
type ProtoMarshaler interface {
	proto.Message // for JSON serialization

	Marshal() ([]byte, error)
	MarshalTo(data []byte) (n int, err error)
	MarshalToSizedBuffer(dAtA []byte) (int, error)
	Size() int
	Unmarshal(data []byte) error
}

AuthCodec

What was there before to allow amino or pb for Account

type AuthCodec interface {
	codec.Marshaler

	MarshalAccount(acc exported.AccountI) ([]byte, error)
	UnmarshalAccount(bz []byte) (exported.AccountI, error)

	MarshalAccountJSON(acc exported.AccountI) ([]byte, error)
	UnmarshalAccountJSON(bz []byte) (exported.AccountI, error)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment