[#170] checksum: Do not use pointers

Do not return pointers from getters. Do not pass pointers to the methods
that does not modify the checksum. Add `Empty` method.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-03-04 14:38:23 +03:00 committed by LeL
parent fd13e61266
commit caa055236b
7 changed files with 53 additions and 35 deletions

View file

@ -200,19 +200,26 @@ func (o *Object) SetCreationEpoch(v uint64) {
}
// PayloadChecksum returns checksum of the object payload.
func (o *Object) PayloadChecksum() *checksum.Checksum {
//
// Zero Object has zero checksum.
//
// See also SetPayloadChecksum.
func (o *Object) PayloadChecksum() checksum.Checksum {
var v checksum.Checksum
v.ReadFromV2(
*(*object.Object)(o).
GetHeader().
GetPayloadHash(),
)
v2 := (*object.Object)(o)
return &v
if hash := v2.GetHeader().GetPayloadHash(); hash != nil {
v.ReadFromV2(*hash)
}
return v
}
// SetPayloadChecksum sets checksum of the object payload.
func (o *Object) SetPayloadChecksum(v *checksum.Checksum) {
// Checksum must not be nil.
//
// See also PayloadChecksum.
func (o *Object) SetPayloadChecksum(v checksum.Checksum) {
var v2 refs.Checksum
v.WriteToV2(&v2)
@ -222,19 +229,26 @@ func (o *Object) SetPayloadChecksum(v *checksum.Checksum) {
}
// PayloadHomomorphicHash returns homomorphic hash of the object payload.
func (o *Object) PayloadHomomorphicHash() *checksum.Checksum {
//
// Zero Object has zero checksum.
//
// See also SetPayloadHomomorphicHash.
func (o *Object) PayloadHomomorphicHash() checksum.Checksum {
var v checksum.Checksum
v.ReadFromV2(
*(*object.Object)(o).
GetHeader().
GetHomomorphicHash(),
)
v2 := (*object.Object)(o)
return &v
if hash := v2.GetHeader().GetHomomorphicHash(); hash != nil {
v.ReadFromV2(*hash)
}
return v
}
// SetPayloadHomomorphicHash sets homomorphic hash of the object payload.
func (o *Object) SetPayloadHomomorphicHash(v *checksum.Checksum) {
// Checksum must not be nil.
//
// See also PayloadHomomorphicHash.
func (o *Object) SetPayloadHomomorphicHash(v checksum.Checksum) {
var v2 refs.Checksum
v.WriteToV2(&v2)