codec: Rename codec and marshaler interfaces (#9226)

* codec: Rename codec and marshaler interfaces, ref: 8413

* codec: remove BinaryBare

* changelog update

* Update comments and documentation

* adding doc string comments

* Update CHANGELOG.md

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update codec/codec.go

Co-authored-by: Marko <marbar3778@yahoo.com>

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
Co-authored-by: Marko <marbar3778@yahoo.com>
This commit is contained in:
Robert Zaremba
2021-04-29 10:46:22 +00:00
committed by GitHub
co-authored by Federico Kunze Marko Amaury
parent c94e9eb1bb
commit be4a965599
162 changed files with 824 additions and 621 deletions
+5 -5
View File
@@ -59,8 +59,8 @@ Where there is no protobuf-based type definition for a module (see below), Amino
is used to encode and decode raw wire bytes to the concrete type or interface:
```go
bz := keeper.cdc.MustMarshalBinaryBare(typeOrInterface)
keeper.cdc.MustUnmarshalBinaryBare(bz, &typeOrInterface)
bz := keeper.cdc.MustMarshal(typeOrInterface)
keeper.cdc.MustUnmarshal(bz, &typeOrInterface)
```
Note, there are length-prefixed variants of the above functionality and this is
@@ -150,7 +150,7 @@ profile := Profile {
}
// We can then marshal the profile as usual.
bz, err := cdc.MarshalBinaryBare(profile)
bz, err := cdc.Marshal(profile)
jsonBz, err := cdc.MarshalJSON(profile)
```
@@ -162,7 +162,7 @@ The reverse operation of retrieving the concrete Go type from inside an `Any`, c
profileBz := ... // The proto-encoded bytes of a Profile, e.g. retrieved through gRPC.
var myProfile Profile
// Unmarshal the bytes into the myProfile struct.
err := cdc.UnmarshalBinaryBare(profilebz, &myProfile)
err := cdc.Unmarshal(profilebz, &myProfile)
// Let's see the types of the Account field.
fmt.Printf("%T\n", myProfile.Account) // Prints "Any"
@@ -241,7 +241,7 @@ message MsgSubmitEvidence {
}
```
The SDK `codec.Marshaler` interface provides support methods `MarshalInterface` and `UnmarshalInterface` to easy encoding of state to `Any`.
The SDK `codec.Codec` interface provides support methods `MarshalInterface` and `UnmarshalInterface` to easy encoding of state to `Any`.
Module should register interfaces using `InterfaceRegistry` which provides a mechanism for registering interfaces: `RegisterInterface(protoName string, iface interface{})` and implementations: `RegisterImplementations(iface interface{}, impls ...proto.Message)` that can be safely unpacked from Any, similarly to type registration with Amino: