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

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-13 17:02:30 +03:00 committed by Alex Vanin
parent 7e3e9e1cba
commit 8f8e977a3e
4 changed files with 45 additions and 4 deletions

View file

@ -104,3 +104,23 @@ func (x *XHeader) UnmarshalJSON(data []byte) error {
return nil
}
func (r *RequestMetaHeader) MarshalJSON() ([]byte, error) {
return protojson.MarshalOptions{
EmitUnpopulated: true,
}.Marshal(
RequestMetaHeaderToGRPCMessage(r),
)
}
func (r *RequestMetaHeader) UnmarshalJSON(data []byte) error {
msg := new(session.RequestMetaHeader)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
*r = *RequestMetaHeaderFromGRPCMessage(msg)
return nil
}