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

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-13 16:23:41 +03:00 committed by Alex Vanin
parent 1519a02d63
commit 4b55b06780
6 changed files with 110 additions and 4 deletions

View file

@ -104,3 +104,23 @@ func (v *Version) UnmarshalJSON(data []byte) error {
return nil
}
func (s *Signature) MarshalJSON() ([]byte, error) {
return protojson.MarshalOptions{
EmitUnpopulated: true,
}.Marshal(
SignatureToGRPCMessage(s),
)
}
func (s *Signature) UnmarshalJSON(data []byte) error {
msg := new(refs.Signature)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
*s = *SignatureFromGRPCMessage(msg)
return nil
}