[#168] object: Implement binary/JSON encoders/decoders on ShortHeader
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
a684da6118
commit
ce0d70fa02
4 changed files with 59 additions and 4 deletions
26
v2/object/json.go
Normal file
26
v2/object/json.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package object
|
||||
|
||||
import (
|
||||
object "github.com/nspcc-dev/neofs-api-go/v2/object/grpc"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
)
|
||||
|
||||
func (h *ShortHeader) MarshalJSON() ([]byte, error) {
|
||||
return protojson.MarshalOptions{
|
||||
EmitUnpopulated: true,
|
||||
}.Marshal(
|
||||
ShortHeaderToGRPCMessage(h),
|
||||
)
|
||||
}
|
||||
|
||||
func (h *ShortHeader) UnmarshalJSON(data []byte) error {
|
||||
msg := new(object.ShortHeader)
|
||||
|
||||
if err := protojson.Unmarshal(data, msg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*h = *ShortHeaderFromGRPCMessage(msg)
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue