Updated Marshal and unmarshal methods to make compatible with protobuf (#2918)

* upadtes in grpc Marshal and unmarshal

* update comments
This commit is contained in:
nagarajmanjunath
2018-11-27 21:07:20 +08:00
committed by Ethan Buchman
parent 94e63be922
commit bef39f3346
5 changed files with 134 additions and 0 deletions

View File

@@ -275,6 +275,28 @@ func (b *Block) StringShort() string {
return fmt.Sprintf("Block#%v", b.Hash())
}
//-----------------------------------------------------------
// These methods are for Protobuf Compatibility
// Marshal returns the amino encoding.
func (b *Block) Marshal() ([]byte, error) {
return cdc.MarshalBinaryBare(b)
}
// MarshalTo calls Marshal and copies to the given buffer.
func (b *Block) MarshalTo(data []byte) (int, error) {
bs, err := b.Marshal()
if err != nil {
return -1, err
}
return copy(data, bs), nil
}
// Unmarshal deserializes from amino encoded form.
func (b *Block) Unmarshal(bs []byte) error {
return cdc.UnmarshalBinaryBare(bs, b)
}
//-----------------------------------------------------------------------------
// MaxDataBytes returns the maximum size of block's data.