forked from TrueCloudLab/frostfs-api-go
[#168] refs: Implement binary/JSON encoders/decoders on Version
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
9ec57ee9f8
commit
1519a02d63
6 changed files with 103 additions and 4 deletions
|
@ -84,3 +84,23 @@ func (o *OwnerID) UnmarshalJSON(data []byte) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (v *Version) MarshalJSON() ([]byte, error) {
|
||||
return protojson.MarshalOptions{
|
||||
EmitUnpopulated: true,
|
||||
}.Marshal(
|
||||
VersionToGRPCMessage(v),
|
||||
)
|
||||
}
|
||||
|
||||
func (v *Version) UnmarshalJSON(data []byte) error {
|
||||
msg := new(refs.Version)
|
||||
|
||||
if err := protojson.Unmarshal(data, msg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*v = *VersionFromGRPCMessage(msg)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue