mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-17 01:12:51 +00:00
2cdb23da01
Most usages extensions are only for fields that have a singular message as the type. In such a sitation, the Go type and constructors are determined by the provided protoreflect.MessageType and is certainly what the user wanted. Custom extensions constructors are mainly useful if the user wants to use their own type to represent repeated fields. For example, we use *[]T to represent repeated fields, while a user may want to use their own opaque type. However, this is such a niche use-case that it is not worth supporting given that there is a workaround: type MyExtensionType struct { protoreflect.ExtensionType } func (x MyExtensionType) GoNew() interface{} { ... // return my custom value } func (x MyExtensionType) GoType() reflect.Type { ... // return my custom type } func (x MyExtensionType) ValueOf(v interface{}) protoreflect.Value { ... // convert my custom type to a protoreflect.Value } func (x MyExtensionType) InterfaceOf(v protoreflect.Value) interface{} { ... // convert a protoreflect.Value to my custom type } Change-Id: Iafc838b1c95b0ffc8583461ee9eb327bd3ce9c3c Reviewed-on: https://go-review.googlesource.com/c/148820 Reviewed-by: Herbie Ong <herbie@google.com> |
||
---|---|---|
.. | ||
protoreflect | ||
protoregistry | ||
prototype |