Open
Description
Generated messages have mutexes and other variables that make it dangerous to shallow copy.
Add a function to the proto
package that does the equivalent of a shallow copy in a safe way.
The function would semantically equivalent to:
func ShallowCopy(dst, src proto.Message) {
dm := dst.ProtoReflect()
sm := src.Protoreflect()
if dm.Type() != sm.Type() {
panic("mismatching type")
}
proto.Reset(dst)
sm.Range(func(fd protoreflect.FieldDescriptor, v protoreflect.Value) bool {
dm.Set(fd, v)
return true
})
}
but be optimized for performance.