[#168] acl: Implement binary/JSON encoders/decoders on Target

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-13 14:40:57 +03:00 committed by Alex Vanin
parent 7f42156201
commit 9ddc4c1f48
6 changed files with 127 additions and 4 deletions

View file

@ -102,3 +102,23 @@ func (f *HeaderFilter) UnmarshalJSON(data []byte) error {
return nil
}
func (t *Target) MarshalJSON() ([]byte, error) {
return protojson.MarshalOptions{
EmitUnpopulated: true,
}.Marshal(
TargetToGRPCMessage(t),
)
}
func (t *Target) UnmarshalJSON(data []byte) error {
msg := new(acl.EACLRecord_Target)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
*t = *TargetInfoFromGRPCMessage(msg)
return nil
}