summaryrefslogtreecommitdiffstats
path: root/vendor/google.golang.org/protobuf/reflect/protoreflect
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/google.golang.org/protobuf/reflect/protoreflect')
-rw-r--r--vendor/google.golang.org/protobuf/reflect/protoreflect/source.go84
-rw-r--r--vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go461
-rw-r--r--vendor/google.golang.org/protobuf/reflect/protoreflect/type.go34
3 files changed, 575 insertions, 4 deletions
diff --git a/vendor/google.golang.org/protobuf/reflect/protoreflect/source.go b/vendor/google.golang.org/protobuf/reflect/protoreflect/source.go
index 32ea3d98..121ba3a0 100644
--- a/vendor/google.golang.org/protobuf/reflect/protoreflect/source.go
+++ b/vendor/google.golang.org/protobuf/reflect/protoreflect/source.go
@@ -4,6 +4,10 @@
package protoreflect
+import (
+ "strconv"
+)
+
// SourceLocations is a list of source locations.
type SourceLocations interface {
// Len reports the number of source locations in the proto file.
@@ -11,9 +15,20 @@ type SourceLocations interface {
// Get returns the ith SourceLocation. It panics if out of bounds.
Get(int) SourceLocation
- doNotImplement
+ // ByPath returns the SourceLocation for the given path,
+ // returning the first location if multiple exist for the same path.
+ // If multiple locations exist for the same path,
+ // then SourceLocation.Next index can be used to identify the
+ // index of the next SourceLocation.
+ // If no location exists for this path, it returns the zero value.
+ ByPath(path SourcePath) SourceLocation
- // TODO: Add ByPath and ByDescriptor helper methods.
+ // ByDescriptor returns the SourceLocation for the given descriptor,
+ // returning the first location if multiple exist for the same path.
+ // If no location exists for this descriptor, it returns the zero value.
+ ByDescriptor(desc Descriptor) SourceLocation
+
+ doNotImplement
}
// SourceLocation describes a source location and
@@ -39,6 +54,10 @@ type SourceLocation struct {
LeadingComments string
// TrailingComments is the trailing attached comment for the declaration.
TrailingComments string
+
+ // Next is an index into SourceLocations for the next source location that
+ // has the same Path. It is zero if there is no next location.
+ Next int
}
// SourcePath identifies part of a file descriptor for a source location.
@@ -48,5 +67,62 @@ type SourceLocation struct {
// See google.protobuf.SourceCodeInfo.Location.path.
type SourcePath []int32
-// TODO: Add SourcePath.String method to pretty-print the path. For example:
-// ".message_type[6].nested_type[15].field[3]"
+// Equal reports whether p1 equals p2.
+func (p1 SourcePath) Equal(p2 SourcePath) bool {
+ if len(p1) != len(p2) {
+ return false
+ }
+ for i := range p1 {
+ if p1[i] != p2[i] {
+ return false
+ }
+ }
+ return true
+}
+
+// String formats the path in a humanly readable manner.
+// The output is guaranteed to be deterministic,
+// making it suitable for use as a key into a Go map.
+// It is not guaranteed to be stable as the exact output could change
+// in a future version of this module.
+//
+// Example output:
+// .message_type[6].nested_type[15].field[3]
+func (p SourcePath) String() string {
+ b := p.appendFileDescriptorProto(nil)
+ for _, i := range p {
+ b = append(b, '.')
+ b = strconv.AppendInt(b, int64(i), 10)
+ }
+ return string(b)
+}
+
+type appendFunc func(*SourcePath, []byte) []byte
+
+func (p *SourcePath) appendSingularField(b []byte, name string, f appendFunc) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ b = append(b, '.')
+ b = append(b, name...)
+ *p = (*p)[1:]
+ if f != nil {
+ b = f(p, b)
+ }
+ return b
+}
+
+func (p *SourcePath) appendRepeatedField(b []byte, name string, f appendFunc) []byte {
+ b = p.appendSingularField(b, name, nil)
+ if len(*p) == 0 || (*p)[0] < 0 {
+ return b
+ }
+ b = append(b, '[')
+ b = strconv.AppendUint(b, uint64((*p)[0]), 10)
+ b = append(b, ']')
+ *p = (*p)[1:]
+ if f != nil {
+ b = f(p, b)
+ }
+ return b
+}
diff --git a/vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go b/vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go
new file mode 100644
index 00000000..b03c1223
--- /dev/null
+++ b/vendor/google.golang.org/protobuf/reflect/protoreflect/source_gen.go
@@ -0,0 +1,461 @@
+// Copyright 2019 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Code generated by generate-protos. DO NOT EDIT.
+
+package protoreflect
+
+func (p *SourcePath) appendFileDescriptorProto(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 1:
+ b = p.appendSingularField(b, "name", nil)
+ case 2:
+ b = p.appendSingularField(b, "package", nil)
+ case 3:
+ b = p.appendRepeatedField(b, "dependency", nil)
+ case 10:
+ b = p.appendRepeatedField(b, "public_dependency", nil)
+ case 11:
+ b = p.appendRepeatedField(b, "weak_dependency", nil)
+ case 4:
+ b = p.appendRepeatedField(b, "message_type", (*SourcePath).appendDescriptorProto)
+ case 5:
+ b = p.appendRepeatedField(b, "enum_type", (*SourcePath).appendEnumDescriptorProto)
+ case 6:
+ b = p.appendRepeatedField(b, "service", (*SourcePath).appendServiceDescriptorProto)
+ case 7:
+ b = p.appendRepeatedField(b, "extension", (*SourcePath).appendFieldDescriptorProto)
+ case 8:
+ b = p.appendSingularField(b, "options", (*SourcePath).appendFileOptions)
+ case 9:
+ b = p.appendSingularField(b, "source_code_info", (*SourcePath).appendSourceCodeInfo)
+ case 12:
+ b = p.appendSingularField(b, "syntax", nil)
+ }
+ return b
+}
+
+func (p *SourcePath) appendDescriptorProto(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 1:
+ b = p.appendSingularField(b, "name", nil)
+ case 2:
+ b = p.appendRepeatedField(b, "field", (*SourcePath).appendFieldDescriptorProto)
+ case 6:
+ b = p.appendRepeatedField(b, "extension", (*SourcePath).appendFieldDescriptorProto)
+ case 3:
+ b = p.appendRepeatedField(b, "nested_type", (*SourcePath).appendDescriptorProto)
+ case 4:
+ b = p.appendRepeatedField(b, "enum_type", (*SourcePath).appendEnumDescriptorProto)
+ case 5:
+ b = p.appendRepeatedField(b, "extension_range", (*SourcePath).appendDescriptorProto_ExtensionRange)
+ case 8:
+ b = p.appendRepeatedField(b, "oneof_decl", (*SourcePath).appendOneofDescriptorProto)
+ case 7:
+ b = p.appendSingularField(b, "options", (*SourcePath).appendMessageOptions)
+ case 9:
+ b = p.appendRepeatedField(b, "reserved_range", (*SourcePath).appendDescriptorProto_ReservedRange)
+ case 10:
+ b = p.appendRepeatedField(b, "reserved_name", nil)
+ }
+ return b
+}
+
+func (p *SourcePath) appendEnumDescriptorProto(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 1:
+ b = p.appendSingularField(b, "name", nil)
+ case 2:
+ b = p.appendRepeatedField(b, "value", (*SourcePath).appendEnumValueDescriptorProto)
+ case 3:
+ b = p.appendSingularField(b, "options", (*SourcePath).appendEnumOptions)
+ case 4:
+ b = p.appendRepeatedField(b, "reserved_range", (*SourcePath).appendEnumDescriptorProto_EnumReservedRange)
+ case 5:
+ b = p.appendRepeatedField(b, "reserved_name", nil)
+ }
+ return b
+}
+
+func (p *SourcePath) appendServiceDescriptorProto(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 1:
+ b = p.appendSingularField(b, "name", nil)
+ case 2:
+ b = p.appendRepeatedField(b, "method", (*SourcePath).appendMethodDescriptorProto)
+ case 3:
+ b = p.appendSingularField(b, "options", (*SourcePath).appendServiceOptions)
+ }
+ return b
+}
+
+func (p *SourcePath) appendFieldDescriptorProto(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 1:
+ b = p.appendSingularField(b, "name", nil)
+ case 3:
+ b = p.appendSingularField(b, "number", nil)
+ case 4:
+ b = p.appendSingularField(b, "label", nil)
+ case 5:
+ b = p.appendSingularField(b, "type", nil)
+ case 6:
+ b = p.appendSingularField(b, "type_name", nil)
+ case 2:
+ b = p.appendSingularField(b, "extendee", nil)
+ case 7:
+ b = p.appendSingularField(b, "default_value", nil)
+ case 9:
+ b = p.appendSingularField(b, "oneof_index", nil)
+ case 10:
+ b = p.appendSingularField(b, "json_name", nil)
+ case 8:
+ b = p.appendSingularField(b, "options", (*SourcePath).appendFieldOptions)
+ case 17:
+ b = p.appendSingularField(b, "proto3_optional", nil)
+ }
+ return b
+}
+
+func (p *SourcePath) appendFileOptions(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 1:
+ b = p.appendSingularField(b, "java_package", nil)
+ case 8:
+ b = p.appendSingularField(b, "java_outer_classname", nil)
+ case 10:
+ b = p.appendSingularField(b, "java_multiple_files", nil)
+ case 20:
+ b = p.appendSingularField(b, "java_generate_equals_and_hash", nil)
+ case 27:
+ b = p.appendSingularField(b, "java_string_check_utf8", nil)
+ case 9:
+ b = p.appendSingularField(b, "optimize_for", nil)
+ case 11:
+ b = p.appendSingularField(b, "go_package", nil)
+ case 16:
+ b = p.appendSingularField(b, "cc_generic_services", nil)
+ case 17:
+ b = p.appendSingularField(b, "java_generic_services", nil)
+ case 18:
+ b = p.appendSingularField(b, "py_generic_services", nil)
+ case 42:
+ b = p.appendSingularField(b, "php_generic_services", nil)
+ case 23:
+ b = p.appendSingularField(b, "deprecated", nil)
+ case 31:
+ b = p.appendSingularField(b, "cc_enable_arenas", nil)
+ case 36:
+ b = p.appendSingularField(b, "objc_class_prefix", nil)
+ case 37:
+ b = p.appendSingularField(b, "csharp_namespace", nil)
+ case 39:
+ b = p.appendSingularField(b, "swift_prefix", nil)
+ case 40:
+ b = p.appendSingularField(b, "php_class_prefix", nil)
+ case 41:
+ b = p.appendSingularField(b, "php_namespace", nil)
+ case 44:
+ b = p.appendSingularField(b, "php_metadata_namespace", nil)
+ case 45:
+ b = p.appendSingularField(b, "ruby_package", nil)
+ case 999:
+ b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption)
+ }
+ return b
+}
+
+func (p *SourcePath) appendSourceCodeInfo(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 1:
+ b = p.appendRepeatedField(b, "location", (*SourcePath).appendSourceCodeInfo_Location)
+ }
+ return b
+}
+
+func (p *SourcePath) appendDescriptorProto_ExtensionRange(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 1:
+ b = p.appendSingularField(b, "start", nil)
+ case 2:
+ b = p.appendSingularField(b, "end", nil)
+ case 3:
+ b = p.appendSingularField(b, "options", (*SourcePath).appendExtensionRangeOptions)
+ }
+ return b
+}
+
+func (p *SourcePath) appendOneofDescriptorProto(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 1:
+ b = p.appendSingularField(b, "name", nil)
+ case 2:
+ b = p.appendSingularField(b, "options", (*SourcePath).appendOneofOptions)
+ }
+ return b
+}
+
+func (p *SourcePath) appendMessageOptions(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 1:
+ b = p.appendSingularField(b, "message_set_wire_format", nil)
+ case 2:
+ b = p.appendSingularField(b, "no_standard_descriptor_accessor", nil)
+ case 3:
+ b = p.appendSingularField(b, "deprecated", nil)
+ case 7:
+ b = p.appendSingularField(b, "map_entry", nil)
+ case 999:
+ b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption)
+ }
+ return b
+}
+
+func (p *SourcePath) appendDescriptorProto_ReservedRange(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 1:
+ b = p.appendSingularField(b, "start", nil)
+ case 2:
+ b = p.appendSingularField(b, "end", nil)
+ }
+ return b
+}
+
+func (p *SourcePath) appendEnumValueDescriptorProto(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 1:
+ b = p.appendSingularField(b, "name", nil)
+ case 2:
+ b = p.appendSingularField(b, "number", nil)
+ case 3:
+ b = p.appendSingularField(b, "options", (*SourcePath).appendEnumValueOptions)
+ }
+ return b
+}
+
+func (p *SourcePath) appendEnumOptions(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 2:
+ b = p.appendSingularField(b, "allow_alias", nil)
+ case 3:
+ b = p.appendSingularField(b, "deprecated", nil)
+ case 999:
+ b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption)
+ }
+ return b
+}
+
+func (p *SourcePath) appendEnumDescriptorProto_EnumReservedRange(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 1:
+ b = p.appendSingularField(b, "start", nil)
+ case 2:
+ b = p.appendSingularField(b, "end", nil)
+ }
+ return b
+}
+
+func (p *SourcePath) appendMethodDescriptorProto(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 1:
+ b = p.appendSingularField(b, "name", nil)
+ case 2:
+ b = p.appendSingularField(b, "input_type", nil)
+ case 3:
+ b = p.appendSingularField(b, "output_type", nil)
+ case 4:
+ b = p.appendSingularField(b, "options", (*SourcePath).appendMethodOptions)
+ case 5:
+ b = p.appendSingularField(b, "client_streaming", nil)
+ case 6:
+ b = p.appendSingularField(b, "server_streaming", nil)
+ }
+ return b
+}
+
+func (p *SourcePath) appendServiceOptions(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 33:
+ b = p.appendSingularField(b, "deprecated", nil)
+ case 999:
+ b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption)
+ }
+ return b
+}
+
+func (p *SourcePath) appendFieldOptions(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 1:
+ b = p.appendSingularField(b, "ctype", nil)
+ case 2:
+ b = p.appendSingularField(b, "packed", nil)
+ case 6:
+ b = p.appendSingularField(b, "jstype", nil)
+ case 5:
+ b = p.appendSingularField(b, "lazy", nil)
+ case 3:
+ b = p.appendSingularField(b, "deprecated", nil)
+ case 10:
+ b = p.appendSingularField(b, "weak", nil)
+ case 999:
+ b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption)
+ }
+ return b
+}
+
+func (p *SourcePath) appendUninterpretedOption(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 2:
+ b = p.appendRepeatedField(b, "name", (*SourcePath).appendUninterpretedOption_NamePart)
+ case 3:
+ b = p.appendSingularField(b, "identifier_value", nil)
+ case 4:
+ b = p.appendSingularField(b, "positive_int_value", nil)
+ case 5:
+ b = p.appendSingularField(b, "negative_int_value", nil)
+ case 6:
+ b = p.appendSingularField(b, "double_value", nil)
+ case 7:
+ b = p.appendSingularField(b, "string_value", nil)
+ case 8:
+ b = p.appendSingularField(b, "aggregate_value", nil)
+ }
+ return b
+}
+
+func (p *SourcePath) appendSourceCodeInfo_Location(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 1:
+ b = p.appendRepeatedField(b, "path", nil)
+ case 2:
+ b = p.appendRepeatedField(b, "span", nil)
+ case 3:
+ b = p.appendSingularField(b, "leading_comments", nil)
+ case 4:
+ b = p.appendSingularField(b, "trailing_comments", nil)
+ case 6:
+ b = p.appendRepeatedField(b, "leading_detached_comments", nil)
+ }
+ return b
+}
+
+func (p *SourcePath) appendExtensionRangeOptions(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 999:
+ b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption)
+ }
+ return b
+}
+
+func (p *SourcePath) appendOneofOptions(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 999:
+ b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption)
+ }
+ return b
+}
+
+func (p *SourcePath) appendEnumValueOptions(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 1:
+ b = p.appendSingularField(b, "deprecated", nil)
+ case 999:
+ b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption)
+ }
+ return b
+}
+
+func (p *SourcePath) appendMethodOptions(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 33:
+ b = p.appendSingularField(b, "deprecated", nil)
+ case 34:
+ b = p.appendSingularField(b, "idempotency_level", nil)
+ case 999:
+ b = p.appendRepeatedField(b, "uninterpreted_option", (*SourcePath).appendUninterpretedOption)
+ }
+ return b
+}
+
+func (p *SourcePath) appendUninterpretedOption_NamePart(b []byte) []byte {
+ if len(*p) == 0 {
+ return b
+ }
+ switch (*p)[0] {
+ case 1:
+ b = p.appendSingularField(b, "name_part", nil)
+ case 2:
+ b = p.appendSingularField(b, "is_extension", nil)
+ }
+ return b
+}
diff --git a/vendor/google.golang.org/protobuf/reflect/protoreflect/type.go b/vendor/google.golang.org/protobuf/reflect/protoreflect/type.go
index 5be14a72..8e53c44a 100644
--- a/vendor/google.golang.org/protobuf/reflect/protoreflect/type.go
+++ b/vendor/google.golang.org/protobuf/reflect/protoreflect/type.go
@@ -232,11 +232,15 @@ type MessageDescriptor interface {
type isMessageDescriptor interface{ ProtoType(MessageDescriptor) }
// MessageType encapsulates a MessageDescriptor with a concrete Go implementation.
+// It is recommended that implementations of this interface also implement the
+// MessageFieldTypes interface.
type MessageType interface {
// New returns a newly allocated empty message.
+ // It may return nil for synthetic messages representing a map entry.
New() Message
// Zero returns an empty, read-only message.
+ // It may return nil for synthetic messages representing a map entry.
Zero() Message
// Descriptor returns the message descriptor.
@@ -245,6 +249,26 @@ type MessageType interface {
Descriptor() MessageDescriptor
}
+// MessageFieldTypes extends a MessageType by providing type information
+// regarding enums and messages referenced by the message fields.
+type MessageFieldTypes interface {
+ MessageType
+
+ // Enum returns the EnumType for the ith field in Descriptor.Fields.
+ // It returns nil if the ith field is not an enum kind.
+ // It panics if out of bounds.
+ //
+ // Invariant: mt.Enum(i).Descriptor() == mt.Descriptor().Fields(i).Enum()
+ Enum(i int) EnumType
+
+ // Message returns the MessageType for the ith field in Descriptor.Fields.
+ // It returns nil if the ith field is not a message or group kind.
+ // It panics if out of bounds.
+ //
+ // Invariant: mt.Message(i).Descriptor() == mt.Descriptor().Fields(i).Message()
+ Message(i int) MessageType
+}
+
// MessageDescriptors is a list of message declarations.
type MessageDescriptors interface {
// Len reports the number of messages.
@@ -279,8 +303,15 @@ type FieldDescriptor interface {
// JSONName reports the name used for JSON serialization.
// It is usually the camel-cased form of the field name.
+ // Extension fields are represented by the full name surrounded by brackets.
JSONName() string
+ // TextName reports the name used for text serialization.
+ // It is usually the name of the field, except that groups use the name
+ // of the inlined message, and extension fields are represented by the
+ // full name surrounded by brackets.
+ TextName() string
+
// HasPresence reports whether the field distinguishes between unpopulated
// and default values.
HasPresence() bool
@@ -371,6 +402,9 @@ type FieldDescriptors interface {
// ByJSONName returns the FieldDescriptor for a field with s as the JSON name.
// It returns nil if not found.
ByJSONName(s string) FieldDescriptor
+ // ByTextName returns the FieldDescriptor for a field with s as the text name.
+ // It returns nil if not found.
+ ByTextName(s string) FieldDescriptor
// ByNumber returns the FieldDescriptor for a field numbered n.
// It returns nil if not found.
ByNumber(n FieldNumber) FieldDescriptor