[#376] session: Make XHeader slice non-pointer

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-03-02 11:01:03 +03:00 committed by Alex Vanin
parent 6f4908edc2
commit e21a7823c5
4 changed files with 18 additions and 24 deletions

View file

@ -207,7 +207,7 @@ func (x *XHeader) FromGRPCMessage(m grpc.Message) error {
return nil
}
func XHeadersToGRPC(xs []*XHeader) (res []*session.XHeader) {
func XHeadersToGRPC(xs []XHeader) (res []*session.XHeader) {
if xs != nil {
res = make([]*session.XHeader, 0, len(xs))
@ -219,23 +219,17 @@ func XHeadersToGRPC(xs []*XHeader) (res []*session.XHeader) {
return
}
func XHeadersFromGRPC(xs []*session.XHeader) (res []*XHeader, err error) {
func XHeadersFromGRPC(xs []*session.XHeader) (res []XHeader, err error) {
if xs != nil {
res = make([]*XHeader, 0, len(xs))
res = make([]XHeader, len(xs))
for i := range xs {
var x *XHeader
if xs[i] != nil {
x = new(XHeader)
err = x.FromGRPCMessage(xs[i])
err = res[i].FromGRPCMessage(xs[i])
if err != nil {
return
}
}
res = append(res, x)
}
}

View file

@ -543,7 +543,7 @@ func (r *RequestMetaHeader) StableMarshal(buf []byte) ([]byte, error) {
offset += n
for i := range r.xHeaders {
n, err = proto.NestedStructureMarshal(reqMetaHeaderXHeadersField, buf[offset:], r.xHeaders[i])
n, err = proto.NestedStructureMarshal(reqMetaHeaderXHeadersField, buf[offset:], &r.xHeaders[i])
if err != nil {
return nil, err
}
@ -593,7 +593,7 @@ func (r *RequestMetaHeader) StableSize() (size int) {
size += proto.UInt32Size(reqMetaHeaderTTLField, r.ttl)
for i := range r.xHeaders {
size += proto.NestedStructureSize(reqMetaHeaderXHeadersField, r.xHeaders[i])
size += proto.NestedStructureSize(reqMetaHeaderXHeadersField, &r.xHeaders[i])
}
size += proto.NestedStructureSize(reqMetaHeaderSessionTokenField, r.sessionToken)
@ -714,7 +714,7 @@ func (r *ResponseMetaHeader) StableMarshal(buf []byte) ([]byte, error) {
offset += n
for i := range r.xHeaders {
n, err = proto.NestedStructureMarshal(respMetaHeaderXHeadersField, buf[offset:], r.xHeaders[i])
n, err = proto.NestedStructureMarshal(respMetaHeaderXHeadersField, buf[offset:], &r.xHeaders[i])
if err != nil {
return nil, err
}
@ -750,7 +750,7 @@ func (r *ResponseMetaHeader) StableSize() (size int) {
size += proto.UInt32Size(respMetaHeaderTTLField, r.ttl)
for i := range r.xHeaders {
size += proto.NestedStructureSize(respMetaHeaderXHeadersField, r.xHeaders[i])
size += proto.NestedStructureSize(respMetaHeaderXHeadersField, &r.xHeaders[i])
}
size += proto.NestedStructureSize(respMetaHeaderOriginField, r.origin)

View file

@ -217,13 +217,13 @@ func GenerateXHeader(empty bool) *session.XHeader {
return m
}
func GenerateXHeaders(empty bool) []*session.XHeader {
var xs []*session.XHeader
func GenerateXHeaders(empty bool) []session.XHeader {
var xs []session.XHeader
if !empty {
xs = append(xs,
GenerateXHeader(false),
GenerateXHeader(false),
*GenerateXHeader(false),
*GenerateXHeader(false),
)
}

View file

@ -93,7 +93,7 @@ type RequestMetaHeader struct {
epoch uint64
xHeaders []*XHeader
xHeaders []XHeader
sessionToken *Token
@ -117,7 +117,7 @@ type ResponseMetaHeader struct {
epoch uint64
xHeaders []*XHeader
xHeaders []XHeader
origin *ResponseMetaHeader
@ -401,7 +401,7 @@ func (r *RequestMetaHeader) SetEpoch(v uint64) {
}
}
func (r *RequestMetaHeader) GetXHeaders() []*XHeader {
func (r *RequestMetaHeader) GetXHeaders() []XHeader {
if r != nil {
return r.xHeaders
}
@ -409,7 +409,7 @@ func (r *RequestMetaHeader) GetXHeaders() []*XHeader {
return nil
}
func (r *RequestMetaHeader) SetXHeaders(v []*XHeader) {
func (r *RequestMetaHeader) SetXHeaders(v []XHeader) {
if r != nil {
r.xHeaders = v
}
@ -613,7 +613,7 @@ func (r *ResponseMetaHeader) SetEpoch(v uint64) {
}
}
func (r *ResponseMetaHeader) GetXHeaders() []*XHeader {
func (r *ResponseMetaHeader) GetXHeaders() []XHeader {
if r != nil {
return r.xHeaders
}
@ -621,7 +621,7 @@ func (r *ResponseMetaHeader) GetXHeaders() []*XHeader {
return nil
}
func (r *ResponseMetaHeader) SetXHeaders(v []*XHeader) {
func (r *ResponseMetaHeader) SetXHeaders(v []XHeader) {
if r != nil {
r.xHeaders = v
}