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

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-13 16:07:32 +03:00 committed by Alex Vanin
parent 7289ff6c64
commit c0f3ac51d4
6 changed files with 103 additions and 4 deletions

View file

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