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

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-13 15:00:03 +03:00 committed by Alex Vanin
parent 233756ca8f
commit 0f4d5d5f1e
4 changed files with 45 additions and 4 deletions

View file

@ -114,3 +114,23 @@ func (t *Table) UnmarshalJSON(data []byte) error {
return nil
}
func (l *TokenLifetime) MarshalJSON() ([]byte, error) {
return protojson.MarshalOptions{
EmitUnpopulated: true,
}.Marshal(
TokenLifetimeToGRPCMessage(l),
)
}
func (l *TokenLifetime) UnmarshalJSON(data []byte) error {
msg := new(acl.BearerToken_Body_TokenLifetime)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
*l = *TokenLifetimeFromGRPCMessage(msg)
return nil
}