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

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2020-11-13 16:40:00 +03:00 committed by Alex Vanin
parent 93df2fd765
commit 86351a8f90
4 changed files with 61 additions and 4 deletions

26
v2/session/json.go Normal file
View file

@ -0,0 +1,26 @@
package session
import (
session "github.com/nspcc-dev/neofs-api-go/v2/session/grpc"
"google.golang.org/protobuf/encoding/protojson"
)
func (c *ObjectSessionContext) MarshalJSON() ([]byte, error) {
return protojson.MarshalOptions{
EmitUnpopulated: true,
}.Marshal(
ObjectSessionContextToGRPCMessage(c),
)
}
func (c *ObjectSessionContext) UnmarshalJSON(data []byte) error {
msg := new(session.ObjectSessionContext)
if err := protojson.Unmarshal(data, msg); err != nil {
return err
}
*c = *ObjectSessionContextFromGRPCMessage(msg)
return nil
}