[#168] session: Implement binary/JSON encoders/decoders on XHeader

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-13 16:58:08 +03:00 committed by Alex Vanin
parent 85d4713348
commit 7e3e9e1cba
4 changed files with 45 additions and 4 deletions

View file

@ -84,3 +84,23 @@ func (t *SessionToken) UnmarshalJSON(data []byte) error {
return nil
}
func (x *XHeader) MarshalJSON() ([]byte, error) {
return protojson.MarshalOptions{
EmitUnpopulated: true,
}.Marshal(
XHeaderToGRPCMessage(x),
)
}
func (x *XHeader) UnmarshalJSON(data []byte) error {
msg := new(session.XHeader)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
*x = *XHeaderFromGRPCMessage(msg)
return nil
}