diff --git a/consensus/types/peer_round_state.go b/consensus/types/peer_round_state.go index e42395bc3..16e292940 100644 --- a/consensus/types/peer_round_state.go +++ b/consensus/types/peer_round_state.go @@ -55,3 +55,31 @@ func (prs PeerRoundState) StringIndented(indent string) string { indent, prs.CatchupCommit, prs.CatchupCommitRound, indent) } + +//----------------------------------------------------------- +// These methods are for Protobuf Compatibility + +// Size returns the size of the amino encoding, in bytes. +func (ps *PeerRoundState) Size() int { + bs, _ := ps.Marshal() + return len(bs) +} + +// Marshal returns the amino encoding. +func (ps *PeerRoundState) Marshal() ([]byte, error) { + return cdc.MarshalBinaryBare(ps) +} + +// MarshalTo calls Marshal and copies to the given buffer. +func (ps *PeerRoundState) MarshalTo(data []byte) (int, error) { + bs, err := ps.Marshal() + if err != nil { + return -1, err + } + return copy(data, bs), nil +} + +// Unmarshal deserializes from amino encoded form. +func (ps *PeerRoundState) Unmarshal(bs []byte) error { + return cdc.UnmarshalBinaryBare(bs, ps) +} diff --git a/consensus/types/round_state.go b/consensus/types/round_state.go index 6359a6555..418f73a8e 100644 --- a/consensus/types/round_state.go +++ b/consensus/types/round_state.go @@ -201,3 +201,31 @@ func (rs *RoundState) StringShort() string { return fmt.Sprintf(`RoundState{H:%v R:%v S:%v ST:%v}`, rs.Height, rs.Round, rs.Step, rs.StartTime) } + +//----------------------------------------------------------- +// These methods are for Protobuf Compatibility + +// Size returns the size of the amino encoding, in bytes. +func (rs *RoundStateSimple) Size() int { + bs, _ := rs.Marshal() + return len(bs) +} + +// Marshal returns the amino encoding. +func (rs *RoundStateSimple) Marshal() ([]byte, error) { + return cdc.MarshalBinaryBare(rs) +} + +// MarshalTo calls Marshal and copies to the given buffer. +func (rs *RoundStateSimple) MarshalTo(data []byte) (int, error) { + bs, err := rs.Marshal() + if err != nil { + return -1, err + } + return copy(data, bs), nil +} + +// Unmarshal deserializes from amino encoded form. +func (rs *RoundStateSimple) Unmarshal(bs []byte) error { + return cdc.UnmarshalBinaryBare(bs, rs) +} diff --git a/p2p/node_info.go b/p2p/node_info.go index c36d98d9c..99daf7c43 100644 --- a/p2p/node_info.go +++ b/p2p/node_info.go @@ -230,3 +230,31 @@ func (info DefaultNodeInfo) NetAddress() *NetAddress { } return netAddr } + +//----------------------------------------------------------- +// These methods are for Protobuf Compatibility + +// Size returns the size of the amino encoding, in bytes. +func (info *DefaultNodeInfo) Size() int { + bs, _ := info.Marshal() + return len(bs) +} + +// Marshal returns the amino encoding. +func (info *DefaultNodeInfo) Marshal() ([]byte, error) { + return cdc.MarshalBinaryBare(info) +} + +// MarshalTo calls Marshal and copies to the given buffer. +func (info *DefaultNodeInfo) MarshalTo(data []byte) (int, error) { + bs, err := info.Marshal() + if err != nil { + return -1, err + } + return copy(data, bs), nil +} + +// Unmarshal deserializes from amino encoded form. +func (info *DefaultNodeInfo) Unmarshal(bs []byte) error { + return cdc.UnmarshalBinaryBare(bs, info) +} diff --git a/types/block.go b/types/block.go index b2cddb5e3..15b88d81d 100644 --- a/types/block.go +++ b/types/block.go @@ -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. diff --git a/types/block_meta.go b/types/block_meta.go index d8926af0b..8297446ab 100644 --- a/types/block_meta.go +++ b/types/block_meta.go @@ -13,3 +13,31 @@ func NewBlockMeta(block *Block, blockParts *PartSet) *BlockMeta { Header: block.Header, } } + +//----------------------------------------------------------- +// These methods are for Protobuf Compatibility + +// Size returns the size of the amino encoding, in bytes. +func (bm *BlockMeta) Size() int { + bs, _ := bm.Marshal() + return len(bs) +} + +// Marshal returns the amino encoding. +func (bm *BlockMeta) Marshal() ([]byte, error) { + return cdc.MarshalBinaryBare(bm) +} + +// MarshalTo calls Marshal and copies to the given buffer. +func (bm *BlockMeta) MarshalTo(data []byte) (int, error) { + bs, err := bm.Marshal() + if err != nil { + return -1, err + } + return copy(data, bs), nil +} + +// Unmarshal deserializes from amino encoded form. +func (bm *BlockMeta) Unmarshal(bs []byte) error { + return cdc.UnmarshalBinaryBare(bs, bm) +}