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

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

View file

@ -82,3 +82,23 @@ func BearerTokenFromJSON(data []byte) (*BearerToken, error) {
return BearerTokenFromGRPCMessage(msg), nil
}
func (f *HeaderFilter) MarshalJSON() ([]byte, error) {
return protojson.MarshalOptions{
EmitUnpopulated: true,
}.Marshal(
HeaderFilterToGRPCMessage(f),
)
}
func (f *HeaderFilter) UnmarshalJSON(data []byte) error {
msg := new(acl.EACLRecord_Filter)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
*f = *HeaderFilterFromGRPCMessage(msg)
return nil
}