diff --git a/session/convert.go b/session/convert.go index 200e2274..d7662b4d 100644 --- a/session/convert.go +++ b/session/convert.go @@ -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) } } diff --git a/session/marshal.go b/session/marshal.go index dbaf367d..a57d1a5c 100644 --- a/session/marshal.go +++ b/session/marshal.go @@ -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) diff --git a/session/test/generate.go b/session/test/generate.go index 537240ae..be7cd5fc 100644 --- a/session/test/generate.go +++ b/session/test/generate.go @@ -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), ) } diff --git a/session/types.go b/session/types.go index e41b5a9b..65f47285 100644 --- a/session/types.go +++ b/session/types.go @@ -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 }