[#168] refs: Implement binary/JSON encoders/decoders on Checksum

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-13 16:30:35 +03:00 committed by Alex Vanin
parent 4b55b06780
commit 93df2fd765
6 changed files with 112 additions and 6 deletions

View file

@ -124,3 +124,23 @@ func (s *Signature) UnmarshalJSON(data []byte) error {
return nil
}
func (c *Checksum) MarshalJSON() ([]byte, error) {
return protojson.MarshalOptions{
EmitUnpopulated: true,
}.Marshal(
ChecksumToGRPCMessage(c),
)
}
func (c *Checksum) UnmarshalJSON(data []byte) error {
msg := new(refs.Checksum)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
*c = *ChecksumFromGRPCMessage(msg)
return nil
}