[#168] object: Implement binary/JSON encoders/decoders on Header

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-13 15:38:55 +03:00 committed by Alex Vanin
parent 78374caa41
commit b8f86f1a60
4 changed files with 45 additions and 5 deletions

View file

@ -64,3 +64,23 @@ func (h *SplitHeader) UnmarshalJSON(data []byte) error {
return nil
}
func (h *Header) MarshalJSON() ([]byte, error) {
return protojson.MarshalOptions{
EmitUnpopulated: true,
}.Marshal(
HeaderToGRPCMessage(h),
)
}
func (h *Header) UnmarshalJSON(data []byte) error {
msg := new(object.Header)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
*h = *HeaderFromGRPCMessage(msg)
return nil
}