tendermint / go-amino

Protobuf3 with Interface support - Designed for blockchains (deterministic, upgradeable, fast, and compact)
Other
260 stars 84 forks source link

Add MarshalBinary/UnmarshalBinary interface support #300

Open jordaaash opened 4 years ago

jordaaash commented 4 years ago

This PR provides a mechanism to completely override the Amino encoding of a type by implementing the BinaryMarshaler and BinaryUnmarshaler interfaces.

Amino prefix bytes will still be prepended. Implementing MarshalAmino/UnmarshalAmino is not required. This should unblock https://github.com/tendermint/tendermint/pull/4245

jaekwon commented 4 years ago

Relevant: https://github.com/tendermint/go-amino/issues/301 - "The binary and json were intentionally written to mirror the code structure, so this kind of translation is easy."

Given the current impl, the divergence in JSON hints at divergence in function, whereby this optimization doesn't work for embedded structs (whereas such does work for json). In #301 what I want to convey is that we should continue to maintain code structure parity between binary and json, so that we solve common issues for both and reduce potential bugs. Once the implementations diverge, it will become difficult or impossible to keep in sync.

Anyways, great case study; thank you for the PR.