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