Skip to content

Implement customtype's (Cosmos Scalars) #2

@aaronc

Description

@aaronc
  • cosmos_proto.scalar proto option that applies string and bytes types
  • Mapping YAML config file between scalars (language agnostic) and golang types
    Ex:
scalars:
  cosmos.Int: github.com/cosmos/cosmos-sdk/types.Int
  • define CustomType golang interface that all golang scalar type implementations need to implement (ex. Int), this is what we're using for gogo proto and can maybe reuse:
type CustomType interface {
	Marshal() ([]byte, error)
	MarshalTo(data []byte) (n int, err error)
	Unmarshal(data []byte) error
	Size() int

	MarshalJSON() ([]byte, error)
	UnmarshalJSON(data []byte) error
}

An alternative that just deals with string and bytes types could be:

type CustomStringType interface {
  MarshalString() (string, error)
  UnmarshalString(string) error
}

type CustomBytesTypes interface {
  MarshalBytes() ([]byte, error)
  UnmarshalBytes([]byte) error
}

Depending on whether cosmos_proto.scalar is used on a string or bytes type, the corresponding interface would be used.

  • generate protoreflect.Message handling
  • generate fast marshaling handling

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions