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

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-13 14:48:19 +03:00 committed by Alex Vanin
parent 9ddc4c1f48
commit ae68790bbd
5 changed files with 106 additions and 5 deletions

View file

@ -122,3 +122,23 @@ func (t *Target) UnmarshalJSON(data []byte) error {
return nil
}
func (r *Record) MarshalJSON() ([]byte, error) {
return protojson.MarshalOptions{
EmitUnpopulated: true,
}.Marshal(
RecordToGRPCMessage(r),
)
}
func (r *Record) UnmarshalJSON(data []byte) error {
msg := new(acl.EACLRecord)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
*r = *RecordFromGRPCMessage(msg)
return nil
}