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

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

View file

@ -44,3 +44,23 @@ func (a *Attribute) UnmarshalJSON(data []byte) error {
return nil
}
func (h *SplitHeader) MarshalJSON() ([]byte, error) {
return protojson.MarshalOptions{
EmitUnpopulated: true,
}.Marshal(
SplitHeaderToGRPCMessage(h),
)
}
func (h *SplitHeader) UnmarshalJSON(data []byte) error {
msg := new(object.Header_Split)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
*h = *SplitHeaderFromGRPCMessage(msg)
return nil
}