[#344] netmap: Add method Clone

Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
Anton Nikiforov 2025-03-07 13:59:38 +03:00
parent f70c0c9081
commit 749b4e9ab5
6 changed files with 141 additions and 0 deletions

View file

@ -1,6 +1,9 @@
package netmap
import (
"bytes"
"slices"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/refs"
"git.frostfs.info/TrueCloudLab/frostfs-sdk-go/api/session"
)
@ -382,6 +385,18 @@ func (a *Attribute) SetParents(parent []string) {
a.parents = parent
}
// Clone returns a copy of Attribute.
func (a *Attribute) Clone() *Attribute {
if a == nil {
return nil
}
return &Attribute{
parents: slices.Clone(a.parents),
value: a.value,
key: a.key,
}
}
func (ni *NodeInfo) GetPublicKey() []byte {
if ni != nil {
return ni.publicKey
@ -465,6 +480,23 @@ func (ni *NodeInfo) SetState(state NodeState) {
ni.state = state
}
// Clone returns a copy of NodeInfo.
func (ni *NodeInfo) Clone() *NodeInfo {
if ni == nil {
return nil
}
dst := NodeInfo{
addresses: slices.Clone(ni.addresses),
publicKey: bytes.Clone(ni.publicKey),
state: ni.state,
attributes: make([]Attribute, len(ni.attributes)),
}
for i, v := range ni.attributes {
dst.attributes[i] = *v.Clone()
}
return &dst
}
func (l *LocalNodeInfoResponseBody) GetVersion() *refs.Version {
if l != nil {
return l.version