-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR #5491: Protobuf Introduction + Types
- Loading branch information
1 parent
f091204
commit 26d6e49
Showing
34 changed files
with
2,826 additions
and
398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
build: | ||
roots: | ||
- . | ||
lint: | ||
use: | ||
- DEFAULT | ||
- COMMENTS | ||
- FILE_LOWER_SNAKE_CASE | ||
except: | ||
- UNARY_RPC | ||
- COMMENT_FIELD | ||
- PACKAGE_DIRECTORY_MATCH | ||
ignore: | ||
- third_party | ||
breaking: | ||
use: | ||
- FILE | ||
ignore: | ||
- third_party |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package codec | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
|
||
amino "github.com/tendermint/go-amino" | ||
cryptoamino "github.com/tendermint/tendermint/crypto/encoding/amino" | ||
tmtypes "github.com/tendermint/tendermint/types" | ||
) | ||
|
||
// Cdc defines a global generic sealed Amino codec to be used throughout sdk. It | ||
// has all Tendermint crypto and evidence types registered. | ||
// | ||
// TODO: Consider removing this global. | ||
var Cdc *Codec | ||
|
||
func init() { | ||
cdc := New() | ||
RegisterCrypto(cdc) | ||
RegisterEvidences(cdc) | ||
Cdc = cdc.Seal() | ||
} | ||
|
||
// Codec defines a type alias for an Amino codec. | ||
type Codec = amino.Codec | ||
|
||
func New() *Codec { | ||
return amino.NewCodec() | ||
} | ||
|
||
// RegisterCrypto registers all crypto dependency types with the provided Amino | ||
// codec. | ||
func RegisterCrypto(cdc *Codec) { | ||
cryptoamino.RegisterAmino(cdc) | ||
} | ||
|
||
// RegisterEvidences registers Tendermint evidence types with the provided Amino | ||
// codec. | ||
func RegisterEvidences(cdc *Codec) { | ||
tmtypes.RegisterEvidences(cdc) | ||
} | ||
|
||
// MarshalJSONIndent provides a utility for indented JSON encoding of an object | ||
// via an Amino codec. It returns an error if it cannot serialize or indent as | ||
// JSON. | ||
func MarshalJSONIndent(cdc *Codec, obj interface{}) ([]byte, error) { | ||
bz, err := cdc.MarshalJSON(obj) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var out bytes.Buffer | ||
if err = json.Indent(&out, bz, "", " "); err != nil { | ||
return nil, err | ||
} | ||
|
||
return out.Bytes(), nil | ||
} | ||
|
||
// MustMarshalJSONIndent executes MarshalJSONIndent except it panics upon failure. | ||
func MustMarshalJSONIndent(cdc *Codec, obj interface{}) []byte { | ||
bz, err := MarshalJSONIndent(cdc, obj) | ||
if err != nil { | ||
panic(fmt.Sprintf("failed to marshal JSON: %s", err)) | ||
} | ||
|
||
return bz | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package codec | ||
|
||
// AminoCodec defines a codec that utilizes Amino for both binary and JSON | ||
// encoding. | ||
type AminoCodec struct { | ||
amino *Codec | ||
} | ||
|
||
func NewAminoCodec(amino *Codec) Marshaler { | ||
return &AminoCodec{amino} | ||
} | ||
|
||
func (ac *AminoCodec) MarshalBinaryBare(o ProtoMarshaler) ([]byte, error) { | ||
return ac.amino.MarshalBinaryBare(o) | ||
} | ||
|
||
func (ac *AminoCodec) MustMarshalBinaryBare(o ProtoMarshaler) []byte { | ||
return ac.amino.MustMarshalBinaryBare(o) | ||
} | ||
|
||
func (ac *AminoCodec) MarshalBinaryLengthPrefixed(o ProtoMarshaler) ([]byte, error) { | ||
return ac.amino.MarshalBinaryLengthPrefixed(o) | ||
} | ||
|
||
func (ac *AminoCodec) MustMarshalBinaryLengthPrefixed(o ProtoMarshaler) []byte { | ||
return ac.amino.MustMarshalBinaryLengthPrefixed(o) | ||
} | ||
|
||
func (ac *AminoCodec) UnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) error { | ||
return ac.amino.UnmarshalBinaryBare(bz, ptr) | ||
} | ||
|
||
func (ac *AminoCodec) MustUnmarshalBinaryBare(bz []byte, ptr ProtoMarshaler) { | ||
ac.amino.MustUnmarshalBinaryBare(bz, ptr) | ||
} | ||
|
||
func (ac *AminoCodec) UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error { | ||
return ac.amino.UnmarshalBinaryLengthPrefixed(bz, ptr) | ||
} | ||
|
||
func (ac *AminoCodec) MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) { | ||
ac.amino.MustUnmarshalBinaryLengthPrefixed(bz, ptr) | ||
} | ||
|
||
func (ac *AminoCodec) MarshalJSON(o interface{}) ([]byte, error) { // nolint: stdmethods | ||
return ac.amino.MarshalJSON(o) | ||
} | ||
|
||
func (ac *AminoCodec) MustMarshalJSON(o interface{}) []byte { | ||
return ac.amino.MustMarshalJSON(o) | ||
} | ||
|
||
func (ac *AminoCodec) UnmarshalJSON(bz []byte, ptr interface{}) error { // nolint: stdmethods | ||
return ac.amino.UnmarshalJSON(bz, ptr) | ||
} | ||
|
||
func (ac *AminoCodec) MustUnmarshalJSON(bz []byte, ptr interface{}) { | ||
ac.amino.MustUnmarshalJSON(bz, ptr) | ||
} |
Oops, something went wrong.