Fix SetMarshalData for PutSingle request #65
2 changed files with 7 additions and 6 deletions
|
@ -1111,17 +1111,13 @@ func (r *PutSingleRequestBody) StableMarshal(buf []byte) []byte {
|
||||||
|
|
||||||
// SetMarshalData sets marshal data to reduce memory allocations.
|
// SetMarshalData sets marshal data to reduce memory allocations.
|
||||||
//
|
//
|
||||||
// It is unsafe to modify request data after setting marshal data.
|
// It is unsafe to modify/copy request data after setting marshal data.
|
||||||
func (r *PutSingleRequestBody) SetMarshalData(data []byte) {
|
func (r *PutSingleRequestBody) SetMarshalData(data []byte) {
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if data == nil {
|
r.marshalData = data
|
||||||
r.marshalData = r.StableMarshal(nil)
|
|
||||||
} else {
|
|
||||||
r.marshalData = data
|
|
||||||
}
|
|
||||||
|
|
||||||
proto.NestedStructureSetMarshalData(putSingleReqObjectField, r.marshalData, r.object)
|
proto.NestedStructureSetMarshalData(putSingleReqObjectField, r.marshalData, r.object)
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,6 +287,11 @@ func NestedStructureSetMarshalData[T any, M setMarshalData[T]](field int64, pare
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if parentData == nil {
|
||||||
|
|||||||
|
v.SetMarshalData(nil)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
n := v.StableSize()
|
n := v.StableSize()
|
||||||
buf := make([]byte, binary.MaxVarintLen64)
|
buf := make([]byte, binary.MaxVarintLen64)
|
||||||
prefix := protowire.EncodeTag(protowire.Number(field), protowire.BytesType)
|
prefix := protowire.EncodeTag(protowire.Number(field), protowire.BytesType)
|
||||||
|
|
Loading…
Reference in a new issue
How is this related?
Now
r.marshalData
can benil
So if
parentData == nil
then we should reset nested marshalData