[#376] status: Remove pointer from Detail slice

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-03-02 11:43:54 +03:00 committed by Alex Vanin
parent 0cab407378
commit 43fd3cfb4f
5 changed files with 14 additions and 20 deletions

View file

@ -67,7 +67,7 @@ func WriteAccessDeniedDesc(st *status.Status, desc string) {
d.SetID(detailAccessDeniedDesc)
d.SetValue([]byte(desc))
st.AppendDetails(&d)
st.AppendDetails(d)
}
}

View file

@ -71,27 +71,21 @@ func (x *Status) FromGRPCMessage(m grpc.Message) error {
}
var (
ds []*Detail
ds []Detail
dsV2 = v.GetDetails()
)
if dsV2 != nil {
ln := len(dsV2)
ds = make([]*Detail, 0, ln)
ds = make([]Detail, ln)
for i := 0; i < ln; i++ {
var p *Detail
if dsV2[i] != nil {
p = new(Detail)
if err := p.FromGRPCMessage(dsV2[i]); err != nil {
if err := ds[i].FromGRPCMessage(dsV2[i]); err != nil {
return err
}
}
ds = append(ds, p)
}
}

View file

@ -88,7 +88,7 @@ func (x *Status) StableMarshal(buf []byte) ([]byte, error) {
offset += n
for i := range x.details {
n, err = protoutil.NestedStructureMarshal(statusDetailsFNum, buf[offset:], x.details[i])
n, err = protoutil.NestedStructureMarshal(statusDetailsFNum, buf[offset:], &x.details[i])
if err != nil {
return nil, err
}
@ -104,7 +104,7 @@ func (x *Status) StableSize() (size int) {
size += protoutil.StringSize(statusMsgFNum, x.msg)
for i := range x.details {
size += protoutil.NestedStructureSize(statusDetailsFNum, x.details[i])
size += protoutil.NestedStructureSize(statusDetailsFNum, &x.details[i])
}
return size

View file

@ -17,13 +17,13 @@ func Detail(empty bool) *status.Detail {
}
// Details returns several status.Detail messages filled with static random values.
func Details(empty bool) []*status.Detail {
var res []*status.Detail
func Details(empty bool) []status.Detail {
var res []status.Detail
if !empty {
res = append(res,
Detail(false),
Detail(false),
*Detail(false),
*Detail(false),
)
}

View file

@ -53,7 +53,7 @@ type Status struct {
msg string
details []*Detail
details []Detail
}
// Code returns code of the Status.
@ -104,7 +104,7 @@ func (x *Status) NumberOfDetails() int {
func (x *Status) IterateDetails(f func(*Detail) bool) {
if x != nil {
for i := range x.details {
if f(x.details[i]) {
if f(&x.details[i]) {
break
}
}
@ -119,14 +119,14 @@ func (x *Status) ResetDetails() {
}
// AppendDetails appends the list of details to the Status.
func (x *Status) AppendDetails(ds ...*Detail) {
func (x *Status) AppendDetails(ds ...Detail) {
if x != nil {
x.details = append(x.details, ds...)
}
}
// SetStatusDetails sets Detail list of the Status.
func SetStatusDetails(dst *Status, ds []*Detail) {
func SetStatusDetails(dst *Status, ds []Detail) {
dst.ResetDetails()
dst.AppendDetails(ds...)
}