forked from TrueCloudLab/frostfs-api-go
[#168] session: Implement binary/JSON encoders/decoders on SessionContext
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
93df2fd765
commit
86351a8f90
4 changed files with 61 additions and 4 deletions
26
v2/session/json.go
Normal file
26
v2/session/json.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue