forked from TrueCloudLab/frostfs-api-go
[#168] refs: Implement binary/JSON encoders/decoders on Checksum
Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
parent
4b55b06780
commit
93df2fd765
6 changed files with 112 additions and 6 deletions
|
@ -124,3 +124,23 @@ func (s *Signature) UnmarshalJSON(data []byte) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Checksum) MarshalJSON() ([]byte, error) {
|
||||
return protojson.MarshalOptions{
|
||||
EmitUnpopulated: true,
|
||||
}.Marshal(
|
||||
ChecksumToGRPCMessage(c),
|
||||
)
|
||||
}
|
||||
|
||||
func (c *Checksum) UnmarshalJSON(data []byte) error {
|
||||
msg := new(refs.Checksum)
|
||||
|
||||
if err := protojson.Unmarshal(data, msg); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*c = *ChecksumFromGRPCMessage(msg)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue