forked from TrueCloudLab/frostfs-api-go
[#168] storageGroup: Implement binary/JSON encoders/decoders on SG
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
6456fcf8fa
commit
55948c2ab1
4 changed files with 79 additions and 18 deletions
26
v2/storagegroup/json.go
Normal file
26
v2/storagegroup/json.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package storagegroup
|
||||
|
||||
import (
|
||||
storagegroup "github.com/nspcc-dev/neofs-api-go/v2/storagegroup/grpc"
|
||||
"google.golang.org/protobuf/encoding/protojson"
|
||||
)
|
||||
|
||||
func (s *StorageGroup) MarshalJSON() ([]byte, error) {
|
||||
return protojson.MarshalOptions{
|
||||
EmitUnpopulated: true,
|
||||
}.Marshal(
|
||||
StorageGroupToGRPCMessage(s),
|
||||
)
|
||||
}
|
||||
|
||||
func (s *StorageGroup) UnmarshalJSON(data []byte) error {
|
||||
msg := new(storagegroup.StorageGroup)
|
||||
|
||||
if err := protojson.Unmarshal(data, msg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*s = *StorageGroupFromGRPCMessage(msg)
|
||||
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue