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

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

View file

@ -64,3 +64,23 @@ func (c *ContainerID) UnmarshalJSON(data []byte) error {
return nil
}
func (o *OwnerID) MarshalJSON() ([]byte, error) {
return protojson.MarshalOptions{
EmitUnpopulated: true,
}.Marshal(
OwnerIDToGRPCMessage(o),
)
}
func (o *OwnerID) UnmarshalJSON(data []byte) error {
msg := new(refs.OwnerID)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
*o = *OwnerIDFromGRPCMessage(msg)
return nil
}