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

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

View file

@ -84,3 +84,23 @@ func (o *OwnerID) UnmarshalJSON(data []byte) error {
return nil
}
func (v *Version) MarshalJSON() ([]byte, error) {
return protojson.MarshalOptions{
EmitUnpopulated: true,
}.Marshal(
VersionToGRPCMessage(v),
)
}
func (v *Version) UnmarshalJSON(data []byte) error {
msg := new(refs.Version)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
*v = *VersionFromGRPCMessage(msg)
return nil
}