[#168] client: Adopt replacement of pointer slices with struct slices

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2022-03-11 12:16:08 +03:00 committed by Alex Vanin
parent e89a0d88d2
commit 9c5d3d9dfa
7 changed files with 21 additions and 28 deletions

View file

@ -71,14 +71,11 @@ func (x *prmCommonMeta) WithXHeaders(hs ...string) {
func (x prmCommonMeta) writeToMetaHeader(h *v2session.RequestMetaHeader) {
if len(x.xHeaders) > 0 {
hs := make([]*v2session.XHeader, 0, len(x.xHeaders)/2)
hs := make([]v2session.XHeader, len(x.xHeaders)/2)
for i := 0; i < len(x.xHeaders); i += 2 {
var h v2session.XHeader
h.SetKey(x.xHeaders[i])
h.SetValue(x.xHeaders[i+1])
hs = append(hs, &h)
hs[i].SetKey(x.xHeaders[i])
hs[i].SetValue(x.xHeaders[i+1])
}
h.SetXHeaders(hs)

View file

@ -255,17 +255,17 @@ func (x *PrmContainerList) SetAccount(id owner.ID) {
type ResContainerList struct {
statusRes
ids []*cid.ID
ids []cid.ID
}
// Containers returns list of identifiers of the account-owned containers.
//
// Client doesn't retain value so modification is safe.
func (x ResContainerList) Containers() []*cid.ID {
func (x ResContainerList) Containers() []cid.ID {
return x.ids
}
func (x *ResContainerList) setContainers(ids []*cid.ID) {
func (x *ResContainerList) setContainers(ids []cid.ID) {
x.ids = ids
}
@ -319,10 +319,10 @@ func (c *Client) ContainerList(ctx context.Context, prm PrmContainerList) (*ResC
cc.result = func(r responseV2) {
resp := r.(*v2container.ListResponse)
ids := make([]*cid.ID, 0, len(resp.GetBody().GetContainerIDs()))
ids := make([]cid.ID, len(resp.GetBody().GetContainerIDs()))
for _, cidV2 := range resp.GetBody().GetContainerIDs() {
ids = append(ids, cid.NewFromV2(cidV2))
for i, cidV2 := range resp.GetBody().GetContainerIDs() {
ids[i] = *cid.NewFromV2(&cidV2)
}
res.setContainers(ids)
@ -695,9 +695,9 @@ func (c *Client) ContainerAnnounceUsedSpace(ctx context.Context, prm PrmAnnounce
}
// convert list of SDK announcement structures into NeoFS-API v2 list
v2announce := make([]*v2container.UsedSpaceAnnouncement, 0, len(prm.announcements))
v2announce := make([]v2container.UsedSpaceAnnouncement, len(prm.announcements))
for i := range prm.announcements {
v2announce = append(v2announce, prm.announcements[i].ToV2())
v2announce[i] = *prm.announcements[i].ToV2()
}
// prepare body of the NeoFS-API v2 request and request itself

View file

@ -71,10 +71,9 @@ func (x *PrmObjectHash) SetRangeList(r ...uint64) {
panic("odd number of range parameters")
}
rs := make([]*v2object.Range, ln/2)
rs := make([]v2object.Range, ln/2)
for i := 0; i < ln/2; i++ {
rs[i] = new(v2object.Range)
rs[i].SetOffset(r[2*i])
rs[i].SetLength(r[2*i+1])
}

View file

@ -95,7 +95,7 @@ type ObjectListReader struct {
// initially bound to contextCall
bodyResp v2object.SearchResponseBody
tail []*v2refs.ObjectID
tail []v2refs.ObjectID
}
// UseKey specifies private key to sign the requests.
@ -130,7 +130,7 @@ func (x *ObjectListReader) Read(buf []oid.ID) (int, bool) {
}
for i := 0; i < read; i++ {
buf[i] = *oid.NewIDFromV2(x.tail[i]) // need smth better
buf[i] = *oid.NewIDFromV2(&x.tail[i]) // need smth better
}
x.tail = x.tail[read:]
@ -140,7 +140,7 @@ func (x *ObjectListReader) Read(buf []oid.ID) (int, bool) {
}
var ok bool
var ids []*v2refs.ObjectID
var ids []v2refs.ObjectID
var i, ln, rem int
for {
@ -164,7 +164,7 @@ func (x *ObjectListReader) Read(buf []oid.ID) (int, bool) {
}
for i = 0; i < ln; i++ {
buf[read+i] = *oid.NewIDFromV2(ids[i]) // need smth better
buf[read+i] = *oid.NewIDFromV2(&ids[i]) // need smth better
}
read += ln

View file

@ -175,9 +175,9 @@ func testListReaderResponse(t *testing.T) (*ObjectListReader, func(id []oid.ID)
resp := new(object.SearchResponse)
resp.SetBody(new(object.SearchResponseBody))
v2id := make([]*refs.ObjectID, len(id))
v2id := make([]refs.ObjectID, len(id))
for i := range id {
v2id[i] = id[i].ToV2()
v2id[i] = *id[i].ToV2()
}
resp.GetBody().SetIDList(v2id)
err := signatureV2.SignServiceMessage(&p.PrivateKey, resp)

View file

@ -65,11 +65,8 @@ func (c *Client) AnnounceLocalTrust(ctx context.Context, prm PrmAnnounceLocalTru
reqBody := new(v2reputation.AnnounceLocalTrustRequestBody)
reqBody.SetEpoch(prm.epoch)
trusts := make([]*reputation.Trust, 0, len(prm.trusts))
for i := range prm.trusts {
trusts = append(trusts, &prm.trusts[i])
}
trusts := make([]reputation.Trust, len(prm.trusts))
copy(trusts, prm.trusts)
reqBody.SetTrusts(reputation.TrustsToV2(trusts))

View file

@ -99,7 +99,7 @@ func (x *WrongMagicNumber) WriteCorrectMagic(magic uint64) {
d.SetValue(buf)
// attach the detail
x.v2.AppendDetails(&d)
x.v2.AppendDetails(d)
}
// CorrectMagic returns network magic returned by the server.