/
common.go
85 lines (68 loc) · 2.69 KB
/
common.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package generator
import (
"go/build"
"github.com/golang/protobuf/protoc-gen-go/descriptor"
)
// generatedCodeVersion indicates a version of the generated code.
// It is incremented whenever an incompatibility between the generated code and
// proto package is introduced; the generated code references
// a constant, proto.ProtoPackageIsVersionN (where N is generatedCodeVersion).
const generatedCodeVersion = 2
// A JavaImportPath is the import path of a Java package. e.g., "com.google.genproto.protobuf".
type JavaImportPath string
func (p JavaImportPath) String() string { return string(p) }
// A JavaPackageName is the name of a Java package. e.g., "com.google.protobuf".
type JavaPackageName string
type pathType int
const (
pathTypeImport pathType = iota
pathTypeSourceRelative
)
// Each type we import as a protocol buffer (other than FileDescriptorProto) needs
// a pointer to the FileDescriptorProto that represents it. These types achieve that
// wrapping by placing each Proto inside a struct with the pointer to its File. The
// structs have the same names as their contents, with "Proto" removed.
// FileDescriptor is used to store the things that it points to.
// The file and package name method are common to messages and enums.
type common struct {
file *FileDescriptor // File this object comes from.
}
// JavaImportPath is the import path of the Java package containing the type.
func (c *common) JavaImportPath() JavaImportPath {
return c.file.importPath
}
func (c *common) File() *FileDescriptor { return c.file }
func fileIsProto3(file *descriptor.FileDescriptorProto) bool {
return file.GetSyntax() == "proto3"
}
func (c *common) proto3() bool { return fileIsProto3(c.file.FileDescriptorProto) }
// The SourceCodeInfo message describes the location of elements of a parsed
// .proto file by way of a "path", which is a sequence of integers that
// describe the route from a FileDescriptorProto to the relevant submessage.
// The path alternates between a field number of a repeated field, and an index
// into that repeated field. The constants below define the field numbers that
// are used.
//
// See descriptor.proto for more information about this.
const (
// tag numbers in FileDescriptorProto
packagePath = 2 // package
messagePath = 4 // message_type
enumPath = 5 // enum_type
// tag numbers in DescriptorProto
messageFieldPath = 2 // field
messageMessagePath = 3 // nested_type
messageEnumPath = 4 // enum_type
messageOneofPath = 8 // oneof_decl
// tag numbers in EnumDescriptorProto
enumValuePath = 2 // value
)
var supportTypeAliases bool
func init() {
for _, tag := range build.Default.ReleaseTags {
if tag == "go1.9" {
supportTypeAliases = true
return
}
}
}