@@ -41,6 +41,31 @@ import (
41
41
// Converting to/from a Value and a concrete Go value panics on type mismatch.
42
42
// For example, ValueOf("hello").Int() panics because this attempts to
43
43
// retrieve an int64 from a string.
44
+ //
45
+ // List, Map, and Message Values are called "composite" values.
46
+ //
47
+ // A composite Value may alias (reference) memory at some location,
48
+ // such that changes to the Value updates the that location.
49
+ // A composite value acquired with a Mutable method, such as Message.Mutable,
50
+ // always references the source object.
51
+ //
52
+ // For example:
53
+ // // Append a 0 to a "repeated int32" field.
54
+ // // Since the Value returned by Mutable is guaranteed to alias
55
+ // // the source message, modifying the Value modifies the message.
56
+ // message.Mutable(fieldDesc).(List).Append(protoreflect.ValueOfInt32(0))
57
+ //
58
+ // // Assign [0] to a "repeated int32" field by creating a new Value,
59
+ // // modifying it, and assigning it.
60
+ // list := message.NewField(fieldDesc).(List)
61
+ // list.Append(protoreflect.ValueOfInt32(0))
62
+ // message.Set(fieldDesc, list)
63
+ // // ERROR: Since it is not defined whether Set aliases the source,
64
+ // // appending to the List here may or may not modify the message.
65
+ // list.Append(protoreflect.ValueOfInt32(0))
66
+ //
67
+ // Some operations, such as Message.Get, may return an "empty, read-only"
68
+ // composite Value. Modifying an empty, read-only value panics.
44
69
type Value value
45
70
46
71
// The protoreflect API uses a custom Value union type instead of interface{}
0 commit comments