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

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-13 15:43:02 +03:00 committed by Alex Vanin
parent b8f86f1a60
commit 9cdd14841a
4 changed files with 66 additions and 5 deletions

View file

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