-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
What version of protobuf and what language are you using?
Version: v1.5.2
What did you do?
Please provide the context of your code usage.
type RoleData struct {
Dogs []int
}
roleData:= make([]int, 3)
proto.UnmarshalOptions{Merge: true}.Unmarshal(bin, roleData)
The variable bin contains a slice variable named dogs with a length of 4.
What did you expect to see?
During usage, my expectation was that the length of my roleData's sliceList would still be 4 after Unmarshal, but in reality it became 7.
What did you see instead?
By examining the source code(proto/decode_gen.go.219), it was found that the append operation is causing the length of roleData to increase from 3. This inner situation is completely unknown to the user. In fact, when the user uses merge , they only want to merge the variable values in roleData into bin , and ultimately the bin value should be the primary data, not the append operation changing the length of the final slice. This point is very important.
Anything else we should know about your project / environment?