Skip to content

About the suggestion for the append operation in the unmarshalList function. #1550

@EddieChan1993

Description

@EddieChan1993

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions