[#168] container: Implement binary/JSON encoders/decoders on Attribute

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-13 15:14:39 +03:00 committed by Alex Vanin
parent ec957be60c
commit bc5d9dcce5
4 changed files with 92 additions and 49 deletions

View file

@ -34,3 +34,23 @@ func ContainerFromJSON(data []byte) (*Container, error) {
return ContainerFromGRPCMessage(msg), nil
}
func (a *Attribute) MarshalJSON() ([]byte, error) {
return protojson.MarshalOptions{
EmitUnpopulated: true,
}.Marshal(
AttributeToGRPCMessage(a),
)
}
func (a *Attribute) UnmarshalJSON(data []byte) error {
msg := new(container.Container_Attribute)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
*a = *AttributeFromGRPCMessage(msg)
return nil
}