Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
8f79df77
Commit
8f79df77
authored
Nov 15, 2015
by
Jeromy
Browse files
vendor in gogo protobuf
parent
f3d96ac5
Changes
152
Hide whitespace changes
Inline
Side-by-side
Too many changes to show.
To preserve performance only
152 of 152+
files are displayed.
Plain diff
Email patch
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gofast/main.go
0 → 100644
View file @
8f79df77
// Extensions for Protocol Buffers to create more go like structures.
//
// Copyright (c) 2015, Vastech SA (PTY) LTD. All rights reserved.
// http://github.com/gogo/protobuf/gogoproto
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package
main
import
(
"QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/vanity"
"QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/vanity/command"
)
func
main
()
{
req
:=
command
.
Read
()
files
:=
req
.
GetProtoFile
()
vanity
.
ForEachFile
(
files
,
vanity
.
TurnOffGogoImport
)
vanity
.
ForEachFile
(
files
,
vanity
.
TurnOnMarshalerAll
)
vanity
.
ForEachFile
(
files
,
vanity
.
TurnOnSizerAll
)
vanity
.
ForEachFile
(
files
,
vanity
.
TurnOnUnmarshalerAll
)
resp
:=
command
.
Generate
(
req
)
command
.
Write
(
resp
)
}
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/Makefile
0 → 100644
View file @
8f79df77
# Go support for Protocol Buffers - Google's data interchange format
#
# Copyright 2010 The Go Authors. All rights reserved.
# https://github.com/golang/protobuf
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
test
:
cd
testdata
&&
make
test
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/descriptor/Makefile
0 → 100644
View file @
8f79df77
# Go support for Protocol Buffers - Google's data interchange format
#
# Copyright 2010 The Go Authors. All rights reserved.
# https://github.com/golang/protobuf
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
regenerate
:
protoc
--gogo_out
=
.
-I
=
../../protobuf/google/protobuf ../../protobuf/google/protobuf/descriptor.proto
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/descriptor/descriptor.pb.go
0 → 100644
View file @
8f79df77
// Code generated by protoc-gen-gogo.
// source: descriptor.proto
// DO NOT EDIT!
/*
Package google_protobuf is a generated protocol buffer package.
It is generated from these files:
descriptor.proto
It has these top-level messages:
FileDescriptorSet
FileDescriptorProto
DescriptorProto
FieldDescriptorProto
OneofDescriptorProto
EnumDescriptorProto
EnumValueDescriptorProto
ServiceDescriptorProto
MethodDescriptorProto
FileOptions
MessageOptions
FieldOptions
EnumOptions
EnumValueOptions
ServiceOptions
MethodOptions
UninterpretedOption
SourceCodeInfo
*/
package
google_protobuf
import
proto
"QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/proto"
import
fmt
"fmt"
import
math
"math"
// Reference imports to suppress errors if they are not otherwise used.
var
_
=
proto
.
Marshal
var
_
=
fmt
.
Errorf
var
_
=
math
.
Inf
type
FieldDescriptorProto_Type
int32
const
(
// 0 is reserved for errors.
// Order is weird for historical reasons.
FieldDescriptorProto_TYPE_DOUBLE
FieldDescriptorProto_Type
=
1
FieldDescriptorProto_TYPE_FLOAT
FieldDescriptorProto_Type
=
2
// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
// negative values are likely.
FieldDescriptorProto_TYPE_INT64
FieldDescriptorProto_Type
=
3
FieldDescriptorProto_TYPE_UINT64
FieldDescriptorProto_Type
=
4
// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
// negative values are likely.
FieldDescriptorProto_TYPE_INT32
FieldDescriptorProto_Type
=
5
FieldDescriptorProto_TYPE_FIXED64
FieldDescriptorProto_Type
=
6
FieldDescriptorProto_TYPE_FIXED32
FieldDescriptorProto_Type
=
7
FieldDescriptorProto_TYPE_BOOL
FieldDescriptorProto_Type
=
8
FieldDescriptorProto_TYPE_STRING
FieldDescriptorProto_Type
=
9
FieldDescriptorProto_TYPE_GROUP
FieldDescriptorProto_Type
=
10
FieldDescriptorProto_TYPE_MESSAGE
FieldDescriptorProto_Type
=
11
// New in version 2.
FieldDescriptorProto_TYPE_BYTES
FieldDescriptorProto_Type
=
12
FieldDescriptorProto_TYPE_UINT32
FieldDescriptorProto_Type
=
13
FieldDescriptorProto_TYPE_ENUM
FieldDescriptorProto_Type
=
14
FieldDescriptorProto_TYPE_SFIXED32
FieldDescriptorProto_Type
=
15
FieldDescriptorProto_TYPE_SFIXED64
FieldDescriptorProto_Type
=
16
FieldDescriptorProto_TYPE_SINT32
FieldDescriptorProto_Type
=
17
FieldDescriptorProto_TYPE_SINT64
FieldDescriptorProto_Type
=
18
)
var
FieldDescriptorProto_Type_name
=
map
[
int32
]
string
{
1
:
"TYPE_DOUBLE"
,
2
:
"TYPE_FLOAT"
,
3
:
"TYPE_INT64"
,
4
:
"TYPE_UINT64"
,
5
:
"TYPE_INT32"
,
6
:
"TYPE_FIXED64"
,
7
:
"TYPE_FIXED32"
,
8
:
"TYPE_BOOL"
,
9
:
"TYPE_STRING"
,
10
:
"TYPE_GROUP"
,
11
:
"TYPE_MESSAGE"
,
12
:
"TYPE_BYTES"
,
13
:
"TYPE_UINT32"
,
14
:
"TYPE_ENUM"
,
15
:
"TYPE_SFIXED32"
,
16
:
"TYPE_SFIXED64"
,
17
:
"TYPE_SINT32"
,
18
:
"TYPE_SINT64"
,
}
var
FieldDescriptorProto_Type_value
=
map
[
string
]
int32
{
"TYPE_DOUBLE"
:
1
,
"TYPE_FLOAT"
:
2
,
"TYPE_INT64"
:
3
,
"TYPE_UINT64"
:
4
,
"TYPE_INT32"
:
5
,
"TYPE_FIXED64"
:
6
,
"TYPE_FIXED32"
:
7
,
"TYPE_BOOL"
:
8
,
"TYPE_STRING"
:
9
,
"TYPE_GROUP"
:
10
,
"TYPE_MESSAGE"
:
11
,
"TYPE_BYTES"
:
12
,
"TYPE_UINT32"
:
13
,
"TYPE_ENUM"
:
14
,
"TYPE_SFIXED32"
:
15
,
"TYPE_SFIXED64"
:
16
,
"TYPE_SINT32"
:
17
,
"TYPE_SINT64"
:
18
,
}
func
(
x
FieldDescriptorProto_Type
)
Enum
()
*
FieldDescriptorProto_Type
{
p
:=
new
(
FieldDescriptorProto_Type
)
*
p
=
x
return
p
}
func
(
x
FieldDescriptorProto_Type
)
String
()
string
{
return
proto
.
EnumName
(
FieldDescriptorProto_Type_name
,
int32
(
x
))
}
func
(
x
*
FieldDescriptorProto_Type
)
UnmarshalJSON
(
data
[]
byte
)
error
{
value
,
err
:=
proto
.
UnmarshalJSONEnum
(
FieldDescriptorProto_Type_value
,
data
,
"FieldDescriptorProto_Type"
)
if
err
!=
nil
{
return
err
}
*
x
=
FieldDescriptorProto_Type
(
value
)
return
nil
}
type
FieldDescriptorProto_Label
int32
const
(
// 0 is reserved for errors
FieldDescriptorProto_LABEL_OPTIONAL
FieldDescriptorProto_Label
=
1
FieldDescriptorProto_LABEL_REQUIRED
FieldDescriptorProto_Label
=
2
FieldDescriptorProto_LABEL_REPEATED
FieldDescriptorProto_Label
=
3
)
var
FieldDescriptorProto_Label_name
=
map
[
int32
]
string
{
1
:
"LABEL_OPTIONAL"
,
2
:
"LABEL_REQUIRED"
,
3
:
"LABEL_REPEATED"
,
}
var
FieldDescriptorProto_Label_value
=
map
[
string
]
int32
{
"LABEL_OPTIONAL"
:
1
,
"LABEL_REQUIRED"
:
2
,
"LABEL_REPEATED"
:
3
,
}
func
(
x
FieldDescriptorProto_Label
)
Enum
()
*
FieldDescriptorProto_Label
{
p
:=
new
(
FieldDescriptorProto_Label
)
*
p
=
x
return
p
}
func
(
x
FieldDescriptorProto_Label
)
String
()
string
{
return
proto
.
EnumName
(
FieldDescriptorProto_Label_name
,
int32
(
x
))
}
func
(
x
*
FieldDescriptorProto_Label
)
UnmarshalJSON
(
data
[]
byte
)
error
{
value
,
err
:=
proto
.
UnmarshalJSONEnum
(
FieldDescriptorProto_Label_value
,
data
,
"FieldDescriptorProto_Label"
)
if
err
!=
nil
{
return
err
}
*
x
=
FieldDescriptorProto_Label
(
value
)
return
nil
}
// Generated classes can be optimized for speed or code size.
type
FileOptions_OptimizeMode
int32
const
(
FileOptions_SPEED
FileOptions_OptimizeMode
=
1
// etc.
FileOptions_CODE_SIZE
FileOptions_OptimizeMode
=
2
FileOptions_LITE_RUNTIME
FileOptions_OptimizeMode
=
3
)
var
FileOptions_OptimizeMode_name
=
map
[
int32
]
string
{
1
:
"SPEED"
,
2
:
"CODE_SIZE"
,
3
:
"LITE_RUNTIME"
,
}
var
FileOptions_OptimizeMode_value
=
map
[
string
]
int32
{
"SPEED"
:
1
,
"CODE_SIZE"
:
2
,
"LITE_RUNTIME"
:
3
,
}
func
(
x
FileOptions_OptimizeMode
)
Enum
()
*
FileOptions_OptimizeMode
{
p
:=
new
(
FileOptions_OptimizeMode
)
*
p
=
x
return
p
}
func
(
x
FileOptions_OptimizeMode
)
String
()
string
{
return
proto
.
EnumName
(
FileOptions_OptimizeMode_name
,
int32
(
x
))
}
func
(
x
*
FileOptions_OptimizeMode
)
UnmarshalJSON
(
data
[]
byte
)
error
{
value
,
err
:=
proto
.
UnmarshalJSONEnum
(
FileOptions_OptimizeMode_value
,
data
,
"FileOptions_OptimizeMode"
)
if
err
!=
nil
{
return
err
}
*
x
=
FileOptions_OptimizeMode
(
value
)
return
nil
}
type
FieldOptions_CType
int32
const
(
// Default mode.
FieldOptions_STRING
FieldOptions_CType
=
0
FieldOptions_CORD
FieldOptions_CType
=
1
FieldOptions_STRING_PIECE
FieldOptions_CType
=
2
)
var
FieldOptions_CType_name
=
map
[
int32
]
string
{
0
:
"STRING"
,
1
:
"CORD"
,
2
:
"STRING_PIECE"
,
}
var
FieldOptions_CType_value
=
map
[
string
]
int32
{
"STRING"
:
0
,
"CORD"
:
1
,
"STRING_PIECE"
:
2
,
}
func
(
x
FieldOptions_CType
)
Enum
()
*
FieldOptions_CType
{
p
:=
new
(
FieldOptions_CType
)
*
p
=
x
return
p
}
func
(
x
FieldOptions_CType
)
String
()
string
{
return
proto
.
EnumName
(
FieldOptions_CType_name
,
int32
(
x
))
}
func
(
x
*
FieldOptions_CType
)
UnmarshalJSON
(
data
[]
byte
)
error
{
value
,
err
:=
proto
.
UnmarshalJSONEnum
(
FieldOptions_CType_value
,
data
,
"FieldOptions_CType"
)
if
err
!=
nil
{
return
err
}
*
x
=
FieldOptions_CType
(
value
)
return
nil
}
// The protocol compiler can output a FileDescriptorSet containing the .proto
// files it parses.
type
FileDescriptorSet
struct
{
File
[]
*
FileDescriptorProto
`protobuf:"bytes,1,rep,name=file" json:"file,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
FileDescriptorSet
)
Reset
()
{
*
m
=
FileDescriptorSet
{}
}
func
(
m
*
FileDescriptorSet
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
FileDescriptorSet
)
ProtoMessage
()
{}
func
(
m
*
FileDescriptorSet
)
GetFile
()
[]
*
FileDescriptorProto
{
if
m
!=
nil
{
return
m
.
File
}
return
nil
}
// Describes a complete .proto file.
type
FileDescriptorProto
struct
{
Name
*
string
`protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
Package
*
string
`protobuf:"bytes,2,opt,name=package" json:"package,omitempty"`
// Names of files imported by this file.
Dependency
[]
string
`protobuf:"bytes,3,rep,name=dependency" json:"dependency,omitempty"`
// Indexes of the public imported files in the dependency list above.
PublicDependency
[]
int32
`protobuf:"varint,10,rep,name=public_dependency" json:"public_dependency,omitempty"`
// Indexes of the weak imported files in the dependency list.
// For Google-internal migration only. Do not use.
WeakDependency
[]
int32
`protobuf:"varint,11,rep,name=weak_dependency" json:"weak_dependency,omitempty"`
// All top-level definitions in this file.
MessageType
[]
*
DescriptorProto
`protobuf:"bytes,4,rep,name=message_type" json:"message_type,omitempty"`
EnumType
[]
*
EnumDescriptorProto
`protobuf:"bytes,5,rep,name=enum_type" json:"enum_type,omitempty"`
Service
[]
*
ServiceDescriptorProto
`protobuf:"bytes,6,rep,name=service" json:"service,omitempty"`
Extension
[]
*
FieldDescriptorProto
`protobuf:"bytes,7,rep,name=extension" json:"extension,omitempty"`
Options
*
FileOptions
`protobuf:"bytes,8,opt,name=options" json:"options,omitempty"`
// This field contains optional information about the original source code.
// You may safely remove this entire field without harming runtime
// functionality of the descriptors -- the information is needed only by
// development tools.
SourceCodeInfo
*
SourceCodeInfo
`protobuf:"bytes,9,opt,name=source_code_info" json:"source_code_info,omitempty"`
// The syntax of the proto file.
// The supported values are "proto2" and "proto3".
Syntax
*
string
`protobuf:"bytes,12,opt,name=syntax" json:"syntax,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
FileDescriptorProto
)
Reset
()
{
*
m
=
FileDescriptorProto
{}
}
func
(
m
*
FileDescriptorProto
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
FileDescriptorProto
)
ProtoMessage
()
{}
func
(
m
*
FileDescriptorProto
)
GetName
()
string
{
if
m
!=
nil
&&
m
.
Name
!=
nil
{
return
*
m
.
Name
}
return
""
}
func
(
m
*
FileDescriptorProto
)
GetPackage
()
string
{
if
m
!=
nil
&&
m
.
Package
!=
nil
{
return
*
m
.
Package
}
return
""
}
func
(
m
*
FileDescriptorProto
)
GetDependency
()
[]
string
{
if
m
!=
nil
{
return
m
.
Dependency
}
return
nil
}
func
(
m
*
FileDescriptorProto
)
GetPublicDependency
()
[]
int32
{
if
m
!=
nil
{
return
m
.
PublicDependency
}
return
nil
}
func
(
m
*
FileDescriptorProto
)
GetWeakDependency
()
[]
int32
{
if
m
!=
nil
{
return
m
.
WeakDependency
}
return
nil
}
func
(
m
*
FileDescriptorProto
)
GetMessageType
()
[]
*
DescriptorProto
{
if
m
!=
nil
{
return
m
.
MessageType
}
return
nil
}
func
(
m
*
FileDescriptorProto
)
GetEnumType
()
[]
*
EnumDescriptorProto
{
if
m
!=
nil
{
return
m
.
EnumType
}
return
nil
}
func
(
m
*
FileDescriptorProto
)
GetService
()
[]
*
ServiceDescriptorProto
{
if
m
!=
nil
{
return
m
.
Service
}
return
nil
}
func
(
m
*
FileDescriptorProto
)
GetExtension
()
[]
*
FieldDescriptorProto
{
if
m
!=
nil
{
return
m
.
Extension
}
return
nil
}
func
(
m
*
FileDescriptorProto
)
GetOptions
()
*
FileOptions
{
if
m
!=
nil
{
return
m
.
Options
}
return
nil
}
func
(
m
*
FileDescriptorProto
)
GetSourceCodeInfo
()
*
SourceCodeInfo
{
if
m
!=
nil
{
return
m
.
SourceCodeInfo
}
return
nil
}
func
(
m
*
FileDescriptorProto
)
GetSyntax
()
string
{
if
m
!=
nil
&&
m
.
Syntax
!=
nil
{
return
*
m
.
Syntax
}
return
""
}
// Describes a message type.
type
DescriptorProto
struct
{
Name
*
string
`protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
Field
[]
*
FieldDescriptorProto
`protobuf:"bytes,2,rep,name=field" json:"field,omitempty"`
Extension
[]
*
FieldDescriptorProto
`protobuf:"bytes,6,rep,name=extension" json:"extension,omitempty"`
NestedType
[]
*
DescriptorProto
`protobuf:"bytes,3,rep,name=nested_type" json:"nested_type,omitempty"`
EnumType
[]
*
EnumDescriptorProto
`protobuf:"bytes,4,rep,name=enum_type" json:"enum_type,omitempty"`
ExtensionRange
[]
*
DescriptorProto_ExtensionRange
`protobuf:"bytes,5,rep,name=extension_range" json:"extension_range,omitempty"`
OneofDecl
[]
*
OneofDescriptorProto
`protobuf:"bytes,8,rep,name=oneof_decl" json:"oneof_decl,omitempty"`
Options
*
MessageOptions
`protobuf:"bytes,7,opt,name=options" json:"options,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
DescriptorProto
)
Reset
()
{
*
m
=
DescriptorProto
{}
}
func
(
m
*
DescriptorProto
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
DescriptorProto
)
ProtoMessage
()
{}
func
(
m
*
DescriptorProto
)
GetName
()
string
{
if
m
!=
nil
&&
m
.
Name
!=
nil
{
return
*
m
.
Name
}
return
""
}
func
(
m
*
DescriptorProto
)
GetField
()
[]
*
FieldDescriptorProto
{
if
m
!=
nil
{
return
m
.
Field
}
return
nil
}
func
(
m
*
DescriptorProto
)
GetExtension
()
[]
*
FieldDescriptorProto
{
if
m
!=
nil
{
return
m
.
Extension
}
return
nil
}
func
(
m
*
DescriptorProto
)
GetNestedType
()
[]
*
DescriptorProto
{
if
m
!=
nil
{
return
m
.
NestedType
}
return
nil
}
func
(
m
*
DescriptorProto
)
GetEnumType
()
[]
*
EnumDescriptorProto
{
if
m
!=
nil
{
return
m
.
EnumType
}
return
nil
}
func
(
m
*
DescriptorProto
)
GetExtensionRange
()
[]
*
DescriptorProto_ExtensionRange
{
if
m
!=
nil
{
return
m
.
ExtensionRange
}
return
nil
}
func
(
m
*
DescriptorProto
)
GetOneofDecl
()
[]
*
OneofDescriptorProto
{
if
m
!=
nil
{
return
m
.
OneofDecl
}
return
nil
}
func
(
m
*
DescriptorProto
)
GetOptions
()
*
MessageOptions
{
if
m
!=
nil
{
return
m
.
Options
}
return
nil
}
type
DescriptorProto_ExtensionRange
struct
{
Start
*
int32
`protobuf:"varint,1,opt,name=start" json:"start,omitempty"`
End
*
int32
`protobuf:"varint,2,opt,name=end" json:"end,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
DescriptorProto_ExtensionRange
)
Reset
()
{
*
m
=
DescriptorProto_ExtensionRange
{}
}
func
(
m
*
DescriptorProto_ExtensionRange
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
DescriptorProto_ExtensionRange
)
ProtoMessage
()
{}
func
(
m
*
DescriptorProto_ExtensionRange
)
GetStart
()
int32
{
if
m
!=
nil
&&
m
.
Start
!=
nil
{
return
*
m
.
Start
}
return
0
}
func
(
m
*
DescriptorProto_ExtensionRange
)
GetEnd
()
int32
{
if
m
!=
nil
&&
m
.
End
!=
nil
{
return
*
m
.
End
}
return
0
}
// Describes a field within a message.
type
FieldDescriptorProto
struct
{
Name
*
string
`protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
Number
*
int32
`protobuf:"varint,3,opt,name=number" json:"number,omitempty"`
Label
*
FieldDescriptorProto_Label
`protobuf:"varint,4,opt,name=label,enum=google.protobuf.FieldDescriptorProto_Label" json:"label,omitempty"`
// If type_name is set, this need not be set. If both this and type_name
// are set, this must be one of TYPE_ENUM, TYPE_MESSAGE or TYPE_GROUP.
Type
*
FieldDescriptorProto_Type
`protobuf:"varint,5,opt,name=type,enum=google.protobuf.FieldDescriptorProto_Type" json:"type,omitempty"`
// For message and enum types, this is the name of the type. If the name
// starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
// rules are used to find the type (i.e. first the nested types within this
// message are searched, then within the parent, on up to the root
// namespace).
TypeName
*
string
`protobuf:"bytes,6,opt,name=type_name" json:"type_name,omitempty"`
// For extensions, this is the name of the type being extended. It is
// resolved in the same manner as type_name.
Extendee
*
string
`protobuf:"bytes,2,opt,name=extendee" json:"extendee,omitempty"`
// For numeric types, contains the original text representation of the value.
// For booleans, "true" or "false".
// For strings, contains the default text contents (not escaped in any way).
// For bytes, contains the C escaped value. All bytes >= 128 are escaped.
// TODO(kenton): Base-64 encode?
DefaultValue
*
string
`protobuf:"bytes,7,opt,name=default_value" json:"default_value,omitempty"`
// If set, gives the index of a oneof in the containing type's oneof_decl
// list. This field is a member of that oneof. Extensions of a oneof should
// not set this since the oneof to which they belong will be inferred based
// on the extension range containing the extension's field number.
OneofIndex
*
int32
`protobuf:"varint,9,opt,name=oneof_index" json:"oneof_index,omitempty"`
Options
*
FieldOptions
`protobuf:"bytes,8,opt,name=options" json:"options,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
FieldDescriptorProto
)
Reset
()
{
*
m
=
FieldDescriptorProto
{}
}
func
(
m
*
FieldDescriptorProto
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
FieldDescriptorProto
)
ProtoMessage
()
{}
func
(
m
*
FieldDescriptorProto
)
GetName
()
string
{
if
m
!=
nil
&&
m
.
Name
!=
nil
{
return
*
m
.
Name
}
return
""
}
func
(
m
*
FieldDescriptorProto
)
GetNumber
()
int32
{
if
m
!=
nil
&&
m
.
Number
!=
nil
{
return
*
m
.
Number
}
return
0
}
func
(
m
*
FieldDescriptorProto
)
GetLabel
()
FieldDescriptorProto_Label
{
if
m
!=
nil
&&
m
.
Label
!=
nil
{
return
*
m
.
Label
}
return
FieldDescriptorProto_LABEL_OPTIONAL
}
func
(
m
*
FieldDescriptorProto
)
GetType
()
FieldDescriptorProto_Type
{
if
m
!=
nil
&&
m
.
Type
!=
nil
{
return
*
m
.
Type
}
return
FieldDescriptorProto_TYPE_DOUBLE
}
func
(
m
*
FieldDescriptorProto
)
GetTypeName
()
string
{
if
m
!=
nil
&&
m
.
TypeName
!=
nil
{
return
*
m
.
TypeName
}
return
""
}
func
(
m
*
FieldDescriptorProto
)
GetExtendee
()
string
{
if
m
!=
nil
&&
m
.
Extendee
!=
nil
{
return
*
m
.
Extendee
}
return
""
}
func
(
m
*
FieldDescriptorProto
)
GetDefaultValue
()
string
{
if
m
!=
nil
&&
m
.
DefaultValue
!=
nil
{
return
*
m
.
DefaultValue
}
return
""
}
func
(
m
*
FieldDescriptorProto
)
GetOneofIndex
()
int32
{
if
m
!=
nil
&&
m
.
OneofIndex
!=
nil
{
return
*
m
.
OneofIndex
}
return
0
}
func
(
m
*
FieldDescriptorProto
)
GetOptions
()
*
FieldOptions
{
if
m
!=
nil
{
return
m
.
Options
}
return
nil
}
// Describes a oneof.
type
OneofDescriptorProto
struct
{
Name
*
string
`protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
OneofDescriptorProto
)
Reset
()
{
*
m
=
OneofDescriptorProto
{}
}
func
(
m
*
OneofDescriptorProto
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
OneofDescriptorProto
)
ProtoMessage
()
{}
func
(
m
*
OneofDescriptorProto
)
GetName
()
string
{
if
m
!=
nil
&&
m
.
Name
!=
nil
{
return
*
m
.
Name
}
return
""
}
// Describes an enum type.
type
EnumDescriptorProto
struct
{
Name
*
string
`protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
Value
[]
*
EnumValueDescriptorProto
`protobuf:"bytes,2,rep,name=value" json:"value,omitempty"`
Options
*
EnumOptions
`protobuf:"bytes,3,opt,name=options" json:"options,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
EnumDescriptorProto
)
Reset
()
{
*
m
=
EnumDescriptorProto
{}
}
func
(
m
*
EnumDescriptorProto
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
EnumDescriptorProto
)
ProtoMessage
()
{}
func
(
m
*
EnumDescriptorProto
)
GetName
()
string
{
if
m
!=
nil
&&
m
.
Name
!=
nil
{
return
*
m
.
Name
}
return
""
}
func
(
m
*
EnumDescriptorProto
)
GetValue
()
[]
*
EnumValueDescriptorProto
{
if
m
!=
nil
{
return
m
.
Value
}
return
nil
}
func
(
m
*
EnumDescriptorProto
)
GetOptions
()
*
EnumOptions
{
if
m
!=
nil
{
return
m
.
Options
}
return
nil
}
// Describes a value within an enum.
type
EnumValueDescriptorProto
struct
{
Name
*
string
`protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
Number
*
int32
`protobuf:"varint,2,opt,name=number" json:"number,omitempty"`
Options
*
EnumValueOptions
`protobuf:"bytes,3,opt,name=options" json:"options,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
EnumValueDescriptorProto
)
Reset
()
{
*
m
=
EnumValueDescriptorProto
{}
}
func
(
m
*
EnumValueDescriptorProto
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
EnumValueDescriptorProto
)
ProtoMessage
()
{}
func
(
m
*
EnumValueDescriptorProto
)
GetName
()
string
{
if
m
!=
nil
&&
m
.
Name
!=
nil
{
return
*
m
.
Name
}
return
""
}
func
(
m
*
EnumValueDescriptorProto
)
GetNumber
()
int32
{
if
m
!=
nil
&&
m
.
Number
!=
nil
{
return
*
m
.
Number
}
return
0
}
func
(
m
*
EnumValueDescriptorProto
)
GetOptions
()
*
EnumValueOptions
{
if
m
!=
nil
{
return
m
.
Options
}
return
nil
}
// Describes a service.
type
ServiceDescriptorProto
struct
{
Name
*
string
`protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
Method
[]
*
MethodDescriptorProto
`protobuf:"bytes,2,rep,name=method" json:"method,omitempty"`
Options
*
ServiceOptions
`protobuf:"bytes,3,opt,name=options" json:"options,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
ServiceDescriptorProto
)
Reset
()
{
*
m
=
ServiceDescriptorProto
{}
}
func
(
m
*
ServiceDescriptorProto
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
ServiceDescriptorProto
)
ProtoMessage
()
{}
func
(
m
*
ServiceDescriptorProto
)
GetName
()
string
{
if
m
!=
nil
&&
m
.
Name
!=
nil
{
return
*
m
.
Name
}
return
""
}
func
(
m
*
ServiceDescriptorProto
)
GetMethod
()
[]
*
MethodDescriptorProto
{
if
m
!=
nil
{
return
m
.
Method
}
return
nil
}
func
(
m
*
ServiceDescriptorProto
)
GetOptions
()
*
ServiceOptions
{
if
m
!=
nil
{
return
m
.
Options
}
return
nil
}
// Describes a method of a service.
type
MethodDescriptorProto
struct
{
Name
*
string
`protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
// Input and output type names. These are resolved in the same way as
// FieldDescriptorProto.type_name, but must refer to a message type.
InputType
*
string
`protobuf:"bytes,2,opt,name=input_type" json:"input_type,omitempty"`
OutputType
*
string
`protobuf:"bytes,3,opt,name=output_type" json:"output_type,omitempty"`
Options
*
MethodOptions
`protobuf:"bytes,4,opt,name=options" json:"options,omitempty"`
// Identifies if client streams multiple client messages
ClientStreaming
*
bool
`protobuf:"varint,5,opt,name=client_streaming,def=0" json:"client_streaming,omitempty"`
// Identifies if server streams multiple server messages
ServerStreaming
*
bool
`protobuf:"varint,6,opt,name=server_streaming,def=0" json:"server_streaming,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
MethodDescriptorProto
)
Reset
()
{
*
m
=
MethodDescriptorProto
{}
}
func
(
m
*
MethodDescriptorProto
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
MethodDescriptorProto
)
ProtoMessage
()
{}
const
Default_MethodDescriptorProto_ClientStreaming
bool
=
false
const
Default_MethodDescriptorProto_ServerStreaming
bool
=
false
func
(
m
*
MethodDescriptorProto
)
GetName
()
string
{
if
m
!=
nil
&&
m
.
Name
!=
nil
{
return
*
m
.
Name
}
return
""
}
func
(
m
*
MethodDescriptorProto
)
GetInputType
()
string
{
if
m
!=
nil
&&
m
.
InputType
!=
nil
{
return
*
m
.
InputType
}
return
""
}
func
(
m
*
MethodDescriptorProto
)
GetOutputType
()
string
{
if
m
!=
nil
&&
m
.
OutputType
!=
nil
{
return
*
m
.
OutputType
}
return
""
}
func
(
m
*
MethodDescriptorProto
)
GetOptions
()
*
MethodOptions
{
if
m
!=
nil
{
return
m
.
Options
}
return
nil
}
func
(
m
*
MethodDescriptorProto
)
GetClientStreaming
()
bool
{
if
m
!=
nil
&&
m
.
ClientStreaming
!=
nil
{
return
*
m
.
ClientStreaming
}
return
Default_MethodDescriptorProto_ClientStreaming
}
func
(
m
*
MethodDescriptorProto
)
GetServerStreaming
()
bool
{
if
m
!=
nil
&&
m
.
ServerStreaming
!=
nil
{
return
*
m
.
ServerStreaming
}
return
Default_MethodDescriptorProto_ServerStreaming
}
type
FileOptions
struct
{
// Sets the Java package where classes generated from this .proto will be
// placed. By default, the proto package is used, but this is often
// inappropriate because proto packages do not normally start with backwards
// domain names.
JavaPackage
*
string
`protobuf:"bytes,1,opt,name=java_package" json:"java_package,omitempty"`
// If set, all the classes from the .proto file are wrapped in a single
// outer class with the given name. This applies to both Proto1
// (equivalent to the old "--one_java_file" option) and Proto2 (where
// a .proto always translates to a single class, but you may want to
// explicitly choose the class name).
JavaOuterClassname
*
string
`protobuf:"bytes,8,opt,name=java_outer_classname" json:"java_outer_classname,omitempty"`
// If set true, then the Java code generator will generate a separate .java
// file for each top-level message, enum, and service defined in the .proto
// file. Thus, these types will *not* be nested inside the outer class
// named by java_outer_classname. However, the outer class will still be
// generated to contain the file's getDescriptor() method as well as any
// top-level extensions defined in the file.
JavaMultipleFiles
*
bool
`protobuf:"varint,10,opt,name=java_multiple_files,def=0" json:"java_multiple_files,omitempty"`
// If set true, then the Java code generator will generate equals() and
// hashCode() methods for all messages defined in the .proto file.
// - In the full runtime, this is purely a speed optimization, as the
// AbstractMessage base class includes reflection-based implementations of
// these methods.
// - In the lite runtime, setting this option changes the semantics of
// equals() and hashCode() to more closely match those of the full runtime;
// the generated methods compute their results based on field values rather
// than object identity. (Implementations should not assume that hashcodes
// will be consistent across runtimes or versions of the protocol compiler.)
JavaGenerateEqualsAndHash
*
bool
`protobuf:"varint,20,opt,name=java_generate_equals_and_hash,def=0" json:"java_generate_equals_and_hash,omitempty"`
// If set true, then the Java2 code generator will generate code that
// throws an exception whenever an attempt is made to assign a non-UTF-8
// byte sequence to a string field.
// Message reflection will do the same.
// However, an extension field still accepts non-UTF-8 byte sequences.
// This option has no effect on when used with the lite runtime.
JavaStringCheckUtf8
*
bool
`protobuf:"varint,27,opt,name=java_string_check_utf8,def=0" json:"java_string_check_utf8,omitempty"`
OptimizeFor
*
FileOptions_OptimizeMode
`protobuf:"varint,9,opt,name=optimize_for,enum=google.protobuf.FileOptions_OptimizeMode,def=1" json:"optimize_for,omitempty"`
// Sets the Go package where structs generated from this .proto will be
// placed. If omitted, the Go package will be derived from the following:
// - The basename of the package import path, if provided.
// - Otherwise, the package statement in the .proto file, if present.
// - Otherwise, the basename of the .proto file, without extension.
GoPackage
*
string
`protobuf:"bytes,11,opt,name=go_package" json:"go_package,omitempty"`
// Should generic services be generated in each language? "Generic" services
// are not specific to any particular RPC system. They are generated by the
// main code generators in each language (without additional plugins).
// Generic services were the only kind of service generation supported by
// early versions of google.protobuf.
//
// Generic services are now considered deprecated in favor of using plugins
// that generate code specific to your particular RPC system. Therefore,
// these default to false. Old code which depends on generic services should
// explicitly set them to true.
CcGenericServices
*
bool
`protobuf:"varint,16,opt,name=cc_generic_services,def=0" json:"cc_generic_services,omitempty"`
JavaGenericServices
*
bool
`protobuf:"varint,17,opt,name=java_generic_services,def=0" json:"java_generic_services,omitempty"`
PyGenericServices
*
bool
`protobuf:"varint,18,opt,name=py_generic_services,def=0" json:"py_generic_services,omitempty"`
// Is this file deprecated?
// Depending on the target platform, this can emit Deprecated annotations
// for everything in the file, or it will be completely ignored; in the very
// least, this is a formalization for deprecating files.
Deprecated
*
bool
`protobuf:"varint,23,opt,name=deprecated,def=0" json:"deprecated,omitempty"`
// Enables the use of arenas for the proto messages in this file. This applies
// only to generated classes for C++.
CcEnableArenas
*
bool
`protobuf:"varint,31,opt,name=cc_enable_arenas,def=0" json:"cc_enable_arenas,omitempty"`
// The parser stores options it doesn't recognize here. See above.
UninterpretedOption
[]
*
UninterpretedOption
`protobuf:"bytes,999,rep,name=uninterpreted_option" json:"uninterpreted_option,omitempty"`
XXX_extensions
map
[
int32
]
proto
.
Extension
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
FileOptions
)
Reset
()
{
*
m
=
FileOptions
{}
}
func
(
m
*
FileOptions
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
FileOptions
)
ProtoMessage
()
{}
var
extRange_FileOptions
=
[]
proto
.
ExtensionRange
{
{
1000
,
536870911
},
}
func
(
*
FileOptions
)
ExtensionRangeArray
()
[]
proto
.
ExtensionRange
{
return
extRange_FileOptions
}
func
(
m
*
FileOptions
)
ExtensionMap
()
map
[
int32
]
proto
.
Extension
{
if
m
.
XXX_extensions
==
nil
{
m
.
XXX_extensions
=
make
(
map
[
int32
]
proto
.
Extension
)
}
return
m
.
XXX_extensions
}
const
Default_FileOptions_JavaMultipleFiles
bool
=
false
const
Default_FileOptions_JavaGenerateEqualsAndHash
bool
=
false
const
Default_FileOptions_JavaStringCheckUtf8
bool
=
false
const
Default_FileOptions_OptimizeFor
FileOptions_OptimizeMode
=
FileOptions_SPEED
const
Default_FileOptions_CcGenericServices
bool
=
false
const
Default_FileOptions_JavaGenericServices
bool
=
false
const
Default_FileOptions_PyGenericServices
bool
=
false
const
Default_FileOptions_Deprecated
bool
=
false
const
Default_FileOptions_CcEnableArenas
bool
=
false
func
(
m
*
FileOptions
)
GetJavaPackage
()
string
{
if
m
!=
nil
&&
m
.
JavaPackage
!=
nil
{
return
*
m
.
JavaPackage
}
return
""
}
func
(
m
*
FileOptions
)
GetJavaOuterClassname
()
string
{
if
m
!=
nil
&&
m
.
JavaOuterClassname
!=
nil
{
return
*
m
.
JavaOuterClassname
}
return
""
}
func
(
m
*
FileOptions
)
GetJavaMultipleFiles
()
bool
{
if
m
!=
nil
&&
m
.
JavaMultipleFiles
!=
nil
{
return
*
m
.
JavaMultipleFiles
}
return
Default_FileOptions_JavaMultipleFiles
}
func
(
m
*
FileOptions
)
GetJavaGenerateEqualsAndHash
()
bool
{
if
m
!=
nil
&&
m
.
JavaGenerateEqualsAndHash
!=
nil
{
return
*
m
.
JavaGenerateEqualsAndHash
}
return
Default_FileOptions_JavaGenerateEqualsAndHash
}
func
(
m
*
FileOptions
)
GetJavaStringCheckUtf8
()
bool
{
if
m
!=
nil
&&
m
.
JavaStringCheckUtf8
!=
nil
{
return
*
m
.
JavaStringCheckUtf8
}
return
Default_FileOptions_JavaStringCheckUtf8
}
func
(
m
*
FileOptions
)
GetOptimizeFor
()
FileOptions_OptimizeMode
{
if
m
!=
nil
&&
m
.
OptimizeFor
!=
nil
{
return
*
m
.
OptimizeFor
}
return
Default_FileOptions_OptimizeFor
}
func
(
m
*
FileOptions
)
GetGoPackage
()
string
{
if
m
!=
nil
&&
m
.
GoPackage
!=
nil
{
return
*
m
.
GoPackage
}
return
""
}
func
(
m
*
FileOptions
)
GetCcGenericServices
()
bool
{
if
m
!=
nil
&&
m
.
CcGenericServices
!=
nil
{
return
*
m
.
CcGenericServices
}
return
Default_FileOptions_CcGenericServices
}
func
(
m
*
FileOptions
)
GetJavaGenericServices
()
bool
{
if
m
!=
nil
&&
m
.
JavaGenericServices
!=
nil
{
return
*
m
.
JavaGenericServices
}
return
Default_FileOptions_JavaGenericServices
}
func
(
m
*
FileOptions
)
GetPyGenericServices
()
bool
{
if
m
!=
nil
&&
m
.
PyGenericServices
!=
nil
{
return
*
m
.
PyGenericServices
}
return
Default_FileOptions_PyGenericServices
}
func
(
m
*
FileOptions
)
GetDeprecated
()
bool
{
if
m
!=
nil
&&
m
.
Deprecated
!=
nil
{
return
*
m
.
Deprecated
}
return
Default_FileOptions_Deprecated
}
func
(
m
*
FileOptions
)
GetCcEnableArenas
()
bool
{
if
m
!=
nil
&&
m
.
CcEnableArenas
!=
nil
{
return
*
m
.
CcEnableArenas
}
return
Default_FileOptions_CcEnableArenas
}
func
(
m
*
FileOptions
)
GetUninterpretedOption
()
[]
*
UninterpretedOption
{
if
m
!=
nil
{
return
m
.
UninterpretedOption
}
return
nil
}
type
MessageOptions
struct
{
// Set true to use the old proto1 MessageSet wire format for extensions.
// This is provided for backwards-compatibility with the MessageSet wire
// format. You should not use this for any other reason: It's less
// efficient, has fewer features, and is more complicated.
//
// The message must be defined exactly as follows:
// message Foo {
// option message_set_wire_format = true;
// extensions 4 to max;
// }
// Note that the message cannot have any defined fields; MessageSets only
// have extensions.
//
// All extensions of your type must be singular messages; e.g. they cannot
// be int32s, enums, or repeated messages.
//
// Because this is an option, the above two restrictions are not enforced by
// the protocol compiler.
MessageSetWireFormat
*
bool
`protobuf:"varint,1,opt,name=message_set_wire_format,def=0" json:"message_set_wire_format,omitempty"`
// Disables the generation of the standard "descriptor()" accessor, which can
// conflict with a field of the same name. This is meant to make migration
// from proto1 easier; new code should avoid fields named "descriptor".
NoStandardDescriptorAccessor
*
bool
`protobuf:"varint,2,opt,name=no_standard_descriptor_accessor,def=0" json:"no_standard_descriptor_accessor,omitempty"`
// Is this message deprecated?
// Depending on the target platform, this can emit Deprecated annotations
// for the message, or it will be completely ignored; in the very least,
// this is a formalization for deprecating messages.
Deprecated
*
bool
`protobuf:"varint,3,opt,name=deprecated,def=0" json:"deprecated,omitempty"`
// Whether the message is an automatically generated map entry type for the
// maps field.
//
// For maps fields:
// map<KeyType, ValueType> map_field = 1;
// The parsed descriptor looks like:
// message MapFieldEntry {
// option map_entry = true;
// optional KeyType key = 1;
// optional ValueType value = 2;
// }
// repeated MapFieldEntry map_field = 1;
//
// Implementations may choose not to generate the map_entry=true message, but
// use a native map in the target language to hold the keys and values.
// The reflection APIs in such implementions still need to work as
// if the field is a repeated message field.
//
// NOTE: Do not set the option in .proto files. Always use the maps syntax
// instead. The option should only be implicitly set by the proto compiler
// parser.
MapEntry
*
bool
`protobuf:"varint,7,opt,name=map_entry" json:"map_entry,omitempty"`
// The parser stores options it doesn't recognize here. See above.
UninterpretedOption
[]
*
UninterpretedOption
`protobuf:"bytes,999,rep,name=uninterpreted_option" json:"uninterpreted_option,omitempty"`
XXX_extensions
map
[
int32
]
proto
.
Extension
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
MessageOptions
)
Reset
()
{
*
m
=
MessageOptions
{}
}
func
(
m
*
MessageOptions
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
MessageOptions
)
ProtoMessage
()
{}
var
extRange_MessageOptions
=
[]
proto
.
ExtensionRange
{
{
1000
,
536870911
},
}
func
(
*
MessageOptions
)
ExtensionRangeArray
()
[]
proto
.
ExtensionRange
{
return
extRange_MessageOptions
}
func
(
m
*
MessageOptions
)
ExtensionMap
()
map
[
int32
]
proto
.
Extension
{
if
m
.
XXX_extensions
==
nil
{
m
.
XXX_extensions
=
make
(
map
[
int32
]
proto
.
Extension
)
}
return
m
.
XXX_extensions
}
const
Default_MessageOptions_MessageSetWireFormat
bool
=
false
const
Default_MessageOptions_NoStandardDescriptorAccessor
bool
=
false
const
Default_MessageOptions_Deprecated
bool
=
false
func
(
m
*
MessageOptions
)
GetMessageSetWireFormat
()
bool
{
if
m
!=
nil
&&
m
.
MessageSetWireFormat
!=
nil
{
return
*
m
.
MessageSetWireFormat
}
return
Default_MessageOptions_MessageSetWireFormat
}
func
(
m
*
MessageOptions
)
GetNoStandardDescriptorAccessor
()
bool
{
if
m
!=
nil
&&
m
.
NoStandardDescriptorAccessor
!=
nil
{
return
*
m
.
NoStandardDescriptorAccessor
}
return
Default_MessageOptions_NoStandardDescriptorAccessor
}
func
(
m
*
MessageOptions
)
GetDeprecated
()
bool
{
if
m
!=
nil
&&
m
.
Deprecated
!=
nil
{
return
*
m
.
Deprecated
}
return
Default_MessageOptions_Deprecated
}
func
(
m
*
MessageOptions
)
GetMapEntry
()
bool
{
if
m
!=
nil
&&
m
.
MapEntry
!=
nil
{
return
*
m
.
MapEntry
}
return
false
}
func
(
m
*
MessageOptions
)
GetUninterpretedOption
()
[]
*
UninterpretedOption
{
if
m
!=
nil
{
return
m
.
UninterpretedOption
}
return
nil
}
type
FieldOptions
struct
{
// The ctype option instructs the C++ code generator to use a different
// representation of the field than it normally would. See the specific
// options below. This option is not yet implemented in the open source
// release -- sorry, we'll try to include it in a future version!
Ctype
*
FieldOptions_CType
`protobuf:"varint,1,opt,name=ctype,enum=google.protobuf.FieldOptions_CType,def=0" json:"ctype,omitempty"`
// The packed option can be enabled for repeated primitive fields to enable
// a more efficient representation on the wire. Rather than repeatedly
// writing the tag and type for each element, the entire array is encoded as
// a single length-delimited blob.
Packed
*
bool
`protobuf:"varint,2,opt,name=packed" json:"packed,omitempty"`
// Should this field be parsed lazily? Lazy applies only to message-type
// fields. It means that when the outer message is initially parsed, the
// inner message's contents will not be parsed but instead stored in encoded
// form. The inner message will actually be parsed when it is first accessed.
//
// This is only a hint. Implementations are free to choose whether to use
// eager or lazy parsing regardless of the value of this option. However,
// setting this option true suggests that the protocol author believes that
// using lazy parsing on this field is worth the additional bookkeeping
// overhead typically needed to implement it.
//
// This option does not affect the public interface of any generated code;
// all method signatures remain the same. Furthermore, thread-safety of the
// interface is not affected by this option; const methods remain safe to
// call from multiple threads concurrently, while non-const methods continue
// to require exclusive access.
//
//
// Note that implementations may choose not to check required fields within
// a lazy sub-message. That is, calling IsInitialized() on the outher message
// may return true even if the inner message has missing required fields.
// This is necessary because otherwise the inner message would have to be
// parsed in order to perform the check, defeating the purpose of lazy
// parsing. An implementation which chooses not to check required fields
// must be consistent about it. That is, for any particular sub-message, the
// implementation must either *always* check its required fields, or *never*
// check its required fields, regardless of whether or not the message has
// been parsed.
Lazy
*
bool
`protobuf:"varint,5,opt,name=lazy,def=0" json:"lazy,omitempty"`
// Is this field deprecated?
// Depending on the target platform, this can emit Deprecated annotations
// for accessors, or it will be completely ignored; in the very least, this
// is a formalization for deprecating fields.
Deprecated
*
bool
`protobuf:"varint,3,opt,name=deprecated,def=0" json:"deprecated,omitempty"`
// For Google-internal migration only. Do not use.
Weak
*
bool
`protobuf:"varint,10,opt,name=weak,def=0" json:"weak,omitempty"`
// The parser stores options it doesn't recognize here. See above.
UninterpretedOption
[]
*
UninterpretedOption
`protobuf:"bytes,999,rep,name=uninterpreted_option" json:"uninterpreted_option,omitempty"`
XXX_extensions
map
[
int32
]
proto
.
Extension
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
FieldOptions
)
Reset
()
{
*
m
=
FieldOptions
{}
}
func
(
m
*
FieldOptions
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
FieldOptions
)
ProtoMessage
()
{}
var
extRange_FieldOptions
=
[]
proto
.
ExtensionRange
{
{
1000
,
536870911
},
}
func
(
*
FieldOptions
)
ExtensionRangeArray
()
[]
proto
.
ExtensionRange
{
return
extRange_FieldOptions
}
func
(
m
*
FieldOptions
)
ExtensionMap
()
map
[
int32
]
proto
.
Extension
{
if
m
.
XXX_extensions
==
nil
{
m
.
XXX_extensions
=
make
(
map
[
int32
]
proto
.
Extension
)
}
return
m
.
XXX_extensions
}
const
Default_FieldOptions_Ctype
FieldOptions_CType
=
FieldOptions_STRING
const
Default_FieldOptions_Lazy
bool
=
false
const
Default_FieldOptions_Deprecated
bool
=
false
const
Default_FieldOptions_Weak
bool
=
false
func
(
m
*
FieldOptions
)
GetCtype
()
FieldOptions_CType
{
if
m
!=
nil
&&
m
.
Ctype
!=
nil
{
return
*
m
.
Ctype
}
return
Default_FieldOptions_Ctype
}
func
(
m
*
FieldOptions
)
GetPacked
()
bool
{
if
m
!=
nil
&&
m
.
Packed
!=
nil
{
return
*
m
.
Packed
}
return
false
}
func
(
m
*
FieldOptions
)
GetLazy
()
bool
{
if
m
!=
nil
&&
m
.
Lazy
!=
nil
{
return
*
m
.
Lazy
}
return
Default_FieldOptions_Lazy
}
func
(
m
*
FieldOptions
)
GetDeprecated
()
bool
{
if
m
!=
nil
&&
m
.
Deprecated
!=
nil
{
return
*
m
.
Deprecated
}
return
Default_FieldOptions_Deprecated
}
func
(
m
*
FieldOptions
)
GetWeak
()
bool
{
if
m
!=
nil
&&
m
.
Weak
!=
nil
{
return
*
m
.
Weak
}
return
Default_FieldOptions_Weak
}
func
(
m
*
FieldOptions
)
GetUninterpretedOption
()
[]
*
UninterpretedOption
{
if
m
!=
nil
{
return
m
.
UninterpretedOption
}
return
nil
}
type
EnumOptions
struct
{
// Set this option to true to allow mapping different tag names to the same
// value.
AllowAlias
*
bool
`protobuf:"varint,2,opt,name=allow_alias" json:"allow_alias,omitempty"`
// Is this enum deprecated?
// Depending on the target platform, this can emit Deprecated annotations
// for the enum, or it will be completely ignored; in the very least, this
// is a formalization for deprecating enums.
Deprecated
*
bool
`protobuf:"varint,3,opt,name=deprecated,def=0" json:"deprecated,omitempty"`
// The parser stores options it doesn't recognize here. See above.
UninterpretedOption
[]
*
UninterpretedOption
`protobuf:"bytes,999,rep,name=uninterpreted_option" json:"uninterpreted_option,omitempty"`
XXX_extensions
map
[
int32
]
proto
.
Extension
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
EnumOptions
)
Reset
()
{
*
m
=
EnumOptions
{}
}
func
(
m
*
EnumOptions
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
EnumOptions
)
ProtoMessage
()
{}
var
extRange_EnumOptions
=
[]
proto
.
ExtensionRange
{
{
1000
,
536870911
},
}
func
(
*
EnumOptions
)
ExtensionRangeArray
()
[]
proto
.
ExtensionRange
{
return
extRange_EnumOptions
}
func
(
m
*
EnumOptions
)
ExtensionMap
()
map
[
int32
]
proto
.
Extension
{
if
m
.
XXX_extensions
==
nil
{
m
.
XXX_extensions
=
make
(
map
[
int32
]
proto
.
Extension
)
}
return
m
.
XXX_extensions
}
const
Default_EnumOptions_Deprecated
bool
=
false
func
(
m
*
EnumOptions
)
GetAllowAlias
()
bool
{
if
m
!=
nil
&&
m
.
AllowAlias
!=
nil
{
return
*
m
.
AllowAlias
}
return
false
}
func
(
m
*
EnumOptions
)
GetDeprecated
()
bool
{
if
m
!=
nil
&&
m
.
Deprecated
!=
nil
{
return
*
m
.
Deprecated
}
return
Default_EnumOptions_Deprecated
}
func
(
m
*
EnumOptions
)
GetUninterpretedOption
()
[]
*
UninterpretedOption
{
if
m
!=
nil
{
return
m
.
UninterpretedOption
}
return
nil
}
type
EnumValueOptions
struct
{
// Is this enum value deprecated?
// Depending on the target platform, this can emit Deprecated annotations
// for the enum value, or it will be completely ignored; in the very least,
// this is a formalization for deprecating enum values.
Deprecated
*
bool
`protobuf:"varint,1,opt,name=deprecated,def=0" json:"deprecated,omitempty"`
// The parser stores options it doesn't recognize here. See above.
UninterpretedOption
[]
*
UninterpretedOption
`protobuf:"bytes,999,rep,name=uninterpreted_option" json:"uninterpreted_option,omitempty"`
XXX_extensions
map
[
int32
]
proto
.
Extension
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
EnumValueOptions
)
Reset
()
{
*
m
=
EnumValueOptions
{}
}
func
(
m
*
EnumValueOptions
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
EnumValueOptions
)
ProtoMessage
()
{}
var
extRange_EnumValueOptions
=
[]
proto
.
ExtensionRange
{
{
1000
,
536870911
},
}
func
(
*
EnumValueOptions
)
ExtensionRangeArray
()
[]
proto
.
ExtensionRange
{
return
extRange_EnumValueOptions
}
func
(
m
*
EnumValueOptions
)
ExtensionMap
()
map
[
int32
]
proto
.
Extension
{
if
m
.
XXX_extensions
==
nil
{
m
.
XXX_extensions
=
make
(
map
[
int32
]
proto
.
Extension
)
}
return
m
.
XXX_extensions
}
const
Default_EnumValueOptions_Deprecated
bool
=
false
func
(
m
*
EnumValueOptions
)
GetDeprecated
()
bool
{
if
m
!=
nil
&&
m
.
Deprecated
!=
nil
{
return
*
m
.
Deprecated
}
return
Default_EnumValueOptions_Deprecated
}
func
(
m
*
EnumValueOptions
)
GetUninterpretedOption
()
[]
*
UninterpretedOption
{
if
m
!=
nil
{
return
m
.
UninterpretedOption
}
return
nil
}
type
ServiceOptions
struct
{
// Is this service deprecated?
// Depending on the target platform, this can emit Deprecated annotations
// for the service, or it will be completely ignored; in the very least,
// this is a formalization for deprecating services.
Deprecated
*
bool
`protobuf:"varint,33,opt,name=deprecated,def=0" json:"deprecated,omitempty"`
// The parser stores options it doesn't recognize here. See above.
UninterpretedOption
[]
*
UninterpretedOption
`protobuf:"bytes,999,rep,name=uninterpreted_option" json:"uninterpreted_option,omitempty"`
XXX_extensions
map
[
int32
]
proto
.
Extension
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
ServiceOptions
)
Reset
()
{
*
m
=
ServiceOptions
{}
}
func
(
m
*
ServiceOptions
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
ServiceOptions
)
ProtoMessage
()
{}
var
extRange_ServiceOptions
=
[]
proto
.
ExtensionRange
{
{
1000
,
536870911
},
}
func
(
*
ServiceOptions
)
ExtensionRangeArray
()
[]
proto
.
ExtensionRange
{
return
extRange_ServiceOptions
}
func
(
m
*
ServiceOptions
)
ExtensionMap
()
map
[
int32
]
proto
.
Extension
{
if
m
.
XXX_extensions
==
nil
{
m
.
XXX_extensions
=
make
(
map
[
int32
]
proto
.
Extension
)
}
return
m
.
XXX_extensions
}
const
Default_ServiceOptions_Deprecated
bool
=
false
func
(
m
*
ServiceOptions
)
GetDeprecated
()
bool
{
if
m
!=
nil
&&
m
.
Deprecated
!=
nil
{
return
*
m
.
Deprecated
}
return
Default_ServiceOptions_Deprecated
}
func
(
m
*
ServiceOptions
)
GetUninterpretedOption
()
[]
*
UninterpretedOption
{
if
m
!=
nil
{
return
m
.
UninterpretedOption
}
return
nil
}
type
MethodOptions
struct
{
// Is this method deprecated?
// Depending on the target platform, this can emit Deprecated annotations
// for the method, or it will be completely ignored; in the very least,
// this is a formalization for deprecating methods.
Deprecated
*
bool
`protobuf:"varint,33,opt,name=deprecated,def=0" json:"deprecated,omitempty"`
// The parser stores options it doesn't recognize here. See above.
UninterpretedOption
[]
*
UninterpretedOption
`protobuf:"bytes,999,rep,name=uninterpreted_option" json:"uninterpreted_option,omitempty"`
XXX_extensions
map
[
int32
]
proto
.
Extension
`json:"-"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
MethodOptions
)
Reset
()
{
*
m
=
MethodOptions
{}
}
func
(
m
*
MethodOptions
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
MethodOptions
)
ProtoMessage
()
{}
var
extRange_MethodOptions
=
[]
proto
.
ExtensionRange
{
{
1000
,
536870911
},
}
func
(
*
MethodOptions
)
ExtensionRangeArray
()
[]
proto
.
ExtensionRange
{
return
extRange_MethodOptions
}
func
(
m
*
MethodOptions
)
ExtensionMap
()
map
[
int32
]
proto
.
Extension
{
if
m
.
XXX_extensions
==
nil
{
m
.
XXX_extensions
=
make
(
map
[
int32
]
proto
.
Extension
)
}
return
m
.
XXX_extensions
}
const
Default_MethodOptions_Deprecated
bool
=
false
func
(
m
*
MethodOptions
)
GetDeprecated
()
bool
{
if
m
!=
nil
&&
m
.
Deprecated
!=
nil
{
return
*
m
.
Deprecated
}
return
Default_MethodOptions_Deprecated
}
func
(
m
*
MethodOptions
)
GetUninterpretedOption
()
[]
*
UninterpretedOption
{
if
m
!=
nil
{
return
m
.
UninterpretedOption
}
return
nil
}
// A message representing a option the parser does not recognize. This only
// appears in options protos created by the compiler::Parser class.
// DescriptorPool resolves these when building Descriptor objects. Therefore,
// options protos in descriptor objects (e.g. returned by Descriptor::options(),
// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
// in them.
type
UninterpretedOption
struct
{
Name
[]
*
UninterpretedOption_NamePart
`protobuf:"bytes,2,rep,name=name" json:"name,omitempty"`
// The value of the uninterpreted option, in whatever type the tokenizer
// identified it as during parsing. Exactly one of these should be set.
IdentifierValue
*
string
`protobuf:"bytes,3,opt,name=identifier_value" json:"identifier_value,omitempty"`
PositiveIntValue
*
uint64
`protobuf:"varint,4,opt,name=positive_int_value" json:"positive_int_value,omitempty"`
NegativeIntValue
*
int64
`protobuf:"varint,5,opt,name=negative_int_value" json:"negative_int_value,omitempty"`
DoubleValue
*
float64
`protobuf:"fixed64,6,opt,name=double_value" json:"double_value,omitempty"`
StringValue
[]
byte
`protobuf:"bytes,7,opt,name=string_value" json:"string_value,omitempty"`
AggregateValue
*
string
`protobuf:"bytes,8,opt,name=aggregate_value" json:"aggregate_value,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
UninterpretedOption
)
Reset
()
{
*
m
=
UninterpretedOption
{}
}
func
(
m
*
UninterpretedOption
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
UninterpretedOption
)
ProtoMessage
()
{}
func
(
m
*
UninterpretedOption
)
GetName
()
[]
*
UninterpretedOption_NamePart
{
if
m
!=
nil
{
return
m
.
Name
}
return
nil
}
func
(
m
*
UninterpretedOption
)
GetIdentifierValue
()
string
{
if
m
!=
nil
&&
m
.
IdentifierValue
!=
nil
{
return
*
m
.
IdentifierValue
}
return
""
}
func
(
m
*
UninterpretedOption
)
GetPositiveIntValue
()
uint64
{
if
m
!=
nil
&&
m
.
PositiveIntValue
!=
nil
{
return
*
m
.
PositiveIntValue
}
return
0
}
func
(
m
*
UninterpretedOption
)
GetNegativeIntValue
()
int64
{
if
m
!=
nil
&&
m
.
NegativeIntValue
!=
nil
{
return
*
m
.
NegativeIntValue
}
return
0
}
func
(
m
*
UninterpretedOption
)
GetDoubleValue
()
float64
{
if
m
!=
nil
&&
m
.
DoubleValue
!=
nil
{
return
*
m
.
DoubleValue
}
return
0
}
func
(
m
*
UninterpretedOption
)
GetStringValue
()
[]
byte
{
if
m
!=
nil
{
return
m
.
StringValue
}
return
nil
}
func
(
m
*
UninterpretedOption
)
GetAggregateValue
()
string
{
if
m
!=
nil
&&
m
.
AggregateValue
!=
nil
{
return
*
m
.
AggregateValue
}
return
""
}
// The name of the uninterpreted option. Each string represents a segment in
// a dot-separated name. is_extension is true iff a segment represents an
// extension (denoted with parentheses in options specs in .proto files).
// E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
// "foo.(bar.baz).qux".
type
UninterpretedOption_NamePart
struct
{
NamePart
*
string
`protobuf:"bytes,1,req,name=name_part" json:"name_part,omitempty"`
IsExtension
*
bool
`protobuf:"varint,2,req,name=is_extension" json:"is_extension,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
UninterpretedOption_NamePart
)
Reset
()
{
*
m
=
UninterpretedOption_NamePart
{}
}
func
(
m
*
UninterpretedOption_NamePart
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
UninterpretedOption_NamePart
)
ProtoMessage
()
{}
func
(
m
*
UninterpretedOption_NamePart
)
GetNamePart
()
string
{
if
m
!=
nil
&&
m
.
NamePart
!=
nil
{
return
*
m
.
NamePart
}
return
""
}
func
(
m
*
UninterpretedOption_NamePart
)
GetIsExtension
()
bool
{
if
m
!=
nil
&&
m
.
IsExtension
!=
nil
{
return
*
m
.
IsExtension
}
return
false
}
// Encapsulates information about the original source file from which a
// FileDescriptorProto was generated.
type
SourceCodeInfo
struct
{
// A Location identifies a piece of source code in a .proto file which
// corresponds to a particular definition. This information is intended
// to be useful to IDEs, code indexers, documentation generators, and similar
// tools.
//
// For example, say we have a file like:
// message Foo {
// optional string foo = 1;
// }
// Let's look at just the field definition:
// optional string foo = 1;
// ^ ^^ ^^ ^ ^^^
// a bc de f ghi
// We have the following locations:
// span path represents
// [a,i) [ 4, 0, 2, 0 ] The whole field definition.
// [a,b) [ 4, 0, 2, 0, 4 ] The label (optional).
// [c,d) [ 4, 0, 2, 0, 5 ] The type (string).
// [e,f) [ 4, 0, 2, 0, 1 ] The name (foo).
// [g,h) [ 4, 0, 2, 0, 3 ] The number (1).
//
// Notes:
// - A location may refer to a repeated field itself (i.e. not to any
// particular index within it). This is used whenever a set of elements are
// logically enclosed in a single code segment. For example, an entire
// extend block (possibly containing multiple extension definitions) will
// have an outer location whose path refers to the "extensions" repeated
// field without an index.
// - Multiple locations may have the same path. This happens when a single
// logical declaration is spread out across multiple places. The most
// obvious example is the "extend" block again -- there may be multiple
// extend blocks in the same scope, each of which will have the same path.
// - A location's span is not always a subset of its parent's span. For
// example, the "extendee" of an extension declaration appears at the
// beginning of the "extend" block and is shared by all extensions within
// the block.
// - Just because a location's span is a subset of some other location's span
// does not mean that it is a descendent. For example, a "group" defines
// both a type and a field in a single declaration. Thus, the locations
// corresponding to the type and field and their components will overlap.
// - Code which tries to interpret locations should probably be designed to
// ignore those that it doesn't understand, as more types of locations could
// be recorded in the future.
Location
[]
*
SourceCodeInfo_Location
`protobuf:"bytes,1,rep,name=location" json:"location,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
SourceCodeInfo
)
Reset
()
{
*
m
=
SourceCodeInfo
{}
}
func
(
m
*
SourceCodeInfo
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
SourceCodeInfo
)
ProtoMessage
()
{}
func
(
m
*
SourceCodeInfo
)
GetLocation
()
[]
*
SourceCodeInfo_Location
{
if
m
!=
nil
{
return
m
.
Location
}
return
nil
}
type
SourceCodeInfo_Location
struct
{
// Identifies which part of the FileDescriptorProto was defined at this
// location.
//
// Each element is a field number or an index. They form a path from
// the root FileDescriptorProto to the place where the definition. For
// example, this path:
// [ 4, 3, 2, 7, 1 ]
// refers to:
// file.message_type(3) // 4, 3
// .field(7) // 2, 7
// .name() // 1
// This is because FileDescriptorProto.message_type has field number 4:
// repeated DescriptorProto message_type = 4;
// and DescriptorProto.field has field number 2:
// repeated FieldDescriptorProto field = 2;
// and FieldDescriptorProto.name has field number 1:
// optional string name = 1;
//
// Thus, the above path gives the location of a field name. If we removed
// the last element:
// [ 4, 3, 2, 7 ]
// this path refers to the whole field declaration (from the beginning
// of the label to the terminating semicolon).
Path
[]
int32
`protobuf:"varint,1,rep,packed,name=path" json:"path,omitempty"`
// Always has exactly three or four elements: start line, start column,
// end line (optional, otherwise assumed same as start line), end column.
// These are packed into a single field for efficiency. Note that line
// and column numbers are zero-based -- typically you will want to add
// 1 to each before displaying to a user.
Span
[]
int32
`protobuf:"varint,2,rep,packed,name=span" json:"span,omitempty"`
// If this SourceCodeInfo represents a complete declaration, these are any
// comments appearing before and after the declaration which appear to be
// attached to the declaration.
//
// A series of line comments appearing on consecutive lines, with no other
// tokens appearing on those lines, will be treated as a single comment.
//
// Only the comment content is provided; comment markers (e.g. //) are
// stripped out. For block comments, leading whitespace and an asterisk
// will be stripped from the beginning of each line other than the first.
// Newlines are included in the output.
//
// Examples:
//
// optional int32 foo = 1; // Comment attached to foo.
// // Comment attached to bar.
// optional int32 bar = 2;
//
// optional string baz = 3;
// // Comment attached to baz.
// // Another line attached to baz.
//
// // Comment attached to qux.
// //
// // Another line attached to qux.
// optional double qux = 4;
//
// optional string corge = 5;
// /* Block comment attached
// * to corge. Leading asterisks
// * will be removed. */
// /* Block comment attached to
// * grault. */
// optional int32 grault = 6;
LeadingComments
*
string
`protobuf:"bytes,3,opt,name=leading_comments" json:"leading_comments,omitempty"`
TrailingComments
*
string
`protobuf:"bytes,4,opt,name=trailing_comments" json:"trailing_comments,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
SourceCodeInfo_Location
)
Reset
()
{
*
m
=
SourceCodeInfo_Location
{}
}
func
(
m
*
SourceCodeInfo_Location
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
SourceCodeInfo_Location
)
ProtoMessage
()
{}
func
(
m
*
SourceCodeInfo_Location
)
GetPath
()
[]
int32
{
if
m
!=
nil
{
return
m
.
Path
}
return
nil
}
func
(
m
*
SourceCodeInfo_Location
)
GetSpan
()
[]
int32
{
if
m
!=
nil
{
return
m
.
Span
}
return
nil
}
func
(
m
*
SourceCodeInfo_Location
)
GetLeadingComments
()
string
{
if
m
!=
nil
&&
m
.
LeadingComments
!=
nil
{
return
*
m
.
LeadingComments
}
return
""
}
func
(
m
*
SourceCodeInfo_Location
)
GetTrailingComments
()
string
{
if
m
!=
nil
&&
m
.
TrailingComments
!=
nil
{
return
*
m
.
TrailingComments
}
return
""
}
func
init
()
{
proto
.
RegisterEnum
(
"google.protobuf.FieldDescriptorProto_Type"
,
FieldDescriptorProto_Type_name
,
FieldDescriptorProto_Type_value
)
proto
.
RegisterEnum
(
"google.protobuf.FieldDescriptorProto_Label"
,
FieldDescriptorProto_Label_name
,
FieldDescriptorProto_Label_value
)
proto
.
RegisterEnum
(
"google.protobuf.FileOptions_OptimizeMode"
,
FileOptions_OptimizeMode_name
,
FileOptions_OptimizeMode_value
)
proto
.
RegisterEnum
(
"google.protobuf.FieldOptions_CType"
,
FieldOptions_CType_name
,
FieldOptions_CType_value
)
}
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/descriptor/gostring.go
0 → 100644
View file @
8f79df77
package
google_protobuf
import
fmt
"fmt"
import
strings
"strings"
import
github_com_gogo_protobuf_proto
"QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/proto"
import
sort
"sort"
import
strconv
"strconv"
import
reflect
"reflect"
func
(
this
*
FileDescriptorSet
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
5
)
s
=
append
(
s
,
"&google_protobuf.FileDescriptorSet{"
)
if
this
.
File
!=
nil
{
s
=
append
(
s
,
"File: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
File
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
FileDescriptorProto
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
16
)
s
=
append
(
s
,
"&google_protobuf.FileDescriptorProto{"
)
if
this
.
Name
!=
nil
{
s
=
append
(
s
,
"Name: "
+
valueToGoStringDescriptor
(
this
.
Name
,
"string"
)
+
",
\n
"
)
}
if
this
.
Package
!=
nil
{
s
=
append
(
s
,
"Package: "
+
valueToGoStringDescriptor
(
this
.
Package
,
"string"
)
+
",
\n
"
)
}
if
this
.
Dependency
!=
nil
{
s
=
append
(
s
,
"Dependency: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Dependency
)
+
",
\n
"
)
}
if
this
.
PublicDependency
!=
nil
{
s
=
append
(
s
,
"PublicDependency: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
PublicDependency
)
+
",
\n
"
)
}
if
this
.
WeakDependency
!=
nil
{
s
=
append
(
s
,
"WeakDependency: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
WeakDependency
)
+
",
\n
"
)
}
if
this
.
MessageType
!=
nil
{
s
=
append
(
s
,
"MessageType: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
MessageType
)
+
",
\n
"
)
}
if
this
.
EnumType
!=
nil
{
s
=
append
(
s
,
"EnumType: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
EnumType
)
+
",
\n
"
)
}
if
this
.
Service
!=
nil
{
s
=
append
(
s
,
"Service: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Service
)
+
",
\n
"
)
}
if
this
.
Extension
!=
nil
{
s
=
append
(
s
,
"Extension: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Extension
)
+
",
\n
"
)
}
if
this
.
Options
!=
nil
{
s
=
append
(
s
,
"Options: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Options
)
+
",
\n
"
)
}
if
this
.
SourceCodeInfo
!=
nil
{
s
=
append
(
s
,
"SourceCodeInfo: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
SourceCodeInfo
)
+
",
\n
"
)
}
if
this
.
Syntax
!=
nil
{
s
=
append
(
s
,
"Syntax: "
+
valueToGoStringDescriptor
(
this
.
Syntax
,
"string"
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
DescriptorProto
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
12
)
s
=
append
(
s
,
"&google_protobuf.DescriptorProto{"
)
if
this
.
Name
!=
nil
{
s
=
append
(
s
,
"Name: "
+
valueToGoStringDescriptor
(
this
.
Name
,
"string"
)
+
",
\n
"
)
}
if
this
.
Field
!=
nil
{
s
=
append
(
s
,
"Field: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Field
)
+
",
\n
"
)
}
if
this
.
Extension
!=
nil
{
s
=
append
(
s
,
"Extension: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Extension
)
+
",
\n
"
)
}
if
this
.
NestedType
!=
nil
{
s
=
append
(
s
,
"NestedType: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
NestedType
)
+
",
\n
"
)
}
if
this
.
EnumType
!=
nil
{
s
=
append
(
s
,
"EnumType: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
EnumType
)
+
",
\n
"
)
}
if
this
.
ExtensionRange
!=
nil
{
s
=
append
(
s
,
"ExtensionRange: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
ExtensionRange
)
+
",
\n
"
)
}
if
this
.
OneofDecl
!=
nil
{
s
=
append
(
s
,
"OneofDecl: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
OneofDecl
)
+
",
\n
"
)
}
if
this
.
Options
!=
nil
{
s
=
append
(
s
,
"Options: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Options
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
DescriptorProto_ExtensionRange
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
6
)
s
=
append
(
s
,
"&google_protobuf.DescriptorProto_ExtensionRange{"
)
if
this
.
Start
!=
nil
{
s
=
append
(
s
,
"Start: "
+
valueToGoStringDescriptor
(
this
.
Start
,
"int32"
)
+
",
\n
"
)
}
if
this
.
End
!=
nil
{
s
=
append
(
s
,
"End: "
+
valueToGoStringDescriptor
(
this
.
End
,
"int32"
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
FieldDescriptorProto
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
13
)
s
=
append
(
s
,
"&google_protobuf.FieldDescriptorProto{"
)
if
this
.
Name
!=
nil
{
s
=
append
(
s
,
"Name: "
+
valueToGoStringDescriptor
(
this
.
Name
,
"string"
)
+
",
\n
"
)
}
if
this
.
Number
!=
nil
{
s
=
append
(
s
,
"Number: "
+
valueToGoStringDescriptor
(
this
.
Number
,
"int32"
)
+
",
\n
"
)
}
if
this
.
Label
!=
nil
{
s
=
append
(
s
,
"Label: "
+
valueToGoStringDescriptor
(
this
.
Label
,
"google_protobuf.FieldDescriptorProto_Label"
)
+
",
\n
"
)
}
if
this
.
Type
!=
nil
{
s
=
append
(
s
,
"Type: "
+
valueToGoStringDescriptor
(
this
.
Type
,
"google_protobuf.FieldDescriptorProto_Type"
)
+
",
\n
"
)
}
if
this
.
TypeName
!=
nil
{
s
=
append
(
s
,
"TypeName: "
+
valueToGoStringDescriptor
(
this
.
TypeName
,
"string"
)
+
",
\n
"
)
}
if
this
.
Extendee
!=
nil
{
s
=
append
(
s
,
"Extendee: "
+
valueToGoStringDescriptor
(
this
.
Extendee
,
"string"
)
+
",
\n
"
)
}
if
this
.
DefaultValue
!=
nil
{
s
=
append
(
s
,
"DefaultValue: "
+
valueToGoStringDescriptor
(
this
.
DefaultValue
,
"string"
)
+
",
\n
"
)
}
if
this
.
OneofIndex
!=
nil
{
s
=
append
(
s
,
"OneofIndex: "
+
valueToGoStringDescriptor
(
this
.
OneofIndex
,
"int32"
)
+
",
\n
"
)
}
if
this
.
Options
!=
nil
{
s
=
append
(
s
,
"Options: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Options
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
OneofDescriptorProto
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
5
)
s
=
append
(
s
,
"&google_protobuf.OneofDescriptorProto{"
)
if
this
.
Name
!=
nil
{
s
=
append
(
s
,
"Name: "
+
valueToGoStringDescriptor
(
this
.
Name
,
"string"
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
EnumDescriptorProto
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
7
)
s
=
append
(
s
,
"&google_protobuf.EnumDescriptorProto{"
)
if
this
.
Name
!=
nil
{
s
=
append
(
s
,
"Name: "
+
valueToGoStringDescriptor
(
this
.
Name
,
"string"
)
+
",
\n
"
)
}
if
this
.
Value
!=
nil
{
s
=
append
(
s
,
"Value: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Value
)
+
",
\n
"
)
}
if
this
.
Options
!=
nil
{
s
=
append
(
s
,
"Options: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Options
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
EnumValueDescriptorProto
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
7
)
s
=
append
(
s
,
"&google_protobuf.EnumValueDescriptorProto{"
)
if
this
.
Name
!=
nil
{
s
=
append
(
s
,
"Name: "
+
valueToGoStringDescriptor
(
this
.
Name
,
"string"
)
+
",
\n
"
)
}
if
this
.
Number
!=
nil
{
s
=
append
(
s
,
"Number: "
+
valueToGoStringDescriptor
(
this
.
Number
,
"int32"
)
+
",
\n
"
)
}
if
this
.
Options
!=
nil
{
s
=
append
(
s
,
"Options: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Options
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
ServiceDescriptorProto
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
7
)
s
=
append
(
s
,
"&google_protobuf.ServiceDescriptorProto{"
)
if
this
.
Name
!=
nil
{
s
=
append
(
s
,
"Name: "
+
valueToGoStringDescriptor
(
this
.
Name
,
"string"
)
+
",
\n
"
)
}
if
this
.
Method
!=
nil
{
s
=
append
(
s
,
"Method: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Method
)
+
",
\n
"
)
}
if
this
.
Options
!=
nil
{
s
=
append
(
s
,
"Options: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Options
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
MethodDescriptorProto
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
10
)
s
=
append
(
s
,
"&google_protobuf.MethodDescriptorProto{"
)
if
this
.
Name
!=
nil
{
s
=
append
(
s
,
"Name: "
+
valueToGoStringDescriptor
(
this
.
Name
,
"string"
)
+
",
\n
"
)
}
if
this
.
InputType
!=
nil
{
s
=
append
(
s
,
"InputType: "
+
valueToGoStringDescriptor
(
this
.
InputType
,
"string"
)
+
",
\n
"
)
}
if
this
.
OutputType
!=
nil
{
s
=
append
(
s
,
"OutputType: "
+
valueToGoStringDescriptor
(
this
.
OutputType
,
"string"
)
+
",
\n
"
)
}
if
this
.
Options
!=
nil
{
s
=
append
(
s
,
"Options: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Options
)
+
",
\n
"
)
}
if
this
.
ClientStreaming
!=
nil
{
s
=
append
(
s
,
"ClientStreaming: "
+
valueToGoStringDescriptor
(
this
.
ClientStreaming
,
"bool"
)
+
",
\n
"
)
}
if
this
.
ServerStreaming
!=
nil
{
s
=
append
(
s
,
"ServerStreaming: "
+
valueToGoStringDescriptor
(
this
.
ServerStreaming
,
"bool"
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
FileOptions
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
17
)
s
=
append
(
s
,
"&google_protobuf.FileOptions{"
)
if
this
.
JavaPackage
!=
nil
{
s
=
append
(
s
,
"JavaPackage: "
+
valueToGoStringDescriptor
(
this
.
JavaPackage
,
"string"
)
+
",
\n
"
)
}
if
this
.
JavaOuterClassname
!=
nil
{
s
=
append
(
s
,
"JavaOuterClassname: "
+
valueToGoStringDescriptor
(
this
.
JavaOuterClassname
,
"string"
)
+
",
\n
"
)
}
if
this
.
JavaMultipleFiles
!=
nil
{
s
=
append
(
s
,
"JavaMultipleFiles: "
+
valueToGoStringDescriptor
(
this
.
JavaMultipleFiles
,
"bool"
)
+
",
\n
"
)
}
if
this
.
JavaGenerateEqualsAndHash
!=
nil
{
s
=
append
(
s
,
"JavaGenerateEqualsAndHash: "
+
valueToGoStringDescriptor
(
this
.
JavaGenerateEqualsAndHash
,
"bool"
)
+
",
\n
"
)
}
if
this
.
JavaStringCheckUtf8
!=
nil
{
s
=
append
(
s
,
"JavaStringCheckUtf8: "
+
valueToGoStringDescriptor
(
this
.
JavaStringCheckUtf8
,
"bool"
)
+
",
\n
"
)
}
if
this
.
OptimizeFor
!=
nil
{
s
=
append
(
s
,
"OptimizeFor: "
+
valueToGoStringDescriptor
(
this
.
OptimizeFor
,
"google_protobuf.FileOptions_OptimizeMode"
)
+
",
\n
"
)
}
if
this
.
GoPackage
!=
nil
{
s
=
append
(
s
,
"GoPackage: "
+
valueToGoStringDescriptor
(
this
.
GoPackage
,
"string"
)
+
",
\n
"
)
}
if
this
.
CcGenericServices
!=
nil
{
s
=
append
(
s
,
"CcGenericServices: "
+
valueToGoStringDescriptor
(
this
.
CcGenericServices
,
"bool"
)
+
",
\n
"
)
}
if
this
.
JavaGenericServices
!=
nil
{
s
=
append
(
s
,
"JavaGenericServices: "
+
valueToGoStringDescriptor
(
this
.
JavaGenericServices
,
"bool"
)
+
",
\n
"
)
}
if
this
.
PyGenericServices
!=
nil
{
s
=
append
(
s
,
"PyGenericServices: "
+
valueToGoStringDescriptor
(
this
.
PyGenericServices
,
"bool"
)
+
",
\n
"
)
}
if
this
.
Deprecated
!=
nil
{
s
=
append
(
s
,
"Deprecated: "
+
valueToGoStringDescriptor
(
this
.
Deprecated
,
"bool"
)
+
",
\n
"
)
}
if
this
.
CcEnableArenas
!=
nil
{
s
=
append
(
s
,
"CcEnableArenas: "
+
valueToGoStringDescriptor
(
this
.
CcEnableArenas
,
"bool"
)
+
",
\n
"
)
}
if
this
.
UninterpretedOption
!=
nil
{
s
=
append
(
s
,
"UninterpretedOption: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
UninterpretedOption
)
+
",
\n
"
)
}
if
this
.
XXX_extensions
!=
nil
{
s
=
append
(
s
,
"XXX_extensions: "
+
extensionToGoStringDescriptor
(
this
.
XXX_extensions
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
MessageOptions
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
9
)
s
=
append
(
s
,
"&google_protobuf.MessageOptions{"
)
if
this
.
MessageSetWireFormat
!=
nil
{
s
=
append
(
s
,
"MessageSetWireFormat: "
+
valueToGoStringDescriptor
(
this
.
MessageSetWireFormat
,
"bool"
)
+
",
\n
"
)
}
if
this
.
NoStandardDescriptorAccessor
!=
nil
{
s
=
append
(
s
,
"NoStandardDescriptorAccessor: "
+
valueToGoStringDescriptor
(
this
.
NoStandardDescriptorAccessor
,
"bool"
)
+
",
\n
"
)
}
if
this
.
Deprecated
!=
nil
{
s
=
append
(
s
,
"Deprecated: "
+
valueToGoStringDescriptor
(
this
.
Deprecated
,
"bool"
)
+
",
\n
"
)
}
if
this
.
MapEntry
!=
nil
{
s
=
append
(
s
,
"MapEntry: "
+
valueToGoStringDescriptor
(
this
.
MapEntry
,
"bool"
)
+
",
\n
"
)
}
if
this
.
UninterpretedOption
!=
nil
{
s
=
append
(
s
,
"UninterpretedOption: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
UninterpretedOption
)
+
",
\n
"
)
}
if
this
.
XXX_extensions
!=
nil
{
s
=
append
(
s
,
"XXX_extensions: "
+
extensionToGoStringDescriptor
(
this
.
XXX_extensions
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
FieldOptions
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
10
)
s
=
append
(
s
,
"&google_protobuf.FieldOptions{"
)
if
this
.
Ctype
!=
nil
{
s
=
append
(
s
,
"Ctype: "
+
valueToGoStringDescriptor
(
this
.
Ctype
,
"google_protobuf.FieldOptions_CType"
)
+
",
\n
"
)
}
if
this
.
Packed
!=
nil
{
s
=
append
(
s
,
"Packed: "
+
valueToGoStringDescriptor
(
this
.
Packed
,
"bool"
)
+
",
\n
"
)
}
if
this
.
Lazy
!=
nil
{
s
=
append
(
s
,
"Lazy: "
+
valueToGoStringDescriptor
(
this
.
Lazy
,
"bool"
)
+
",
\n
"
)
}
if
this
.
Deprecated
!=
nil
{
s
=
append
(
s
,
"Deprecated: "
+
valueToGoStringDescriptor
(
this
.
Deprecated
,
"bool"
)
+
",
\n
"
)
}
if
this
.
Weak
!=
nil
{
s
=
append
(
s
,
"Weak: "
+
valueToGoStringDescriptor
(
this
.
Weak
,
"bool"
)
+
",
\n
"
)
}
if
this
.
UninterpretedOption
!=
nil
{
s
=
append
(
s
,
"UninterpretedOption: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
UninterpretedOption
)
+
",
\n
"
)
}
if
this
.
XXX_extensions
!=
nil
{
s
=
append
(
s
,
"XXX_extensions: "
+
extensionToGoStringDescriptor
(
this
.
XXX_extensions
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
EnumOptions
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
7
)
s
=
append
(
s
,
"&google_protobuf.EnumOptions{"
)
if
this
.
AllowAlias
!=
nil
{
s
=
append
(
s
,
"AllowAlias: "
+
valueToGoStringDescriptor
(
this
.
AllowAlias
,
"bool"
)
+
",
\n
"
)
}
if
this
.
Deprecated
!=
nil
{
s
=
append
(
s
,
"Deprecated: "
+
valueToGoStringDescriptor
(
this
.
Deprecated
,
"bool"
)
+
",
\n
"
)
}
if
this
.
UninterpretedOption
!=
nil
{
s
=
append
(
s
,
"UninterpretedOption: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
UninterpretedOption
)
+
",
\n
"
)
}
if
this
.
XXX_extensions
!=
nil
{
s
=
append
(
s
,
"XXX_extensions: "
+
extensionToGoStringDescriptor
(
this
.
XXX_extensions
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
EnumValueOptions
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
6
)
s
=
append
(
s
,
"&google_protobuf.EnumValueOptions{"
)
if
this
.
Deprecated
!=
nil
{
s
=
append
(
s
,
"Deprecated: "
+
valueToGoStringDescriptor
(
this
.
Deprecated
,
"bool"
)
+
",
\n
"
)
}
if
this
.
UninterpretedOption
!=
nil
{
s
=
append
(
s
,
"UninterpretedOption: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
UninterpretedOption
)
+
",
\n
"
)
}
if
this
.
XXX_extensions
!=
nil
{
s
=
append
(
s
,
"XXX_extensions: "
+
extensionToGoStringDescriptor
(
this
.
XXX_extensions
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
ServiceOptions
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
6
)
s
=
append
(
s
,
"&google_protobuf.ServiceOptions{"
)
if
this
.
Deprecated
!=
nil
{
s
=
append
(
s
,
"Deprecated: "
+
valueToGoStringDescriptor
(
this
.
Deprecated
,
"bool"
)
+
",
\n
"
)
}
if
this
.
UninterpretedOption
!=
nil
{
s
=
append
(
s
,
"UninterpretedOption: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
UninterpretedOption
)
+
",
\n
"
)
}
if
this
.
XXX_extensions
!=
nil
{
s
=
append
(
s
,
"XXX_extensions: "
+
extensionToGoStringDescriptor
(
this
.
XXX_extensions
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
MethodOptions
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
6
)
s
=
append
(
s
,
"&google_protobuf.MethodOptions{"
)
if
this
.
Deprecated
!=
nil
{
s
=
append
(
s
,
"Deprecated: "
+
valueToGoStringDescriptor
(
this
.
Deprecated
,
"bool"
)
+
",
\n
"
)
}
if
this
.
UninterpretedOption
!=
nil
{
s
=
append
(
s
,
"UninterpretedOption: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
UninterpretedOption
)
+
",
\n
"
)
}
if
this
.
XXX_extensions
!=
nil
{
s
=
append
(
s
,
"XXX_extensions: "
+
extensionToGoStringDescriptor
(
this
.
XXX_extensions
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
UninterpretedOption
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
11
)
s
=
append
(
s
,
"&google_protobuf.UninterpretedOption{"
)
if
this
.
Name
!=
nil
{
s
=
append
(
s
,
"Name: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Name
)
+
",
\n
"
)
}
if
this
.
IdentifierValue
!=
nil
{
s
=
append
(
s
,
"IdentifierValue: "
+
valueToGoStringDescriptor
(
this
.
IdentifierValue
,
"string"
)
+
",
\n
"
)
}
if
this
.
PositiveIntValue
!=
nil
{
s
=
append
(
s
,
"PositiveIntValue: "
+
valueToGoStringDescriptor
(
this
.
PositiveIntValue
,
"uint64"
)
+
",
\n
"
)
}
if
this
.
NegativeIntValue
!=
nil
{
s
=
append
(
s
,
"NegativeIntValue: "
+
valueToGoStringDescriptor
(
this
.
NegativeIntValue
,
"int64"
)
+
",
\n
"
)
}
if
this
.
DoubleValue
!=
nil
{
s
=
append
(
s
,
"DoubleValue: "
+
valueToGoStringDescriptor
(
this
.
DoubleValue
,
"float64"
)
+
",
\n
"
)
}
if
this
.
StringValue
!=
nil
{
s
=
append
(
s
,
"StringValue: "
+
valueToGoStringDescriptor
(
this
.
StringValue
,
"byte"
)
+
",
\n
"
)
}
if
this
.
AggregateValue
!=
nil
{
s
=
append
(
s
,
"AggregateValue: "
+
valueToGoStringDescriptor
(
this
.
AggregateValue
,
"string"
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
UninterpretedOption_NamePart
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
6
)
s
=
append
(
s
,
"&google_protobuf.UninterpretedOption_NamePart{"
)
if
this
.
NamePart
!=
nil
{
s
=
append
(
s
,
"NamePart: "
+
valueToGoStringDescriptor
(
this
.
NamePart
,
"string"
)
+
",
\n
"
)
}
if
this
.
IsExtension
!=
nil
{
s
=
append
(
s
,
"IsExtension: "
+
valueToGoStringDescriptor
(
this
.
IsExtension
,
"bool"
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
SourceCodeInfo
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
5
)
s
=
append
(
s
,
"&google_protobuf.SourceCodeInfo{"
)
if
this
.
Location
!=
nil
{
s
=
append
(
s
,
"Location: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Location
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
(
this
*
SourceCodeInfo_Location
)
GoString
()
string
{
if
this
==
nil
{
return
"nil"
}
s
:=
make
([]
string
,
0
,
8
)
s
=
append
(
s
,
"&google_protobuf.SourceCodeInfo_Location{"
)
if
this
.
Path
!=
nil
{
s
=
append
(
s
,
"Path: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Path
)
+
",
\n
"
)
}
if
this
.
Span
!=
nil
{
s
=
append
(
s
,
"Span: "
+
fmt
.
Sprintf
(
"%#v"
,
this
.
Span
)
+
",
\n
"
)
}
if
this
.
LeadingComments
!=
nil
{
s
=
append
(
s
,
"LeadingComments: "
+
valueToGoStringDescriptor
(
this
.
LeadingComments
,
"string"
)
+
",
\n
"
)
}
if
this
.
TrailingComments
!=
nil
{
s
=
append
(
s
,
"TrailingComments: "
+
valueToGoStringDescriptor
(
this
.
TrailingComments
,
"string"
)
+
",
\n
"
)
}
if
this
.
XXX_unrecognized
!=
nil
{
s
=
append
(
s
,
"XXX_unrecognized:"
+
fmt
.
Sprintf
(
"%#v"
,
this
.
XXX_unrecognized
)
+
",
\n
"
)
}
s
=
append
(
s
,
"}"
)
return
strings
.
Join
(
s
,
""
)
}
func
valueToGoStringDescriptor
(
v
interface
{},
typ
string
)
string
{
rv
:=
reflect
.
ValueOf
(
v
)
if
rv
.
IsNil
()
{
return
"nil"
}
pv
:=
reflect
.
Indirect
(
rv
)
.
Interface
()
return
fmt
.
Sprintf
(
"func(v %v) *%v { return &v } ( %#v )"
,
typ
,
typ
,
pv
)
}
func
extensionToGoStringDescriptor
(
e
map
[
int32
]
github_com_gogo_protobuf_proto
.
Extension
)
string
{
if
e
==
nil
{
return
"nil"
}
s
:=
"map[int32]proto.Extension{"
keys
:=
make
([]
int
,
0
,
len
(
e
))
for
k
:=
range
e
{
keys
=
append
(
keys
,
int
(
k
))
}
sort
.
Ints
(
keys
)
ss
:=
[]
string
{}
for
_
,
k
:=
range
keys
{
ss
=
append
(
ss
,
strconv
.
Itoa
(
k
)
+
": "
+
e
[
int32
(
k
)]
.
GoString
())
}
s
+=
strings
.
Join
(
ss
,
","
)
+
"}"
return
s
}
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/descriptor/helper.go
0 → 100644
View file @
8f79df77
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
// http://github.com/gogo/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package
google_protobuf
import
(
"strings"
)
func
(
msg
*
DescriptorProto
)
GetMapFields
()
(
*
FieldDescriptorProto
,
*
FieldDescriptorProto
)
{
if
!
msg
.
GetOptions
()
.
GetMapEntry
()
{
return
nil
,
nil
}
return
msg
.
GetField
()[
0
],
msg
.
GetField
()[
1
]
}
func
dotToUnderscore
(
r
rune
)
rune
{
if
r
==
'.'
{
return
'_'
}
return
r
}
func
(
field
*
FieldDescriptorProto
)
WireType
()
(
wire
int
)
{
switch
*
field
.
Type
{
case
FieldDescriptorProto_TYPE_DOUBLE
:
return
1
case
FieldDescriptorProto_TYPE_FLOAT
:
return
5
case
FieldDescriptorProto_TYPE_INT64
:
return
0
case
FieldDescriptorProto_TYPE_UINT64
:
return
0
case
FieldDescriptorProto_TYPE_INT32
:
return
0
case
FieldDescriptorProto_TYPE_UINT32
:
return
0
case
FieldDescriptorProto_TYPE_FIXED64
:
return
1
case
FieldDescriptorProto_TYPE_FIXED32
:
return
5
case
FieldDescriptorProto_TYPE_BOOL
:
return
0
case
FieldDescriptorProto_TYPE_STRING
:
return
2
case
FieldDescriptorProto_TYPE_GROUP
:
return
2
case
FieldDescriptorProto_TYPE_MESSAGE
:
return
2
case
FieldDescriptorProto_TYPE_BYTES
:
return
2
case
FieldDescriptorProto_TYPE_ENUM
:
return
0
case
FieldDescriptorProto_TYPE_SFIXED32
:
return
5
case
FieldDescriptorProto_TYPE_SFIXED64
:
return
1
case
FieldDescriptorProto_TYPE_SINT32
:
return
0
case
FieldDescriptorProto_TYPE_SINT64
:
return
0
}
panic
(
"unreachable"
)
}
func
(
field
*
FieldDescriptorProto
)
GetKeyUint64
()
(
x
uint64
)
{
packed
:=
field
.
IsPacked
()
wireType
:=
field
.
WireType
()
fieldNumber
:=
field
.
GetNumber
()
if
packed
{
wireType
=
2
}
x
=
uint64
(
uint32
(
fieldNumber
)
<<
3
|
uint32
(
wireType
))
return
x
}
func
(
field
*
FieldDescriptorProto
)
GetKey
()
[]
byte
{
x
:=
field
.
GetKeyUint64
()
i
:=
0
keybuf
:=
make
([]
byte
,
0
)
for
i
=
0
;
x
>
127
;
i
++
{
keybuf
=
append
(
keybuf
,
0x80
|
uint8
(
x
&
0x7F
))
x
>>=
7
}
keybuf
=
append
(
keybuf
,
uint8
(
x
))
return
keybuf
}
func
(
desc
*
FileDescriptorSet
)
GetField
(
packageName
,
messageName
,
fieldName
string
)
*
FieldDescriptorProto
{
msg
:=
desc
.
GetMessage
(
packageName
,
messageName
)
if
msg
==
nil
{
return
nil
}
for
_
,
field
:=
range
msg
.
GetField
()
{
if
field
.
GetName
()
==
fieldName
{
return
field
}
}
return
nil
}
func
(
file
*
FileDescriptorProto
)
GetMessage
(
typeName
string
)
*
DescriptorProto
{
for
_
,
msg
:=
range
file
.
GetMessageType
()
{
if
msg
.
GetName
()
==
typeName
{
return
msg
}
for
_
,
nes
:=
range
msg
.
GetNestedType
()
{
if
nes
.
GetName
()
==
typeName
{
return
nes
}
if
msg
.
GetName
()
+
"."
+
nes
.
GetName
()
==
typeName
{
return
nes
}
}
}
return
nil
}
func
(
desc
*
FileDescriptorSet
)
GetMessage
(
packageName
string
,
typeName
string
)
*
DescriptorProto
{
for
_
,
file
:=
range
desc
.
GetFile
()
{
if
strings
.
Map
(
dotToUnderscore
,
file
.
GetPackage
())
!=
strings
.
Map
(
dotToUnderscore
,
packageName
)
{
continue
}
for
_
,
msg
:=
range
file
.
GetMessageType
()
{
if
msg
.
GetName
()
==
typeName
{
return
msg
}
}
for
_
,
msg
:=
range
file
.
GetMessageType
()
{
for
_
,
nes
:=
range
msg
.
GetNestedType
()
{
if
nes
.
GetName
()
==
typeName
{
return
nes
}
if
msg
.
GetName
()
+
"."
+
nes
.
GetName
()
==
typeName
{
return
nes
}
}
}
}
return
nil
}
func
(
desc
*
FileDescriptorSet
)
IsProto3
(
packageName
string
,
typeName
string
)
bool
{
for
_
,
file
:=
range
desc
.
GetFile
()
{
if
strings
.
Map
(
dotToUnderscore
,
file
.
GetPackage
())
!=
strings
.
Map
(
dotToUnderscore
,
packageName
)
{
continue
}
for
_
,
msg
:=
range
file
.
GetMessageType
()
{
if
msg
.
GetName
()
==
typeName
{
return
file
.
GetSyntax
()
==
"proto3"
}
}
for
_
,
msg
:=
range
file
.
GetMessageType
()
{
for
_
,
nes
:=
range
msg
.
GetNestedType
()
{
if
nes
.
GetName
()
==
typeName
{
return
file
.
GetSyntax
()
==
"proto3"
}
if
msg
.
GetName
()
+
"."
+
nes
.
GetName
()
==
typeName
{
return
file
.
GetSyntax
()
==
"proto3"
}
}
}
}
return
false
}
func
(
msg
*
DescriptorProto
)
IsExtendable
()
bool
{
return
len
(
msg
.
GetExtensionRange
())
>
0
}
func
(
desc
*
FileDescriptorSet
)
FindExtension
(
packageName
string
,
typeName
string
,
fieldName
string
)
(
extPackageName
string
,
field
*
FieldDescriptorProto
)
{
parent
:=
desc
.
GetMessage
(
packageName
,
typeName
)
if
parent
==
nil
{
return
""
,
nil
}
if
!
parent
.
IsExtendable
()
{
return
""
,
nil
}
extendee
:=
"."
+
packageName
+
"."
+
typeName
for
_
,
file
:=
range
desc
.
GetFile
()
{
for
_
,
ext
:=
range
file
.
GetExtension
()
{
if
strings
.
Map
(
dotToUnderscore
,
file
.
GetPackage
())
==
strings
.
Map
(
dotToUnderscore
,
packageName
)
{
if
!
(
ext
.
GetExtendee
()
==
typeName
||
ext
.
GetExtendee
()
==
extendee
)
{
continue
}
}
else
{
if
ext
.
GetExtendee
()
!=
extendee
{
continue
}
}
if
ext
.
GetName
()
==
fieldName
{
return
file
.
GetPackage
(),
ext
}
}
}
return
""
,
nil
}
func
(
desc
*
FileDescriptorSet
)
FindExtensionByFieldNumber
(
packageName
string
,
typeName
string
,
fieldNum
int32
)
(
extPackageName
string
,
field
*
FieldDescriptorProto
)
{
parent
:=
desc
.
GetMessage
(
packageName
,
typeName
)
if
parent
==
nil
{
return
""
,
nil
}
if
!
parent
.
IsExtendable
()
{
return
""
,
nil
}
extendee
:=
"."
+
packageName
+
"."
+
typeName
for
_
,
file
:=
range
desc
.
GetFile
()
{
for
_
,
ext
:=
range
file
.
GetExtension
()
{
if
strings
.
Map
(
dotToUnderscore
,
file
.
GetPackage
())
==
strings
.
Map
(
dotToUnderscore
,
packageName
)
{
if
!
(
ext
.
GetExtendee
()
==
typeName
||
ext
.
GetExtendee
()
==
extendee
)
{
continue
}
}
else
{
if
ext
.
GetExtendee
()
!=
extendee
{
continue
}
}
if
ext
.
GetNumber
()
==
fieldNum
{
return
file
.
GetPackage
(),
ext
}
}
}
return
""
,
nil
}
func
(
desc
*
FileDescriptorSet
)
FindMessage
(
packageName
string
,
typeName
string
,
fieldName
string
)
(
msgPackageName
string
,
msgName
string
)
{
parent
:=
desc
.
GetMessage
(
packageName
,
typeName
)
if
parent
==
nil
{
return
""
,
""
}
field
:=
parent
.
GetFieldDescriptor
(
fieldName
)
if
field
==
nil
{
var
extPackageName
string
extPackageName
,
field
=
desc
.
FindExtension
(
packageName
,
typeName
,
fieldName
)
if
field
==
nil
{
return
""
,
""
}
packageName
=
extPackageName
}
typeNames
:=
strings
.
Split
(
field
.
GetTypeName
(),
"."
)
if
len
(
typeNames
)
==
1
{
msg
:=
desc
.
GetMessage
(
packageName
,
typeName
)
if
msg
==
nil
{
return
""
,
""
}
return
packageName
,
msg
.
GetName
()
}
if
len
(
typeNames
)
>
2
{
for
i
:=
1
;
i
<
len
(
typeNames
)
-
1
;
i
++
{
packageName
=
strings
.
Join
(
typeNames
[
1
:
len
(
typeNames
)
-
i
],
"."
)
typeName
=
strings
.
Join
(
typeNames
[
len
(
typeNames
)
-
i
:
],
"."
)
msg
:=
desc
.
GetMessage
(
packageName
,
typeName
)
if
msg
!=
nil
{
typeNames
:=
strings
.
Split
(
msg
.
GetName
(),
"."
)
if
len
(
typeNames
)
==
1
{
return
packageName
,
msg
.
GetName
()
}
return
strings
.
Join
(
typeNames
[
1
:
len
(
typeNames
)
-
1
],
"."
),
typeNames
[
len
(
typeNames
)
-
1
]
}
}
}
return
""
,
""
}
func
(
msg
*
DescriptorProto
)
GetFieldDescriptor
(
fieldName
string
)
*
FieldDescriptorProto
{
for
_
,
field
:=
range
msg
.
GetField
()
{
if
field
.
GetName
()
==
fieldName
{
return
field
}
}
return
nil
}
func
(
desc
*
FileDescriptorSet
)
GetEnum
(
packageName
string
,
typeName
string
)
*
EnumDescriptorProto
{
for
_
,
file
:=
range
desc
.
GetFile
()
{
if
strings
.
Map
(
dotToUnderscore
,
file
.
GetPackage
())
!=
strings
.
Map
(
dotToUnderscore
,
packageName
)
{
continue
}
for
_
,
enum
:=
range
file
.
GetEnumType
()
{
if
enum
.
GetName
()
==
typeName
{
return
enum
}
}
}
return
nil
}
func
(
f
*
FieldDescriptorProto
)
IsEnum
()
bool
{
return
*
f
.
Type
==
FieldDescriptorProto_TYPE_ENUM
}
func
(
f
*
FieldDescriptorProto
)
IsMessage
()
bool
{
return
*
f
.
Type
==
FieldDescriptorProto_TYPE_MESSAGE
}
func
(
f
*
FieldDescriptorProto
)
IsBytes
()
bool
{
return
*
f
.
Type
==
FieldDescriptorProto_TYPE_BYTES
}
func
(
f
*
FieldDescriptorProto
)
IsRepeated
()
bool
{
return
f
.
Label
!=
nil
&&
*
f
.
Label
==
FieldDescriptorProto_LABEL_REPEATED
}
func
(
f
*
FieldDescriptorProto
)
IsString
()
bool
{
return
*
f
.
Type
==
FieldDescriptorProto_TYPE_STRING
}
func
(
f
*
FieldDescriptorProto
)
IsRequired
()
bool
{
return
f
.
Label
!=
nil
&&
*
f
.
Label
==
FieldDescriptorProto_LABEL_REQUIRED
}
func
(
f
*
FieldDescriptorProto
)
IsPacked
()
bool
{
return
f
.
Options
!=
nil
&&
f
.
GetOptions
()
.
GetPacked
()
}
func
(
m
*
DescriptorProto
)
HasExtension
()
bool
{
return
len
(
m
.
ExtensionRange
)
>
0
}
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/doc.go
0 → 100644
View file @
8f79df77
// Go support for Protocol Buffers - Google's data interchange format
//
// Copyright 2010 The Go Authors. All rights reserved.
// https://github.com/golang/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/*
A plugin for the Google protocol buffer compiler to generate Go code.
Run it by building this program and putting it in your path with the name
protoc-gen-gogo
That word 'gogo' at the end becomes part of the option string set for the
protocol compiler, so once the protocol compiler (protoc) is installed
you can run
protoc --gogo_out=output_directory input_directory/file.proto
to generate Go bindings for the protocol defined by file.proto.
With that input, the output will be written to
output_directory/go_package/file.pb.go
The generated code is documented in the package comment for
the library.
See the README and documentation for protocol buffers to learn more:
https://developers.google.com/protocol-buffers/
*/
package
documentation
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/generator/generator.go
0 → 100644
View file @
8f79df77
// Extensions for Protocol Buffers to create more go like structures.
//
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
// http://github.com/gogo/protobuf/gogoproto
//
// Go support for Protocol Buffers - Google's data interchange format
//
// Copyright 2010 The Go Authors. All rights reserved.
// https://github.com/golang/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
/*
The code generator for the plugin for the Google protocol buffer compiler.
It generates Go code from the protocol buffer description files read by the
main routine.
*/
package
generator
import
(
"bufio"
"bytes"
"fmt"
"go/parser"
"go/printer"
"go/token"
"log"
"os"
"path"
"sort"
"strconv"
"strings"
"unicode"
"unicode/utf8"
"QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/gogoproto"
"QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/proto"
descriptor
"QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/descriptor"
plugin
"QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/plugin"
)
// A Plugin provides functionality to add to the output during Go code generation,
// such as to produce RPC stubs.
type
Plugin
interface
{
// Name identifies the plugin.
Name
()
string
// Init is called once after data structures are built but before
// code generation begins.
Init
(
g
*
Generator
)
// Generate produces the code generated by the plugin for this file,
// except for the imports, by calling the generator's methods P, In, and Out.
Generate
(
file
*
FileDescriptor
)
// GenerateImports produces the import declarations for this file.
// It is called after Generate.
GenerateImports
(
file
*
FileDescriptor
)
}
type
pluginSlice
[]
Plugin
func
(
ps
pluginSlice
)
Len
()
int
{
return
len
(
ps
)
}
func
(
ps
pluginSlice
)
Less
(
i
,
j
int
)
bool
{
return
ps
[
i
]
.
Name
()
<
ps
[
j
]
.
Name
()
}
func
(
ps
pluginSlice
)
Swap
(
i
,
j
int
)
{
ps
[
i
],
ps
[
j
]
=
ps
[
j
],
ps
[
i
]
}
var
plugins
pluginSlice
// RegisterPlugin installs a (second-order) plugin to be run when the Go output is generated.
// It is typically called during initialization.
func
RegisterPlugin
(
p
Plugin
)
{
plugins
=
append
(
plugins
,
p
)
}
// 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
*
descriptor
.
FileDescriptorProto
// File this object comes from.
}
// PackageName is name in the package clause in the generated file.
func
(
c
*
common
)
PackageName
()
string
{
return
uniquePackageOf
(
c
.
file
)
}
func
(
c
*
common
)
File
()
*
descriptor
.
FileDescriptorProto
{
return
c
.
file
}
func
fileIsProto3
(
file
*
descriptor
.
FileDescriptorProto
)
bool
{
return
file
.
GetSyntax
()
==
"proto3"
}
func
(
c
*
common
)
proto3
()
bool
{
return
fileIsProto3
(
c
.
file
)
}
// Descriptor represents a protocol buffer message.
type
Descriptor
struct
{
common
*
descriptor
.
DescriptorProto
parent
*
Descriptor
// The containing message, if any.
nested
[]
*
Descriptor
// Inner messages, if any.
enums
[]
*
EnumDescriptor
// Inner enums, if any.
ext
[]
*
ExtensionDescriptor
// Extensions, if any.
typename
[]
string
// Cached typename vector.
index
int
// The index into the container, whether the file or another message.
path
string
// The SourceCodeInfo path as comma-separated integers.
group
bool
}
// TypeName returns the elements of the dotted type name.
// The package name is not part of this name.
func
(
d
*
Descriptor
)
TypeName
()
[]
string
{
if
d
.
typename
!=
nil
{
return
d
.
typename
}
n
:=
0
for
parent
:=
d
;
parent
!=
nil
;
parent
=
parent
.
parent
{
n
++
}
s
:=
make
([]
string
,
n
,
n
)
for
parent
:=
d
;
parent
!=
nil
;
parent
=
parent
.
parent
{
n
--
s
[
n
]
=
parent
.
GetName
()
}
d
.
typename
=
s
return
s
}
func
(
d
*
Descriptor
)
allowOneof
()
bool
{
return
true
}
// EnumDescriptor describes an enum. If it's at top level, its parent will be nil.
// Otherwise it will be the descriptor of the message in which it is defined.
type
EnumDescriptor
struct
{
common
*
descriptor
.
EnumDescriptorProto
parent
*
Descriptor
// The containing message, if any.
typename
[]
string
// Cached typename vector.
index
int
// The index into the container, whether the file or a message.
path
string
// The SourceCodeInfo path as comma-separated integers.
}
// TypeName returns the elements of the dotted type name.
// The package name is not part of this name.
func
(
e
*
EnumDescriptor
)
TypeName
()
(
s
[]
string
)
{
if
e
.
typename
!=
nil
{
return
e
.
typename
}
name
:=
e
.
GetName
()
if
e
.
parent
==
nil
{
s
=
make
([]
string
,
1
)
}
else
{
pname
:=
e
.
parent
.
TypeName
()
s
=
make
([]
string
,
len
(
pname
)
+
1
)
copy
(
s
,
pname
)
}
s
[
len
(
s
)
-
1
]
=
name
e
.
typename
=
s
return
s
}
// Everything but the last element of the full type name, CamelCased.
// The values of type Foo.Bar are call Foo_value1... not Foo_Bar_value1... .
func
(
e
*
EnumDescriptor
)
prefix
()
string
{
if
e
.
parent
==
nil
{
// If the enum is not part of a message, the prefix is just the type name.
return
CamelCase
(
*
e
.
Name
)
+
"_"
}
typeName
:=
e
.
TypeName
()
return
CamelCaseSlice
(
typeName
[
0
:
len
(
typeName
)
-
1
])
+
"_"
}
// The integer value of the named constant in this enumerated type.
func
(
e
*
EnumDescriptor
)
integerValueAsString
(
name
string
)
string
{
for
_
,
c
:=
range
e
.
Value
{
if
c
.
GetName
()
==
name
{
return
fmt
.
Sprint
(
c
.
GetNumber
())
}
}
log
.
Fatal
(
"cannot find value for enum constant"
)
return
""
}
// ExtensionDescriptor describes an extension. If it's at top level, its parent will be nil.
// Otherwise it will be the descriptor of the message in which it is defined.
type
ExtensionDescriptor
struct
{
common
*
descriptor
.
FieldDescriptorProto
parent
*
Descriptor
// The containing message, if any.
}
// TypeName returns the elements of the dotted type name.
// The package name is not part of this name.
func
(
e
*
ExtensionDescriptor
)
TypeName
()
(
s
[]
string
)
{
name
:=
e
.
GetName
()
if
e
.
parent
==
nil
{
// top-level extension
s
=
make
([]
string
,
1
)
}
else
{
pname
:=
e
.
parent
.
TypeName
()
s
=
make
([]
string
,
len
(
pname
)
+
1
)
copy
(
s
,
pname
)
}
s
[
len
(
s
)
-
1
]
=
name
return
s
}
// DescName returns the variable name used for the generated descriptor.
func
(
e
*
ExtensionDescriptor
)
DescName
()
string
{
// The full type name.
typeName
:=
e
.
TypeName
()
// Each scope of the extension is individually CamelCased, and all are joined with "_" with an "E_" prefix.
for
i
,
s
:=
range
typeName
{
typeName
[
i
]
=
CamelCase
(
s
)
}
return
"E_"
+
strings
.
Join
(
typeName
,
"_"
)
}
// ImportedDescriptor describes a type that has been publicly imported from another file.
type
ImportedDescriptor
struct
{
common
o
Object
}
func
(
id
*
ImportedDescriptor
)
TypeName
()
[]
string
{
return
id
.
o
.
TypeName
()
}
// FileDescriptor describes an protocol buffer descriptor file (.proto).
// It includes slices of all the messages and enums defined within it.
// Those slices are constructed by WrapTypes.
type
FileDescriptor
struct
{
*
descriptor
.
FileDescriptorProto
desc
[]
*
Descriptor
// All the messages defined in this file.
enum
[]
*
EnumDescriptor
// All the enums defined in this file.
ext
[]
*
ExtensionDescriptor
// All the top-level extensions defined in this file.
imp
[]
*
ImportedDescriptor
// All types defined in files publicly imported by this file.
// Comments, stored as a map of path (comma-separated integers) to the comment.
comments
map
[
string
]
*
descriptor
.
SourceCodeInfo_Location
// The full list of symbols that are exported,
// as a map from the exported object to its symbols.
// This is used for supporting public imports.
exported
map
[
Object
][]
symbol
index
int
// The index of this file in the list of files to generate code for
proto3
bool
// whether to generate proto3 code for this file
}
// PackageName is the package name we'll use in the generated code to refer to this file.
func
(
d
*
FileDescriptor
)
PackageName
()
string
{
return
uniquePackageOf
(
d
.
FileDescriptorProto
)
}
// goPackageName returns the Go package name to use in the
// generated Go file. The result explicit reports whether the name
// came from an option go_package statement. If explicit is false,
// the name was derived from the protocol buffer's package statement
// or the input file name.
func
(
d
*
FileDescriptor
)
goPackageName
()
(
name
string
,
explicit
bool
)
{
// Does the file have a "go_package" option?
if
opts
:=
d
.
Options
;
opts
!=
nil
{
if
pkg
:=
opts
.
GetGoPackage
();
pkg
!=
""
{
return
pkg
,
true
}
}
// Does the file have a package clause?
if
pkg
:=
d
.
GetPackage
();
pkg
!=
""
{
return
pkg
,
false
}
// Use the file base name.
return
baseName
(
d
.
GetName
()),
false
}
func
(
d
*
FileDescriptor
)
addExport
(
obj
Object
,
sym
symbol
)
{
d
.
exported
[
obj
]
=
append
(
d
.
exported
[
obj
],
sym
)
}
// symbol is an interface representing an exported Go symbol.
type
symbol
interface
{
// GenerateAlias should generate an appropriate alias
// for the symbol from the named package.
GenerateAlias
(
g
*
Generator
,
pkg
string
)
}
type
messageSymbol
struct
{
sym
string
hasExtensions
,
isMessageSet
bool
getters
[]
getterSymbol
}
type
getterSymbol
struct
{
name
string
typ
string
typeName
string
// canonical name in proto world; empty for proto.Message and similar
genType
bool
// whether typ contains a generated type (message/group/enum)
}
func
(
ms
*
messageSymbol
)
GenerateAlias
(
g
*
Generator
,
pkg
string
)
{
remoteSym
:=
pkg
+
"."
+
ms
.
sym
g
.
P
(
"type "
,
ms
.
sym
,
" "
,
remoteSym
)
g
.
P
(
"func (m *"
,
ms
.
sym
,
") Reset() { (*"
,
remoteSym
,
")(m).Reset() }"
)
g
.
P
(
"func (m *"
,
ms
.
sym
,
") String() string { return (*"
,
remoteSym
,
")(m).String() }"
)
g
.
P
(
"func (*"
,
ms
.
sym
,
") ProtoMessage() {}"
)
if
ms
.
hasExtensions
{
g
.
P
(
"func (*"
,
ms
.
sym
,
") ExtensionRangeArray() []"
,
g
.
Pkg
[
"proto"
],
".ExtensionRange "
,
"{ return (*"
,
remoteSym
,
")(nil).ExtensionRangeArray() }"
)
g
.
P
(
"func (m *"
,
ms
.
sym
,
") ExtensionMap() map[int32]"
,
g
.
Pkg
[
"proto"
],
".Extension "
,
"{ return (*"
,
remoteSym
,
")(m).ExtensionMap() }"
)
if
ms
.
isMessageSet
{
g
.
P
(
"func (m *"
,
ms
.
sym
,
") Marshal() ([]byte, error) "
,
"{ return (*"
,
remoteSym
,
")(m).Marshal() }"
)
g
.
P
(
"func (m *"
,
ms
.
sym
,
") Unmarshal(buf []byte) error "
,
"{ return (*"
,
remoteSym
,
")(m).Unmarshal(buf) }"
)
}
}
for
_
,
get
:=
range
ms
.
getters
{
if
get
.
typeName
!=
""
{
g
.
RecordTypeUse
(
get
.
typeName
)
}
typ
:=
get
.
typ
val
:=
"(*"
+
remoteSym
+
")(m)."
+
get
.
name
+
"()"
if
get
.
genType
{
// typ will be "*pkg.T" (message/group) or "pkg.T" (enum)
// or "map[t]*pkg.T" (map to message/enum).
// The first two of those might have a "[]" prefix if it is repeated.
// Drop any package qualifier since we have hoisted the type into this package.
rep
:=
strings
.
HasPrefix
(
typ
,
"[]"
)
if
rep
{
typ
=
typ
[
2
:
]
}
isMap
:=
strings
.
HasPrefix
(
typ
,
"map["
)
star
:=
typ
[
0
]
==
'*'
if
!
isMap
{
// map types handled lower down
typ
=
typ
[
strings
.
Index
(
typ
,
"."
)
+
1
:
]
}
if
star
{
typ
=
"*"
+
typ
}
if
rep
{
// Go does not permit conversion between slice types where both
// element types are named. That means we need to generate a bit
// of code in this situation.
// typ is the element type.
// val is the expression to get the slice from the imported type.
ctyp
:=
typ
// conversion type expression; "Foo" or "(*Foo)"
if
star
{
ctyp
=
"("
+
typ
+
")"
}
g
.
P
(
"func (m *"
,
ms
.
sym
,
") "
,
get
.
name
,
"() []"
,
typ
,
" {"
)
g
.
In
()
g
.
P
(
"o := "
,
val
)
g
.
P
(
"if o == nil {"
)
g
.
In
()
g
.
P
(
"return nil"
)
g
.
Out
()
g
.
P
(
"}"
)
g
.
P
(
"s := make([]"
,
typ
,
", len(o))"
)
g
.
P
(
"for i, x := range o {"
)
g
.
In
()
g
.
P
(
"s[i] = "
,
ctyp
,
"(x)"
)
g
.
Out
()
g
.
P
(
"}"
)
g
.
P
(
"return s"
)
g
.
Out
()
g
.
P
(
"}"
)
continue
}
if
isMap
{
// Split map[keyTyp]valTyp.
bra
,
ket
:=
strings
.
Index
(
typ
,
"["
),
strings
.
Index
(
typ
,
"]"
)
keyTyp
,
valTyp
:=
typ
[
bra
+
1
:
ket
],
typ
[
ket
+
1
:
]
// Drop any package qualifier.
// Only the value type may be foreign.
star
:=
valTyp
[
0
]
==
'*'
valTyp
=
valTyp
[
strings
.
Index
(
valTyp
,
"."
)
+
1
:
]
if
star
{
valTyp
=
"*"
+
valTyp
}
typ
:=
"map["
+
keyTyp
+
"]"
+
valTyp
g
.
P
(
"func (m *"
,
ms
.
sym
,
") "
,
get
.
name
,
"() "
,
typ
,
" {"
)
g
.
P
(
"o := "
,
val
)
g
.
P
(
"if o == nil { return nil }"
)
g
.
P
(
"s := make("
,
typ
,
", len(o))"
)
g
.
P
(
"for k, v := range o {"
)
g
.
P
(
"s[k] = ("
,
valTyp
,
")(v)"
)
g
.
P
(
"}"
)
g
.
P
(
"return s"
)
g
.
P
(
"}"
)
continue
}
// Convert imported type into the forwarding type.
val
=
"("
+
typ
+
")("
+
val
+
")"
}
g
.
P
(
"func (m *"
,
ms
.
sym
,
") "
,
get
.
name
,
"() "
,
typ
,
" { return "
,
val
,
" }"
)
}
}
type
enumSymbol
struct
{
name
string
proto3
bool
// Whether this came from a proto3 file.
}
func
(
es
enumSymbol
)
GenerateAlias
(
g
*
Generator
,
pkg
string
)
{
s
:=
es
.
name
g
.
P
(
"type "
,
s
,
" "
,
pkg
,
"."
,
s
)
g
.
P
(
"var "
,
s
,
"_name = "
,
pkg
,
"."
,
s
,
"_name"
)
g
.
P
(
"var "
,
s
,
"_value = "
,
pkg
,
"."
,
s
,
"_value"
)
g
.
P
(
"func (x "
,
s
,
") String() string { return ("
,
pkg
,
"."
,
s
,
")(x).String() }"
)
if
!
es
.
proto3
{
g
.
P
(
"func (x "
,
s
,
") Enum() *"
,
s
,
"{ return (*"
,
s
,
")(("
,
pkg
,
"."
,
s
,
")(x).Enum()) }"
)
g
.
P
(
"func (x *"
,
s
,
") UnmarshalJSON(data []byte) error { return (*"
,
pkg
,
"."
,
s
,
")(x).UnmarshalJSON(data) }"
)
}
}
type
constOrVarSymbol
struct
{
sym
string
typ
string
// either "const" or "var"
cast
string
// if non-empty, a type cast is required (used for enums)
}
func
(
cs
constOrVarSymbol
)
GenerateAlias
(
g
*
Generator
,
pkg
string
)
{
v
:=
pkg
+
"."
+
cs
.
sym
if
cs
.
cast
!=
""
{
v
=
cs
.
cast
+
"("
+
v
+
")"
}
g
.
P
(
cs
.
typ
,
" "
,
cs
.
sym
,
" = "
,
v
)
}
// Object is an interface abstracting the abilities shared by enums, messages, extensions and imported objects.
type
Object
interface
{
PackageName
()
string
// The name we use in our output (a_b_c), possibly renamed for uniqueness.
TypeName
()
[]
string
File
()
*
descriptor
.
FileDescriptorProto
}
// Each package name we generate must be unique. The package we're generating
// gets its own name but every other package must have a unique name that does
// not conflict in the code we generate. These names are chosen globally (although
// they don't have to be, it simplifies things to do them globally).
func
uniquePackageOf
(
fd
*
descriptor
.
FileDescriptorProto
)
string
{
s
,
ok
:=
uniquePackageName
[
fd
]
if
!
ok
{
log
.
Fatal
(
"internal error: no package name defined for "
+
fd
.
GetName
())
}
return
s
}
// Generator is the type whose methods generate the output, stored in the associated response structure.
type
Generator
struct
{
*
bytes
.
Buffer
Request
*
plugin
.
CodeGeneratorRequest
// The input.
Response
*
plugin
.
CodeGeneratorResponse
// The output.
Param
map
[
string
]
string
// Command-line parameters.
PackageImportPath
string
// Go import path of the package we're generating code for
ImportPrefix
string
// String to prefix to imported package file names.
ImportMap
map
[
string
]
string
// Mapping from import name to generated name
Pkg
map
[
string
]
string
// The names under which we import support packages
packageName
string
// What we're calling ourselves.
allFiles
[]
*
FileDescriptor
// All files in the tree
genFiles
[]
*
FileDescriptor
// Those files we will generate output for.
file
*
FileDescriptor
// The file we are compiling now.
usedPackages
map
[
string
]
bool
// Names of packages used in current file.
typeNameToObject
map
[
string
]
Object
// Key is a fully-qualified name in input syntax.
init
[]
string
// Lines to emit in the init function.
customImports
[]
string
indent
string
writtenImports
map
[
string
]
bool
// For de-duplicating written imports
}
// New creates a new generator and allocates the request and response protobufs.
func
New
()
*
Generator
{
g
:=
new
(
Generator
)
g
.
Buffer
=
new
(
bytes
.
Buffer
)
g
.
Request
=
new
(
plugin
.
CodeGeneratorRequest
)
g
.
Response
=
new
(
plugin
.
CodeGeneratorResponse
)
g
.
writtenImports
=
make
(
map
[
string
]
bool
)
uniquePackageName
=
make
(
map
[
*
descriptor
.
FileDescriptorProto
]
string
)
pkgNamesInUse
=
make
(
map
[
string
][]
*
FileDescriptor
)
return
g
}
// Error reports a problem, including an error, and exits the program.
func
(
g
*
Generator
)
Error
(
err
error
,
msgs
...
string
)
{
s
:=
strings
.
Join
(
msgs
,
" "
)
+
":"
+
err
.
Error
()
log
.
Print
(
"protoc-gen-gogo: error:"
,
s
)
os
.
Exit
(
1
)
}
// Fail reports a problem and exits the program.
func
(
g
*
Generator
)
Fail
(
msgs
...
string
)
{
s
:=
strings
.
Join
(
msgs
,
" "
)
log
.
Print
(
"protoc-gen-gogo: error:"
,
s
)
os
.
Exit
(
1
)
}
// CommandLineParameters breaks the comma-separated list of key=value pairs
// in the parameter (a member of the request protobuf) into a key/value map.
// It then sets file name mappings defined by those entries.
func
(
g
*
Generator
)
CommandLineParameters
(
parameter
string
)
{
g
.
Param
=
make
(
map
[
string
]
string
)
for
_
,
p
:=
range
strings
.
Split
(
parameter
,
","
)
{
if
i
:=
strings
.
Index
(
p
,
"="
);
i
<
0
{
g
.
Param
[
p
]
=
""
}
else
{
g
.
Param
[
p
[
0
:
i
]]
=
p
[
i
+
1
:
]
}
}
g
.
ImportMap
=
make
(
map
[
string
]
string
)
pluginList
:=
"none"
// Default list of plugin names to enable (empty means all).
for
k
,
v
:=
range
g
.
Param
{
switch
k
{
case
"import_prefix"
:
g
.
ImportPrefix
=
v
case
"import_path"
:
g
.
PackageImportPath
=
v
case
"plugins"
:
pluginList
=
v
default
:
if
len
(
k
)
>
0
&&
k
[
0
]
==
'M'
{
g
.
ImportMap
[
k
[
1
:
]]
=
v
}
}
}
if
pluginList
==
""
{
return
}
if
pluginList
==
"none"
{
pluginList
=
""
}
gogoPluginNames
:=
[]
string
{
"unmarshal"
,
"unsafeunmarshaler"
,
"union"
,
"stringer"
,
"size"
,
"populate"
,
"marshalto"
,
"unsafemarshaler"
,
"gostring"
,
"face"
,
"equal"
,
"enumstringer"
,
"embedcheck"
,
"description"
,
"defaultcheck"
,
"oneofcheck"
}
pluginList
=
strings
.
Join
(
append
(
gogoPluginNames
,
pluginList
),
"+"
)
if
pluginList
!=
""
{
// Amend the set of plugins.
enabled
:=
make
(
map
[
string
]
bool
)
for
_
,
name
:=
range
strings
.
Split
(
pluginList
,
"+"
)
{
enabled
[
name
]
=
true
}
var
nplugins
pluginSlice
for
_
,
p
:=
range
plugins
{
if
enabled
[
p
.
Name
()]
{
nplugins
=
append
(
nplugins
,
p
)
}
}
sort
.
Sort
(
nplugins
)
plugins
=
nplugins
}
}
// DefaultPackageName returns the package name printed for the object.
// If its file is in a different package, it returns the package name we're using for this file, plus ".".
// Otherwise it returns the empty string.
func
(
g
*
Generator
)
DefaultPackageName
(
obj
Object
)
string
{
pkg
:=
obj
.
PackageName
()
if
pkg
==
g
.
packageName
{
return
""
}
return
pkg
+
"."
}
// For each input file, the unique package name to use, underscored.
var
uniquePackageName
=
make
(
map
[
*
descriptor
.
FileDescriptorProto
]
string
)
// Package names already registered. Key is the name from the .proto file;
// value is the name that appears in the generated code.
var
pkgNamesInUse
=
make
(
map
[
string
][]
*
FileDescriptor
)
// Create and remember a guaranteed unique package name for this file descriptor.
// Pkg is the candidate name. If f is nil, it's a builtin package like "proto" and
// has no file descriptor.
func
RegisterUniquePackageName
(
pkg
string
,
f
*
FileDescriptor
)
string
{
// Convert dots to underscores before finding a unique alias.
pkg
=
strings
.
Map
(
badToUnderscore
,
pkg
)
var
i
=
-
1
var
ptr
*
FileDescriptor
=
nil
for
i
,
ptr
=
range
pkgNamesInUse
[
pkg
]
{
if
ptr
==
f
{
if
i
==
0
{
return
pkg
}
return
pkg
+
strconv
.
Itoa
(
i
)
}
}
pkgNamesInUse
[
pkg
]
=
append
(
pkgNamesInUse
[
pkg
],
f
)
i
+=
1
if
i
>
0
{
pkg
=
pkg
+
strconv
.
Itoa
(
i
)
}
if
f
!=
nil
{
uniquePackageName
[
f
.
FileDescriptorProto
]
=
pkg
}
return
pkg
}
var
isGoKeyword
=
map
[
string
]
bool
{
"break"
:
true
,
"case"
:
true
,
"chan"
:
true
,
"const"
:
true
,
"continue"
:
true
,
"default"
:
true
,
"else"
:
true
,
"defer"
:
true
,
"fallthrough"
:
true
,
"for"
:
true
,
"func"
:
true
,
"go"
:
true
,
"goto"
:
true
,
"if"
:
true
,
"import"
:
true
,
"interface"
:
true
,
"map"
:
true
,
"package"
:
true
,
"range"
:
true
,
"return"
:
true
,
"select"
:
true
,
"struct"
:
true
,
"switch"
:
true
,
"type"
:
true
,
"var"
:
true
,
}
// defaultGoPackage returns the package name to use,
// derived from the import path of the package we're building code for.
func
(
g
*
Generator
)
defaultGoPackage
()
string
{
p
:=
g
.
PackageImportPath
if
i
:=
strings
.
LastIndex
(
p
,
"/"
);
i
>=
0
{
p
=
p
[
i
+
1
:
]
}
if
p
==
""
{
return
""
}
p
=
strings
.
Map
(
badToUnderscore
,
p
)
// Identifier must not be keyword: insert _.
if
isGoKeyword
[
p
]
{
p
=
"_"
+
p
}
// Identifier must not begin with digit: insert _.
if
r
,
_
:=
utf8
.
DecodeRuneInString
(
p
);
unicode
.
IsDigit
(
r
)
{
p
=
"_"
+
p
}
return
p
}
// SetPackageNames sets the package name for this run.
// The package name must agree across all files being generated.
// It also defines unique package names for all imported files.
func
(
g
*
Generator
)
SetPackageNames
()
{
// Register the name for this package. It will be the first name
// registered so is guaranteed to be unmodified.
pkg
,
explicit
:=
g
.
genFiles
[
0
]
.
goPackageName
()
// Check all files for an explicit go_package option.
for
_
,
f
:=
range
g
.
genFiles
{
thisPkg
,
thisExplicit
:=
f
.
goPackageName
()
if
thisExplicit
{
if
!
explicit
{
// Let this file's go_package option serve for all input files.
pkg
,
explicit
=
thisPkg
,
true
}
else
if
thisPkg
!=
pkg
{
g
.
Fail
(
"inconsistent package names:"
,
thisPkg
,
pkg
)
}
}
}
// If we don't have an explicit go_package option but we have an
// import path, use that.
if
!
explicit
{
p
:=
g
.
defaultGoPackage
()
if
p
!=
""
{
pkg
,
explicit
=
p
,
true
}
}
// If there was no go_package and no import path to use,
// double-check that all the inputs have the same implicit
// Go package name.
if
!
explicit
{
for
_
,
f
:=
range
g
.
genFiles
{
thisPkg
,
_
:=
f
.
goPackageName
()
if
thisPkg
!=
pkg
{
g
.
Fail
(
"inconsistent package names:"
,
thisPkg
,
pkg
)
}
}
}
g
.
packageName
=
RegisterUniquePackageName
(
pkg
,
g
.
genFiles
[
0
])
// Register the support package names. They might collide with the
// name of a package we import.
g
.
Pkg
=
map
[
string
]
string
{
"fmt"
:
RegisterUniquePackageName
(
"fmt"
,
nil
),
"math"
:
RegisterUniquePackageName
(
"math"
,
nil
),
"proto"
:
RegisterUniquePackageName
(
"proto"
,
nil
),
}
AllFiles
:
for
_
,
f
:=
range
g
.
allFiles
{
for
_
,
genf
:=
range
g
.
genFiles
{
if
f
==
genf
{
// In this package already.
uniquePackageName
[
f
.
FileDescriptorProto
]
=
g
.
packageName
continue
AllFiles
}
}
// The file is a dependency, so we want to ignore its go_package option
// because that is only relevant for its specific generated output.
pkg
:=
f
.
GetPackage
()
if
pkg
==
""
{
pkg
=
baseName
(
*
f
.
Name
)
}
RegisterUniquePackageName
(
pkg
,
f
)
}
}
// WrapTypes walks the incoming data, wrapping DescriptorProtos, EnumDescriptorProtos
// and FileDescriptorProtos into file-referenced objects within the Generator.
// It also creates the list of files to generate and so should be called before GenerateAllFiles.
func
(
g
*
Generator
)
WrapTypes
()
{
g
.
allFiles
=
make
([]
*
FileDescriptor
,
len
(
g
.
Request
.
ProtoFile
))
for
i
,
f
:=
range
g
.
Request
.
ProtoFile
{
// We must wrap the descriptors before we wrap the enums
descs
:=
wrapDescriptors
(
f
)
g
.
buildNestedDescriptors
(
descs
)
enums
:=
wrapEnumDescriptors
(
f
,
descs
)
g
.
buildNestedEnums
(
descs
,
enums
)
exts
:=
wrapExtensions
(
f
)
imps
:=
wrapImported
(
f
,
g
)
fd
:=
&
FileDescriptor
{
FileDescriptorProto
:
f
,
desc
:
descs
,
enum
:
enums
,
ext
:
exts
,
imp
:
imps
,
exported
:
make
(
map
[
Object
][]
symbol
),
proto3
:
fileIsProto3
(
f
),
}
extractComments
(
fd
)
g
.
allFiles
[
i
]
=
fd
}
g
.
genFiles
=
make
([]
*
FileDescriptor
,
len
(
g
.
Request
.
FileToGenerate
))
FindFiles
:
for
i
,
fileName
:=
range
g
.
Request
.
FileToGenerate
{
// Search the list. This algorithm is n^2 but n is tiny.
for
_
,
file
:=
range
g
.
allFiles
{
if
fileName
==
file
.
GetName
()
{
g
.
genFiles
[
i
]
=
file
file
.
index
=
i
continue
FindFiles
}
}
g
.
Fail
(
"could not find file named"
,
fileName
)
}
g
.
Response
.
File
=
make
([]
*
plugin
.
CodeGeneratorResponse_File
,
len
(
g
.
genFiles
))
}
// Scan the descriptors in this file. For each one, build the slice of nested descriptors
func
(
g
*
Generator
)
buildNestedDescriptors
(
descs
[]
*
Descriptor
)
{
for
_
,
desc
:=
range
descs
{
if
len
(
desc
.
NestedType
)
!=
0
{
for
_
,
nest
:=
range
descs
{
if
nest
.
parent
==
desc
{
desc
.
nested
=
append
(
desc
.
nested
,
nest
)
}
}
if
len
(
desc
.
nested
)
!=
len
(
desc
.
NestedType
)
{
g
.
Fail
(
"internal error: nesting failure for"
,
desc
.
GetName
())
}
}
}
}
func
(
g
*
Generator
)
buildNestedEnums
(
descs
[]
*
Descriptor
,
enums
[]
*
EnumDescriptor
)
{
for
_
,
desc
:=
range
descs
{
if
len
(
desc
.
EnumType
)
!=
0
{
for
_
,
enum
:=
range
enums
{
if
enum
.
parent
==
desc
{
desc
.
enums
=
append
(
desc
.
enums
,
enum
)
}
}
if
len
(
desc
.
enums
)
!=
len
(
desc
.
EnumType
)
{
g
.
Fail
(
"internal error: enum nesting failure for"
,
desc
.
GetName
())
}
}
}
}
// Construct the Descriptor
func
newDescriptor
(
desc
*
descriptor
.
DescriptorProto
,
parent
*
Descriptor
,
file
*
descriptor
.
FileDescriptorProto
,
index
int
)
*
Descriptor
{
d
:=
&
Descriptor
{
common
:
common
{
file
},
DescriptorProto
:
desc
,
parent
:
parent
,
index
:
index
,
}
if
parent
==
nil
{
d
.
path
=
fmt
.
Sprintf
(
"%d,%d"
,
messagePath
,
index
)
}
else
{
d
.
path
=
fmt
.
Sprintf
(
"%s,%d,%d"
,
parent
.
path
,
messageMessagePath
,
index
)
}
// The only way to distinguish a group from a message is whether
// the containing message has a TYPE_GROUP field that matches.
if
parent
!=
nil
{
parts
:=
d
.
TypeName
()
if
file
.
Package
!=
nil
{
parts
=
append
([]
string
{
*
file
.
Package
},
parts
...
)
}
exp
:=
"."
+
strings
.
Join
(
parts
,
"."
)
for
_
,
field
:=
range
parent
.
Field
{
if
field
.
GetType
()
==
descriptor
.
FieldDescriptorProto_TYPE_GROUP
&&
field
.
GetTypeName
()
==
exp
{
d
.
group
=
true
break
}
}
}
d
.
ext
=
make
([]
*
ExtensionDescriptor
,
len
(
desc
.
Extension
))
for
i
,
field
:=
range
desc
.
Extension
{
d
.
ext
[
i
]
=
&
ExtensionDescriptor
{
common
{
file
},
field
,
d
}
}
return
d
}
// Return a slice of all the Descriptors defined within this file
func
wrapDescriptors
(
file
*
descriptor
.
FileDescriptorProto
)
[]
*
Descriptor
{
sl
:=
make
([]
*
Descriptor
,
0
,
len
(
file
.
MessageType
)
+
10
)
for
i
,
desc
:=
range
file
.
MessageType
{
sl
=
wrapThisDescriptor
(
sl
,
desc
,
nil
,
file
,
i
)
}
return
sl
}
// Wrap this Descriptor, recursively
func
wrapThisDescriptor
(
sl
[]
*
Descriptor
,
desc
*
descriptor
.
DescriptorProto
,
parent
*
Descriptor
,
file
*
descriptor
.
FileDescriptorProto
,
index
int
)
[]
*
Descriptor
{
sl
=
append
(
sl
,
newDescriptor
(
desc
,
parent
,
file
,
index
))
me
:=
sl
[
len
(
sl
)
-
1
]
for
i
,
nested
:=
range
desc
.
NestedType
{
sl
=
wrapThisDescriptor
(
sl
,
nested
,
me
,
file
,
i
)
}
return
sl
}
// Construct the EnumDescriptor
func
newEnumDescriptor
(
desc
*
descriptor
.
EnumDescriptorProto
,
parent
*
Descriptor
,
file
*
descriptor
.
FileDescriptorProto
,
index
int
)
*
EnumDescriptor
{
ed
:=
&
EnumDescriptor
{
common
:
common
{
file
},
EnumDescriptorProto
:
desc
,
parent
:
parent
,
index
:
index
,
}
if
parent
==
nil
{
ed
.
path
=
fmt
.
Sprintf
(
"%d,%d"
,
enumPath
,
index
)
}
else
{
ed
.
path
=
fmt
.
Sprintf
(
"%s,%d,%d"
,
parent
.
path
,
messageEnumPath
,
index
)
}
return
ed
}
// Return a slice of all the EnumDescriptors defined within this file
func
wrapEnumDescriptors
(
file
*
descriptor
.
FileDescriptorProto
,
descs
[]
*
Descriptor
)
[]
*
EnumDescriptor
{
sl
:=
make
([]
*
EnumDescriptor
,
0
,
len
(
file
.
EnumType
)
+
10
)
// Top-level enums.
for
i
,
enum
:=
range
file
.
EnumType
{
sl
=
append
(
sl
,
newEnumDescriptor
(
enum
,
nil
,
file
,
i
))
}
// Enums within messages. Enums within embedded messages appear in the outer-most message.
for
_
,
nested
:=
range
descs
{
for
i
,
enum
:=
range
nested
.
EnumType
{
sl
=
append
(
sl
,
newEnumDescriptor
(
enum
,
nested
,
file
,
i
))
}
}
return
sl
}
// Return a slice of all the top-level ExtensionDescriptors defined within this file.
func
wrapExtensions
(
file
*
descriptor
.
FileDescriptorProto
)
[]
*
ExtensionDescriptor
{
sl
:=
make
([]
*
ExtensionDescriptor
,
len
(
file
.
Extension
))
for
i
,
field
:=
range
file
.
Extension
{
sl
[
i
]
=
&
ExtensionDescriptor
{
common
{
file
},
field
,
nil
}
}
return
sl
}
// Return a slice of all the types that are publicly imported into this file.
func
wrapImported
(
file
*
descriptor
.
FileDescriptorProto
,
g
*
Generator
)
(
sl
[]
*
ImportedDescriptor
)
{
for
_
,
index
:=
range
file
.
PublicDependency
{
df
:=
g
.
fileByName
(
file
.
Dependency
[
index
])
for
_
,
d
:=
range
df
.
desc
{
if
d
.
GetOptions
()
.
GetMapEntry
()
{
continue
}
sl
=
append
(
sl
,
&
ImportedDescriptor
{
common
{
file
},
d
})
}
for
_
,
e
:=
range
df
.
enum
{
sl
=
append
(
sl
,
&
ImportedDescriptor
{
common
{
file
},
e
})
}
for
_
,
ext
:=
range
df
.
ext
{
sl
=
append
(
sl
,
&
ImportedDescriptor
{
common
{
file
},
ext
})
}
}
return
}
func
extractComments
(
file
*
FileDescriptor
)
{
file
.
comments
=
make
(
map
[
string
]
*
descriptor
.
SourceCodeInfo_Location
)
for
_
,
loc
:=
range
file
.
GetSourceCodeInfo
()
.
GetLocation
()
{
if
loc
.
LeadingComments
==
nil
{
continue
}
var
p
[]
string
for
_
,
n
:=
range
loc
.
Path
{
p
=
append
(
p
,
strconv
.
Itoa
(
int
(
n
)))
}
file
.
comments
[
strings
.
Join
(
p
,
","
)]
=
loc
}
}
// BuildTypeNameMap builds the map from fully qualified type names to objects.
// The key names for the map come from the input data, which puts a period at the beginning.
// It should be called after SetPackageNames and before GenerateAllFiles.
func
(
g
*
Generator
)
BuildTypeNameMap
()
{
g
.
typeNameToObject
=
make
(
map
[
string
]
Object
)
for
_
,
f
:=
range
g
.
allFiles
{
// The names in this loop are defined by the proto world, not us, so the
// package name may be empty. If so, the dotted package name of X will
// be ".X"; otherwise it will be ".pkg.X".
dottedPkg
:=
"."
+
f
.
GetPackage
()
if
dottedPkg
!=
"."
{
dottedPkg
+=
"."
}
for
_
,
enum
:=
range
f
.
enum
{
name
:=
dottedPkg
+
dottedSlice
(
enum
.
TypeName
())
g
.
typeNameToObject
[
name
]
=
enum
}
for
_
,
desc
:=
range
f
.
desc
{
name
:=
dottedPkg
+
dottedSlice
(
desc
.
TypeName
())
g
.
typeNameToObject
[
name
]
=
desc
}
}
}
// ObjectNamed, given a fully-qualified input type name as it appears in the input data,
// returns the descriptor for the message or enum with that name.
func
(
g
*
Generator
)
ObjectNamed
(
typeName
string
)
Object
{
o
,
ok
:=
g
.
typeNameToObject
[
typeName
]
if
!
ok
{
g
.
Fail
(
"can't find object with type"
,
typeName
)
}
// If the file of this object isn't a direct dependency of the current file,
// or in the current file, then this object has been publicly imported into
// a dependency of the current file.
// We should return the ImportedDescriptor object for it instead.
direct
:=
*
o
.
File
()
.
Name
==
*
g
.
file
.
Name
if
!
direct
{
for
_
,
dep
:=
range
g
.
file
.
Dependency
{
if
*
g
.
fileByName
(
dep
)
.
Name
==
*
o
.
File
()
.
Name
{
direct
=
true
break
}
}
}
if
!
direct
{
found
:=
false
Loop
:
for
_
,
dep
:=
range
g
.
file
.
Dependency
{
df
:=
g
.
fileByName
(
*
g
.
fileByName
(
dep
)
.
Name
)
for
_
,
td
:=
range
df
.
imp
{
if
td
.
o
==
o
{
// Found it!
o
=
td
found
=
true
break
Loop
}
}
}
if
!
found
{
log
.
Printf
(
"protoc-gen-gogo: WARNING: failed finding publicly imported dependency for %v, used in %v"
,
typeName
,
*
g
.
file
.
Name
)
}
}
return
o
}
// P prints the arguments to the generated output. It handles strings and int32s, plus
// handling indirections because they may be *string, etc.
func
(
g
*
Generator
)
P
(
str
...
interface
{})
{
g
.
WriteString
(
g
.
indent
)
for
_
,
v
:=
range
str
{
switch
s
:=
v
.
(
type
)
{
case
string
:
g
.
WriteString
(
s
)
case
*
string
:
g
.
WriteString
(
*
s
)
case
bool
:
g
.
WriteString
(
fmt
.
Sprintf
(
"%t"
,
s
))
case
*
bool
:
g
.
WriteString
(
fmt
.
Sprintf
(
"%t"
,
*
s
))
case
int
:
g
.
WriteString
(
fmt
.
Sprintf
(
"%d"
,
s
))
case
*
int32
:
g
.
WriteString
(
fmt
.
Sprintf
(
"%d"
,
*
s
))
case
*
int64
:
g
.
WriteString
(
fmt
.
Sprintf
(
"%d"
,
*
s
))
case
float64
:
g
.
WriteString
(
fmt
.
Sprintf
(
"%g"
,
s
))
case
*
float64
:
g
.
WriteString
(
fmt
.
Sprintf
(
"%g"
,
*
s
))
default
:
g
.
Fail
(
fmt
.
Sprintf
(
"unknown type in printer: %T"
,
v
))
}
}
g
.
WriteByte
(
'\n'
)
}
// addInitf stores the given statement to be printed inside the file's init function.
// The statement is given as a format specifier and arguments.
func
(
g
*
Generator
)
addInitf
(
stmt
string
,
a
...
interface
{})
{
g
.
init
=
append
(
g
.
init
,
fmt
.
Sprintf
(
stmt
,
a
...
))
}
func
(
g
*
Generator
)
PrintImport
(
alias
,
pkg
string
)
{
statement
:=
"import "
+
alias
+
" "
+
strconv
.
Quote
(
pkg
)
if
g
.
writtenImports
[
statement
]
{
return
}
g
.
P
(
statement
)
g
.
writtenImports
[
statement
]
=
true
}
// In Indents the output one tab stop.
func
(
g
*
Generator
)
In
()
{
g
.
indent
+=
"
\t
"
}
// Out unindents the output one tab stop.
func
(
g
*
Generator
)
Out
()
{
if
len
(
g
.
indent
)
>
0
{
g
.
indent
=
g
.
indent
[
1
:
]
}
}
// GenerateAllFiles generates the output for all the files we're outputting.
func
(
g
*
Generator
)
GenerateAllFiles
()
{
// Initialize the plugins
for
_
,
p
:=
range
plugins
{
p
.
Init
(
g
)
}
// Generate the output. The generator runs for every file, even the files
// that we don't generate output for, so that we can collate the full list
// of exported symbols to support public imports.
genFileMap
:=
make
(
map
[
*
FileDescriptor
]
bool
,
len
(
g
.
genFiles
))
for
_
,
file
:=
range
g
.
genFiles
{
genFileMap
[
file
]
=
true
}
i
:=
0
for
_
,
file
:=
range
g
.
allFiles
{
g
.
Reset
()
g
.
generate
(
file
)
if
_
,
ok
:=
genFileMap
[
file
];
!
ok
{
continue
}
g
.
Response
.
File
[
i
]
=
new
(
plugin
.
CodeGeneratorResponse_File
)
g
.
Response
.
File
[
i
]
.
Name
=
proto
.
String
(
goFileName
(
*
file
.
Name
))
g
.
Response
.
File
[
i
]
.
Content
=
proto
.
String
(
g
.
String
())
i
++
}
}
// Run all the plugins associated with the file.
func
(
g
*
Generator
)
runPlugins
(
file
*
FileDescriptor
)
{
for
_
,
p
:=
range
plugins
{
p
.
Generate
(
file
)
}
}
// FileOf return the FileDescriptor for this FileDescriptorProto.
func
(
g
*
Generator
)
FileOf
(
fd
*
descriptor
.
FileDescriptorProto
)
*
FileDescriptor
{
for
_
,
file
:=
range
g
.
allFiles
{
if
file
.
FileDescriptorProto
==
fd
{
return
file
}
}
g
.
Fail
(
"could not find file in table:"
,
fd
.
GetName
())
return
nil
}
// Fill the response protocol buffer with the generated output for all the files we're
// supposed to generate.
func
(
g
*
Generator
)
generate
(
file
*
FileDescriptor
)
{
g
.
customImports
=
make
([]
string
,
0
)
g
.
file
=
g
.
FileOf
(
file
.
FileDescriptorProto
)
g
.
usedPackages
=
make
(
map
[
string
]
bool
)
// Reset on each file
g
.
writtenImports
=
make
(
map
[
string
]
bool
)
for
_
,
td
:=
range
g
.
file
.
imp
{
g
.
generateImported
(
td
)
}
for
_
,
enum
:=
range
g
.
file
.
enum
{
g
.
generateEnum
(
enum
)
}
for
_
,
desc
:=
range
g
.
file
.
desc
{
// Don't generate virtual messages for maps.
if
desc
.
GetOptions
()
.
GetMapEntry
()
{
continue
}
g
.
generateMessage
(
desc
)
}
for
_
,
ext
:=
range
g
.
file
.
ext
{
g
.
generateExtension
(
ext
)
}
g
.
generateInitFunction
()
// Run the plugins before the imports so we know which imports are necessary.
g
.
runPlugins
(
file
)
// Generate header and imports last, though they appear first in the output.
rem
:=
g
.
Buffer
g
.
Buffer
=
new
(
bytes
.
Buffer
)
g
.
generateHeader
()
g
.
generateImports
()
g
.
Write
(
rem
.
Bytes
())
// Reformat generated code.
fset
:=
token
.
NewFileSet
()
raw
:=
g
.
Bytes
()
ast
,
err
:=
parser
.
ParseFile
(
fset
,
""
,
g
,
parser
.
ParseComments
)
if
err
!=
nil
{
// Print out the bad code with line numbers.
// This should never happen in practice, but it can while changing generated code,
// so consider this a debugging aid.
var
src
bytes
.
Buffer
s
:=
bufio
.
NewScanner
(
bytes
.
NewReader
(
raw
))
for
line
:=
1
;
s
.
Scan
();
line
++
{
fmt
.
Fprintf
(
&
src
,
"%5d
\t
%s
\n
"
,
line
,
s
.
Bytes
())
}
if
serr
:=
s
.
Err
();
serr
!=
nil
{
g
.
Fail
(
"bad Go source code was generated:"
,
err
.
Error
(),
"
\n
"
+
string
(
raw
))
}
else
{
g
.
Fail
(
"bad Go source code was generated:"
,
err
.
Error
(),
"
\n
"
+
src
.
String
())
}
}
g
.
Reset
()
err
=
(
&
printer
.
Config
{
Mode
:
printer
.
TabIndent
|
printer
.
UseSpaces
,
Tabwidth
:
8
})
.
Fprint
(
g
,
fset
,
ast
)
if
err
!=
nil
{
g
.
Fail
(
"generated Go source code could not be reformatted:"
,
err
.
Error
())
}
}
// Generate the header, including package definition
func
(
g
*
Generator
)
generateHeader
()
{
g
.
P
(
"// Code generated by protoc-gen-gogo."
)
g
.
P
(
"// source: "
,
*
g
.
file
.
Name
)
g
.
P
(
"// DO NOT EDIT!"
)
g
.
P
()
name
:=
g
.
file
.
PackageName
()
if
g
.
file
.
index
==
0
{
// Generate package docs for the first file in the package.
g
.
P
(
"/*"
)
g
.
P
(
"Package "
,
name
,
" is a generated protocol buffer package."
)
g
.
P
()
if
loc
,
ok
:=
g
.
file
.
comments
[
strconv
.
Itoa
(
packagePath
)];
ok
{
// not using g.PrintComments because this is a /* */ comment block.
text
:=
strings
.
TrimSuffix
(
loc
.
GetLeadingComments
(),
"
\n
"
)
for
_
,
line
:=
range
strings
.
Split
(
text
,
"
\n
"
)
{
line
=
strings
.
TrimPrefix
(
line
,
" "
)
// ensure we don't escape from the block comment
line
=
strings
.
Replace
(
line
,
"*/"
,
"* /"
,
-
1
)
g
.
P
(
line
)
}
g
.
P
()
}
var
topMsgs
[]
string
g
.
P
(
"It is generated from these files:"
)
for
_
,
f
:=
range
g
.
genFiles
{
g
.
P
(
"
\t
"
,
f
.
Name
)
for
_
,
msg
:=
range
f
.
desc
{
if
msg
.
parent
!=
nil
{
continue
}
topMsgs
=
append
(
topMsgs
,
CamelCaseSlice
(
msg
.
TypeName
()))
}
}
g
.
P
()
g
.
P
(
"It has these top-level messages:"
)
for
_
,
msg
:=
range
topMsgs
{
g
.
P
(
"
\t
"
,
msg
)
}
g
.
P
(
"*/"
)
}
g
.
P
(
"package "
,
name
)
g
.
P
()
}
// PrintComments prints any comments from the source .proto file.
// The path is a comma-separated list of integers.
// It returns an indication of whether any comments were printed.
// See descriptor.proto for its format.
func
(
g
*
Generator
)
PrintComments
(
path
string
)
bool
{
if
loc
,
ok
:=
g
.
file
.
comments
[
path
];
ok
{
text
:=
strings
.
TrimSuffix
(
loc
.
GetLeadingComments
(),
"
\n
"
)
for
_
,
line
:=
range
strings
.
Split
(
text
,
"
\n
"
)
{
g
.
P
(
"// "
,
strings
.
TrimPrefix
(
line
,
" "
))
}
return
true
}
return
false
}
// Comments returns any comments from the source .proto file and empty string if comments not found.
// The path is a comma-separated list of intergers.
// See descriptor.proto for its format.
func
(
g
*
Generator
)
Comments
(
path
string
)
string
{
loc
,
ok
:=
g
.
file
.
comments
[
path
]
if
!
ok
{
return
""
}
text
:=
strings
.
TrimSuffix
(
loc
.
GetLeadingComments
(),
"
\n
"
)
return
text
}
func
(
g
*
Generator
)
fileByName
(
filename
string
)
*
FileDescriptor
{
for
_
,
fd
:=
range
g
.
allFiles
{
if
fd
.
GetName
()
==
filename
{
return
fd
}
}
return
nil
}
// weak returns whether the ith import of the current file is a weak import.
func
(
g
*
Generator
)
weak
(
i
int32
)
bool
{
for
_
,
j
:=
range
g
.
file
.
WeakDependency
{
if
j
==
i
{
return
true
}
}
return
false
}
// Generate the imports
func
(
g
*
Generator
)
generateImports
()
{
// We almost always need a proto import. Rather than computing when we
// do, which is tricky when there's a plugin, just import it and
// reference it later. The same argument applies to the fmt and math packages.
if
gogoproto
.
ImportsGoGoProto
(
g
.
file
.
FileDescriptorProto
)
{
g
.
PrintImport
(
g
.
Pkg
[
"proto"
],
g
.
ImportPrefix
+
"github.com/gogo/protobuf/proto"
)
}
else
{
g
.
PrintImport
(
g
.
Pkg
[
"proto"
],
g
.
ImportPrefix
+
"github.com/golang/protobuf/proto"
)
}
g
.
PrintImport
(
g
.
Pkg
[
"fmt"
],
"fmt"
)
g
.
PrintImport
(
g
.
Pkg
[
"math"
],
"math"
)
for
i
,
s
:=
range
g
.
file
.
Dependency
{
fd
:=
g
.
fileByName
(
s
)
// Do not import our own package.
if
fd
.
PackageName
()
==
g
.
packageName
{
continue
}
filename
:=
goFileName
(
s
)
// By default, import path is the dirname of the Go filename.
importPath
:=
path
.
Dir
(
filename
)
if
substitution
,
ok
:=
g
.
ImportMap
[
s
];
ok
{
importPath
=
substitution
}
importPath
=
g
.
ImportPrefix
+
importPath
// Skip weak imports.
if
g
.
weak
(
int32
(
i
))
{
g
.
P
(
"// skipping weak import "
,
fd
.
PackageName
(),
" "
,
strconv
.
Quote
(
importPath
))
continue
}
if
_
,
ok
:=
g
.
usedPackages
[
fd
.
PackageName
()];
ok
{
g
.
PrintImport
(
fd
.
PackageName
(),
importPath
)
}
else
{
// TODO: Re-enable this when we are more feature-complete.
// For instance, some protos use foreign field extensions, which we don't support.
// Until then, this is just annoying spam.
//log.Printf("protoc-gen-go: discarding unused import from %v: %v", *g.file.Name, s)
g
.
P
(
"// discarding unused import "
,
fd
.
PackageName
(),
" "
,
strconv
.
Quote
(
importPath
))
}
}
g
.
P
()
for
_
,
s
:=
range
g
.
customImports
{
s1
:=
strings
.
Map
(
badToUnderscore
,
s
)
g
.
PrintImport
(
s1
,
s
)
}
g
.
P
()
// TODO: may need to worry about uniqueness across plugins
for
_
,
p
:=
range
plugins
{
p
.
GenerateImports
(
g
.
file
)
g
.
P
()
}
g
.
P
(
"// Reference imports to suppress errors if they are not otherwise used."
)
g
.
P
(
"var _ = "
,
g
.
Pkg
[
"proto"
],
".Marshal"
)
g
.
P
(
"var _ = "
,
g
.
Pkg
[
"fmt"
],
".Errorf"
)
g
.
P
(
"var _ = "
,
g
.
Pkg
[
"math"
],
".Inf"
)
g
.
P
()
}
func
(
g
*
Generator
)
generateImported
(
id
*
ImportedDescriptor
)
{
// Don't generate public import symbols for files that we are generating
// code for, since those symbols will already be in this package.
// We can't simply avoid creating the ImportedDescriptor objects,
// because g.genFiles isn't populated at that stage.
tn
:=
id
.
TypeName
()
sn
:=
tn
[
len
(
tn
)
-
1
]
df
:=
g
.
FileOf
(
id
.
o
.
File
())
filename
:=
*
df
.
Name
for
_
,
fd
:=
range
g
.
genFiles
{
if
*
fd
.
Name
==
filename
{
g
.
P
(
"// Ignoring public import of "
,
sn
,
" from "
,
filename
)
g
.
P
()
return
}
}
g
.
P
(
"// "
,
sn
,
" from public import "
,
filename
)
g
.
usedPackages
[
df
.
PackageName
()]
=
true
for
_
,
sym
:=
range
df
.
exported
[
id
.
o
]
{
sym
.
GenerateAlias
(
g
,
df
.
PackageName
())
}
g
.
P
()
}
// Generate the enum definitions for this EnumDescriptor.
func
(
g
*
Generator
)
generateEnum
(
enum
*
EnumDescriptor
)
{
// The full type name
typeName
:=
enum
.
TypeName
()
// The full type name, CamelCased.
ccTypeName
:=
CamelCaseSlice
(
typeName
)
ccPrefix
:=
enum
.
prefix
()
g
.
PrintComments
(
enum
.
path
)
if
!
gogoproto
.
EnabledGoEnumPrefix
(
enum
.
file
,
enum
.
EnumDescriptorProto
)
{
ccPrefix
=
""
}
g
.
P
(
"type "
,
ccTypeName
,
" int32"
)
g
.
file
.
addExport
(
enum
,
enumSymbol
{
ccTypeName
,
enum
.
proto3
()})
g
.
P
(
"const ("
)
g
.
In
()
for
i
,
e
:=
range
enum
.
Value
{
g
.
PrintComments
(
fmt
.
Sprintf
(
"%s,%d,%d"
,
enum
.
path
,
enumValuePath
,
i
))
name
:=
ccPrefix
+
*
e
.
Name
g
.
P
(
name
,
" "
,
ccTypeName
,
" = "
,
e
.
Number
)
g
.
file
.
addExport
(
enum
,
constOrVarSymbol
{
name
,
"const"
,
ccTypeName
})
}
g
.
Out
()
g
.
P
(
")"
)
g
.
P
(
"var "
,
ccTypeName
,
"_name = map[int32]string{"
)
g
.
In
()
generated
:=
make
(
map
[
int32
]
bool
)
// avoid duplicate values
for
_
,
e
:=
range
enum
.
Value
{
duplicate
:=
""
if
_
,
present
:=
generated
[
*
e
.
Number
];
present
{
duplicate
=
"// Duplicate value: "
}
g
.
P
(
duplicate
,
e
.
Number
,
": "
,
strconv
.
Quote
(
*
e
.
Name
),
","
)
generated
[
*
e
.
Number
]
=
true
}
g
.
Out
()
g
.
P
(
"}"
)
g
.
P
(
"var "
,
ccTypeName
,
"_value = map[string]int32{"
)
g
.
In
()
for
_
,
e
:=
range
enum
.
Value
{
g
.
P
(
strconv
.
Quote
(
*
e
.
Name
),
": "
,
e
.
Number
,
","
)
}
g
.
Out
()
g
.
P
(
"}"
)
if
!
enum
.
proto3
()
{
g
.
P
(
"func (x "
,
ccTypeName
,
") Enum() *"
,
ccTypeName
,
" {"
)
g
.
In
()
g
.
P
(
"p := new("
,
ccTypeName
,
")"
)
g
.
P
(
"*p = x"
)
g
.
P
(
"return p"
)
g
.
Out
()
g
.
P
(
"}"
)
}
if
gogoproto
.
IsGoEnumStringer
(
g
.
file
.
FileDescriptorProto
,
enum
.
EnumDescriptorProto
)
{
g
.
P
(
"func (x "
,
ccTypeName
,
") String() string {"
)
g
.
In
()
g
.
P
(
"return "
,
g
.
Pkg
[
"proto"
],
".EnumName("
,
ccTypeName
,
"_name, int32(x))"
)
g
.
Out
()
g
.
P
(
"}"
)
}
if
!
enum
.
proto3
()
&&
!
gogoproto
.
IsGoEnumStringer
(
g
.
file
.
FileDescriptorProto
,
enum
.
EnumDescriptorProto
)
{
g
.
P
(
"func (x "
,
ccTypeName
,
") MarshalJSON() ([]byte, error) {"
)
g
.
In
()
g
.
P
(
"return "
,
g
.
Pkg
[
"proto"
],
".MarshalJSONEnum("
,
ccTypeName
,
"_name, int32(x))"
)
g
.
Out
()
g
.
P
(
"}"
)
}
if
!
enum
.
proto3
()
{
g
.
P
(
"func (x *"
,
ccTypeName
,
") UnmarshalJSON(data []byte) error {"
)
g
.
In
()
g
.
P
(
"value, err := "
,
g
.
Pkg
[
"proto"
],
".UnmarshalJSONEnum("
,
ccTypeName
,
`_value, data, "`
,
ccTypeName
,
`")`
)
g
.
P
(
"if err != nil {"
)
g
.
In
()
g
.
P
(
"return err"
)
g
.
Out
()
g
.
P
(
"}"
)
g
.
P
(
"*x = "
,
ccTypeName
,
"(value)"
)
g
.
P
(
"return nil"
)
g
.
Out
()
g
.
P
(
"}"
)
}
g
.
P
()
}
// The tag is a string like "varint,2,opt,name=fieldname,def=7" that
// identifies details of the field for the protocol buffer marshaling and unmarshaling
// code. The fields are:
// wire encoding
// protocol tag number
// opt,req,rep for optional, required, or repeated
// packed whether the encoding is "packed" (optional; repeated primitives only)
// name= the original declared name
// enum= the name of the enum type if it is an enum-typed field.
// proto3 if this field is in a proto3 message
// def= string representation of the default value, if any.
// The default value must be in a representation that can be used at run-time
// to generate the default value. Thus bools become 0 and 1, for instance.
func
(
g
*
Generator
)
goTag
(
message
*
Descriptor
,
field
*
descriptor
.
FieldDescriptorProto
,
wiretype
string
)
string
{
optrepreq
:=
""
switch
{
case
isOptional
(
field
)
:
optrepreq
=
"opt"
case
isRequired
(
field
)
:
optrepreq
=
"req"
case
isRepeated
(
field
)
:
optrepreq
=
"rep"
}
var
defaultValue
string
if
dv
:=
field
.
DefaultValue
;
dv
!=
nil
{
// set means an explicit default
defaultValue
=
*
dv
// Some types need tweaking.
switch
*
field
.
Type
{
case
descriptor
.
FieldDescriptorProto_TYPE_BOOL
:
if
defaultValue
==
"true"
{
defaultValue
=
"1"
}
else
{
defaultValue
=
"0"
}
case
descriptor
.
FieldDescriptorProto_TYPE_STRING
,
descriptor
.
FieldDescriptorProto_TYPE_BYTES
:
// Nothing to do. Quoting is done for the whole tag.
case
descriptor
.
FieldDescriptorProto_TYPE_ENUM
:
// For enums we need to provide the integer constant.
obj
:=
g
.
ObjectNamed
(
field
.
GetTypeName
())
if
id
,
ok
:=
obj
.
(
*
ImportedDescriptor
);
ok
{
// It is an enum that was publicly imported.
// We need the underlying type.
obj
=
id
.
o
}
enum
,
ok
:=
obj
.
(
*
EnumDescriptor
)
if
!
ok
{
log
.
Printf
(
"obj is a %T"
,
obj
)
if
id
,
ok
:=
obj
.
(
*
ImportedDescriptor
);
ok
{
log
.
Printf
(
"id.o is a %T"
,
id
.
o
)
}
g
.
Fail
(
"unknown enum type"
,
CamelCaseSlice
(
obj
.
TypeName
()))
}
defaultValue
=
enum
.
integerValueAsString
(
defaultValue
)
}
defaultValue
=
",def="
+
defaultValue
}
enum
:=
""
if
*
field
.
Type
==
descriptor
.
FieldDescriptorProto_TYPE_ENUM
{
// We avoid using obj.PackageName(), because we want to use the
// original (proto-world) package name.
obj
:=
g
.
ObjectNamed
(
field
.
GetTypeName
())
if
id
,
ok
:=
obj
.
(
*
ImportedDescriptor
);
ok
{
obj
=
id
.
o
}
enum
=
",enum="
if
pkg
:=
obj
.
File
()
.
GetPackage
();
pkg
!=
""
{
enum
+=
pkg
+
"."
}
enum
+=
CamelCaseSlice
(
obj
.
TypeName
())
}
packed
:=
""
if
field
.
Options
!=
nil
&&
field
.
Options
.
GetPacked
()
{
packed
=
",packed"
}
fieldName
:=
field
.
GetName
()
name
:=
fieldName
if
*
field
.
Type
==
descriptor
.
FieldDescriptorProto_TYPE_GROUP
{
// We must use the type name for groups instead of
// the field name to preserve capitalization.
// type_name in FieldDescriptorProto is fully-qualified,
// but we only want the local part.
name
=
*
field
.
TypeName
if
i
:=
strings
.
LastIndex
(
name
,
"."
);
i
>=
0
{
name
=
name
[
i
+
1
:
]
}
}
name
=
",name="
+
name
embed
:=
""
if
gogoproto
.
IsEmbed
(
field
)
{
embed
=
",embedded="
+
fieldName
}
ctype
:=
""
if
gogoproto
.
IsCustomType
(
field
)
{
ctype
=
",customtype="
+
gogoproto
.
GetCustomType
(
field
)
}
casttype
:=
""
if
gogoproto
.
IsCastType
(
field
)
{
casttype
=
",casttype="
+
gogoproto
.
GetCastType
(
field
)
}
if
message
.
proto3
()
{
// We only need the extra tag for []byte fields;
// no need to add noise for the others.
if
*
field
.
Type
!=
descriptor
.
FieldDescriptorProto_TYPE_MESSAGE
&&
*
field
.
Type
!=
descriptor
.
FieldDescriptorProto_TYPE_GROUP
&&
!
field
.
IsRepeated
()
{
name
+=
",proto3"
}
}
oneof
:=
""
if
field
.
OneofIndex
!=
nil
{
oneof
=
",oneof"
}
return
strconv
.
Quote
(
fmt
.
Sprintf
(
"%s,%d,%s%s%s%s%s%s%s%s%s"
,
wiretype
,
field
.
GetNumber
(),
optrepreq
,
packed
,
name
,
enum
,
oneof
,
defaultValue
,
embed
,
ctype
,
casttype
))
}
func
needsStar
(
field
*
descriptor
.
FieldDescriptorProto
,
proto3
bool
,
allowOneOf
bool
)
bool
{
if
isRepeated
(
field
)
&&
(
*
field
.
Type
!=
descriptor
.
FieldDescriptorProto_TYPE_MESSAGE
)
&&
(
*
field
.
Type
!=
descriptor
.
FieldDescriptorProto_TYPE_GROUP
)
{
return
false
}
if
*
field
.
Type
==
descriptor
.
FieldDescriptorProto_TYPE_BYTES
&&
!
gogoproto
.
IsCustomType
(
field
)
{
return
false
}
if
!
gogoproto
.
IsNullable
(
field
)
{
return
false
}
if
field
.
OneofIndex
!=
nil
&&
allowOneOf
&&
(
*
field
.
Type
!=
descriptor
.
FieldDescriptorProto_TYPE_MESSAGE
)
&&
(
*
field
.
Type
!=
descriptor
.
FieldDescriptorProto_TYPE_GROUP
)
{
return
false
}
if
proto3
&&
(
*
field
.
Type
!=
descriptor
.
FieldDescriptorProto_TYPE_MESSAGE
)
&&
(
*
field
.
Type
!=
descriptor
.
FieldDescriptorProto_TYPE_GROUP
)
{
return
false
}
return
true
}
// TypeName is the printed name appropriate for an item. If the object is in the current file,
// TypeName drops the package name and underscores the rest.
// Otherwise the object is from another package; and the result is the underscored
// package name followed by the item name.
// The result always has an initial capital.
func
(
g
*
Generator
)
TypeName
(
obj
Object
)
string
{
return
g
.
DefaultPackageName
(
obj
)
+
CamelCaseSlice
(
obj
.
TypeName
())
}
// TypeNameWithPackage is like TypeName, but always includes the package
// name even if the object is in our own package.
func
(
g
*
Generator
)
TypeNameWithPackage
(
obj
Object
)
string
{
return
obj
.
PackageName
()
+
CamelCaseSlice
(
obj
.
TypeName
())
}
// GoType returns a string representing the type name, and the wire type
func
(
g
*
Generator
)
GoType
(
message
*
Descriptor
,
field
*
descriptor
.
FieldDescriptorProto
)
(
typ
string
,
wire
string
)
{
// TODO: Options.
switch
*
field
.
Type
{
case
descriptor
.
FieldDescriptorProto_TYPE_DOUBLE
:
typ
,
wire
=
"float64"
,
"fixed64"
case
descriptor
.
FieldDescriptorProto_TYPE_FLOAT
:
typ
,
wire
=
"float32"
,
"fixed32"
case
descriptor
.
FieldDescriptorProto_TYPE_INT64
:
typ
,
wire
=
"int64"
,
"varint"
case
descriptor
.
FieldDescriptorProto_TYPE_UINT64
:
typ
,
wire
=
"uint64"
,
"varint"
case
descriptor
.
FieldDescriptorProto_TYPE_INT32
:
typ
,
wire
=
"int32"
,
"varint"
case
descriptor
.
FieldDescriptorProto_TYPE_UINT32
:
typ
,
wire
=
"uint32"
,
"varint"
case
descriptor
.
FieldDescriptorProto_TYPE_FIXED64
:
typ
,
wire
=
"uint64"
,
"fixed64"
case
descriptor
.
FieldDescriptorProto_TYPE_FIXED32
:
typ
,
wire
=
"uint32"
,
"fixed32"
case
descriptor
.
FieldDescriptorProto_TYPE_BOOL
:
typ
,
wire
=
"bool"
,
"varint"
case
descriptor
.
FieldDescriptorProto_TYPE_STRING
:
typ
,
wire
=
"string"
,
"bytes"
case
descriptor
.
FieldDescriptorProto_TYPE_GROUP
:
desc
:=
g
.
ObjectNamed
(
field
.
GetTypeName
())
typ
,
wire
=
g
.
TypeName
(
desc
),
"group"
case
descriptor
.
FieldDescriptorProto_TYPE_MESSAGE
:
desc
:=
g
.
ObjectNamed
(
field
.
GetTypeName
())
typ
,
wire
=
g
.
TypeName
(
desc
),
"bytes"
case
descriptor
.
FieldDescriptorProto_TYPE_BYTES
:
typ
,
wire
=
"[]byte"
,
"bytes"
case
descriptor
.
FieldDescriptorProto_TYPE_ENUM
:
desc
:=
g
.
ObjectNamed
(
field
.
GetTypeName
())
typ
,
wire
=
g
.
TypeName
(
desc
),
"varint"
case
descriptor
.
FieldDescriptorProto_TYPE_SFIXED32
:
typ
,
wire
=
"int32"
,
"fixed32"
case
descriptor
.
FieldDescriptorProto_TYPE_SFIXED64
:
typ
,
wire
=
"int64"
,
"fixed64"
case
descriptor
.
FieldDescriptorProto_TYPE_SINT32
:
typ
,
wire
=
"int32"
,
"zigzag32"
case
descriptor
.
FieldDescriptorProto_TYPE_SINT64
:
typ
,
wire
=
"int64"
,
"zigzag64"
default
:
g
.
Fail
(
"unknown type for"
,
field
.
GetName
())
}
if
gogoproto
.
IsCustomType
(
field
)
&&
gogoproto
.
IsCastType
(
field
)
{
g
.
Fail
(
field
.
GetName
()
+
" cannot be custom type and cast type"
)
}
if
gogoproto
.
IsCustomType
(
field
)
{
var
packageName
string
var
err
error
packageName
,
typ
,
err
=
getCustomType
(
field
)
if
err
!=
nil
{
g
.
Fail
(
err
.
Error
())
}
if
len
(
packageName
)
>
0
{
g
.
customImports
=
append
(
g
.
customImports
,
packageName
)
}
}
if
gogoproto
.
IsCastType
(
field
)
{
var
packageName
string
var
err
error
packageName
,
typ
,
err
=
getCastType
(
field
)
if
err
!=
nil
{
g
.
Fail
(
err
.
Error
())
}
if
len
(
packageName
)
>
0
{
g
.
customImports
=
append
(
g
.
customImports
,
packageName
)
}
}
if
needsStar
(
field
,
g
.
file
.
proto3
,
message
!=
nil
&&
message
.
allowOneof
())
{
typ
=
"*"
+
typ
}
if
isRepeated
(
field
)
{
typ
=
"[]"
+
typ
}
return
}
func
(
g
*
Generator
)
RecordTypeUse
(
t
string
)
{
if
obj
,
ok
:=
g
.
typeNameToObject
[
t
];
ok
{
// Call ObjectNamed to get the true object to record the use.
obj
=
g
.
ObjectNamed
(
t
)
g
.
usedPackages
[
obj
.
PackageName
()]
=
true
}
}
// Method names that may be generated. Fields with these names get an
// underscore appended.
var
methodNames
=
[
...
]
string
{
"Reset"
,
"String"
,
"ProtoMessage"
,
"Marshal"
,
"Unmarshal"
,
"ExtensionRangeArray"
,
"ExtensionMap"
,
"Descriptor"
,
"Size"
,
"MarshalTo"
,
"Equal"
,
"VerboseEqual"
,
"GoString"
,
}
// Generate the type and default constant definitions for this Descriptor.
func
(
g
*
Generator
)
generateMessage
(
message
*
Descriptor
)
{
// The full type name
typeName
:=
message
.
TypeName
()
// The full type name, CamelCased.
ccTypeName
:=
CamelCaseSlice
(
typeName
)
usedNames
:=
make
(
map
[
string
]
bool
)
for
_
,
n
:=
range
methodNames
{
usedNames
[
n
]
=
true
}
fieldNames
:=
make
(
map
[
*
descriptor
.
FieldDescriptorProto
]
string
)
fieldGetterNames
:=
make
(
map
[
*
descriptor
.
FieldDescriptorProto
]
string
)
fieldTypes
:=
make
(
map
[
*
descriptor
.
FieldDescriptorProto
]
string
)
mapFieldTypes
:=
make
(
map
[
*
descriptor
.
FieldDescriptorProto
]
string
)
oneofFieldName
:=
make
(
map
[
int32
]
string
)
// indexed by oneof_index field of FieldDescriptorProto
oneofDisc
:=
make
(
map
[
int32
]
string
)
// name of discriminator method
oneofTypeName
:=
make
(
map
[
*
descriptor
.
FieldDescriptorProto
]
string
)
// without star
oneofInsertPoints
:=
make
(
map
[
int32
]
int
)
// oneof_index => offset of g.Buffer
g
.
PrintComments
(
message
.
path
)
g
.
P
(
"type "
,
ccTypeName
,
" struct {"
)
g
.
In
()
// allocNames finds a conflict-free variation of the given strings,
// consistently mutating their suffixes.
// It returns the same number of strings.
allocNames
:=
func
(
ns
...
string
)
[]
string
{
Loop
:
for
{
for
_
,
n
:=
range
ns
{
if
usedNames
[
n
]
{
for
i
:=
range
ns
{
ns
[
i
]
+=
"_"
}
continue
Loop
}
}
for
_
,
n
:=
range
ns
{
usedNames
[
n
]
=
true
}
return
ns
}
}
for
i
,
field
:=
range
message
.
Field
{
// Allocate the getter and the field at the same time so name
// collisions create field/method consistent names.
// TODO: This allocation occurs based on the order of the fields
// in the proto file, meaning that a change in the field
// ordering can change generated Method/Field names.
base
:=
CamelCase
(
*
field
.
Name
)
if
gogoproto
.
IsCustomName
(
field
)
{
base
=
gogoproto
.
GetCustomName
(
field
)
}
ns
:=
allocNames
(
base
,
"Get"
+
base
)
fieldName
,
fieldGetterName
:=
ns
[
0
],
ns
[
1
]
typename
,
wiretype
:=
g
.
GoType
(
message
,
field
)
jsonName
:=
*
field
.
Name
jsonTag
:=
jsonName
+
",omitempty"
repeatedNativeType
:=
(
!
field
.
IsMessage
()
&&
!
gogoproto
.
IsCustomType
(
field
)
&&
field
.
IsRepeated
())
if
!
gogoproto
.
IsNullable
(
field
)
&&
!
repeatedNativeType
{
jsonTag
=
jsonName
}
gogoJsonTag
:=
gogoproto
.
GetJsonTag
(
field
)
if
gogoJsonTag
!=
nil
{
jsonTag
=
*
gogoJsonTag
}
gogoMoreTags
:=
gogoproto
.
GetMoreTags
(
field
)
moreTags
:=
""
if
gogoMoreTags
!=
nil
{
moreTags
=
" "
+
*
gogoMoreTags
}
tag
:=
fmt
.
Sprintf
(
"protobuf:%s json:%q%s"
,
g
.
goTag
(
message
,
field
,
wiretype
),
jsonTag
,
moreTags
)
fieldNames
[
field
]
=
fieldName
fieldGetterNames
[
field
]
=
fieldGetterName
if
*
field
.
Type
==
descriptor
.
FieldDescriptorProto_TYPE_MESSAGE
&&
gogoproto
.
IsEmbed
(
field
)
{
fieldName
=
""
}
oneof
:=
field
.
OneofIndex
!=
nil
&&
message
.
allowOneof
()
if
oneof
&&
oneofFieldName
[
*
field
.
OneofIndex
]
==
""
{
odp
:=
message
.
OneofDecl
[
int
(
*
field
.
OneofIndex
)]
fname
:=
allocNames
(
CamelCase
(
odp
.
GetName
()))[
0
]
// This is the first field of a oneof we haven't seen before.
// Generate the union field.
com
:=
g
.
PrintComments
(
fmt
.
Sprintf
(
"%s,%d,%d"
,
message
.
path
,
messageOneofPath
,
*
field
.
OneofIndex
))
if
com
{
g
.
P
(
"//"
)
}
g
.
P
(
"// Types that are valid to be assigned to "
,
fname
,
":"
)
// Generate the rest of this comment later,
// when we've computed any disambiguation.
oneofInsertPoints
[
*
field
.
OneofIndex
]
=
g
.
Buffer
.
Len
()
dname
:=
"is"
+
ccTypeName
+
"_"
+
fname
oneofFieldName
[
*
field
.
OneofIndex
]
=
fname
oneofDisc
[
*
field
.
OneofIndex
]
=
dname
tag
:=
`protobuf_oneof:"`
+
odp
.
GetName
()
+
`"`
g
.
P
(
fname
,
" "
,
dname
,
" `"
,
tag
,
"`"
)
}
if
*
field
.
Type
==
descriptor
.
FieldDescriptorProto_TYPE_MESSAGE
{
desc
:=
g
.
ObjectNamed
(
field
.
GetTypeName
())
if
d
,
ok
:=
desc
.
(
*
Descriptor
);
ok
&&
d
.
GetOptions
()
.
GetMapEntry
()
{
// Figure out the Go types and tags for the key and value types.
keyField
,
valField
:=
d
.
Field
[
0
],
d
.
Field
[
1
]
keyType
,
keyWire
:=
g
.
GoType
(
d
,
keyField
)
valType
,
valWire
:=
g
.
GoType
(
d
,
valField
)
keyTag
,
valTag
:=
g
.
goTag
(
d
,
keyField
,
keyWire
),
g
.
goTag
(
d
,
valField
,
valWire
)
// We don't use stars, except for message-typed values.
// Message and enum types are the only two possibly foreign types used in maps,
// so record their use. They are not permitted as map keys.
keyType
=
strings
.
TrimPrefix
(
keyType
,
"*"
)
switch
*
valField
.
Type
{
case
descriptor
.
FieldDescriptorProto_TYPE_ENUM
:
valType
=
strings
.
TrimPrefix
(
valType
,
"*"
)
g
.
RecordTypeUse
(
valField
.
GetTypeName
())
case
descriptor
.
FieldDescriptorProto_TYPE_MESSAGE
:
g
.
RecordTypeUse
(
valField
.
GetTypeName
())
default
:
valType
=
strings
.
TrimPrefix
(
valType
,
"*"
)
}
typename
=
fmt
.
Sprintf
(
"map[%s]%s"
,
keyType
,
valType
)
mapFieldTypes
[
field
]
=
typename
// record for the getter generation
tag
+=
fmt
.
Sprintf
(
" protobuf_key:%s protobuf_val:%s"
,
keyTag
,
valTag
)
}
}
fieldTypes
[
field
]
=
typename
if
oneof
{
tname
:=
ccTypeName
+
"_"
+
fieldName
// It is possible for this to collide with a message or enum
// nested in this message. Check for collisions.
for
{
ok
:=
true
for
_
,
desc
:=
range
message
.
nested
{
if
CamelCaseSlice
(
desc
.
TypeName
())
==
tname
{
ok
=
false
break
}
}
for
_
,
enum
:=
range
message
.
enums
{
if
CamelCaseSlice
(
enum
.
TypeName
())
==
tname
{
ok
=
false
break
}
}
if
!
ok
{
tname
+=
"_"
continue
}
break
}
oneofTypeName
[
field
]
=
tname
continue
}
g
.
PrintComments
(
fmt
.
Sprintf
(
"%s,%d,%d"
,
message
.
path
,
messageFieldPath
,
i
))
g
.
P
(
fieldName
,
"
\t
"
,
typename
,
"
\t
`"
,
tag
,
"`"
)
g
.
RecordTypeUse
(
field
.
GetTypeName
())
}
if
len
(
message
.
ExtensionRange
)
>
0
{
if
gogoproto
.
HasExtensionsMap
(
g
.
file
.
FileDescriptorProto
,
message
.
DescriptorProto
)
{
g
.
P
(
"XXX_extensions
\t\t
map[int32]"
,
g
.
Pkg
[
"proto"
],
".Extension `json:
\"
-
\"
`"
)
}
else
{
g
.
P
(
"XXX_extensions
\t\t
[]byte `protobuf:
\"
bytes,0,opt
\"
json:
\"
-
\"
`"
)
}
}
if
gogoproto
.
HasUnrecognized
(
g
.
file
.
FileDescriptorProto
,
message
.
DescriptorProto
)
&&
!
message
.
proto3
()
{
g
.
P
(
"XXX_unrecognized
\t
[]byte `json:
\"
-
\"
`"
)
}
g
.
Out
()
g
.
P
(
"}"
)
// Update g.Buffer to list valid oneof types.
// We do this down here, after we've disambiguated the oneof type names.
// We go in reverse order of insertion point to avoid invalidating offsets.
for
oi
:=
int32
(
len
(
message
.
OneofDecl
));
oi
>=
0
;
oi
--
{
ip
:=
oneofInsertPoints
[
oi
]
all
:=
g
.
Buffer
.
Bytes
()
rem
:=
all
[
ip
:
]
g
.
Buffer
=
bytes
.
NewBuffer
(
all
[
:
ip
:
ip
])
// set cap so we don't scribble on rem
for
_
,
field
:=
range
message
.
Field
{
if
field
.
OneofIndex
==
nil
||
*
field
.
OneofIndex
!=
oi
{
continue
}
g
.
P
(
"//
\t
*"
,
oneofTypeName
[
field
])
}
g
.
Buffer
.
Write
(
rem
)
}
// Reset, String and ProtoMessage methods.
g
.
P
(
"func (m *"
,
ccTypeName
,
") Reset() { *m = "
,
ccTypeName
,
"{} }"
)
if
gogoproto
.
EnabledGoStringer
(
g
.
file
.
FileDescriptorProto
,
message
.
DescriptorProto
)
{
g
.
P
(
"func (m *"
,
ccTypeName
,
") String() string { return "
,
g
.
Pkg
[
"proto"
],
".CompactTextString(m) }"
)
}
g
.
P
(
"func (*"
,
ccTypeName
,
") ProtoMessage() {}"
)
// Extension support methods
var
hasExtensions
,
isMessageSet
bool
if
len
(
message
.
ExtensionRange
)
>
0
{
hasExtensions
=
true
// message_set_wire_format only makes sense when extensions are defined.
if
opts
:=
message
.
Options
;
opts
!=
nil
&&
opts
.
GetMessageSetWireFormat
()
{
isMessageSet
=
true
g
.
P
()
g
.
P
(
"func (m *"
,
ccTypeName
,
") Marshal() ([]byte, error) {"
)
g
.
In
()
g
.
P
(
"return "
,
g
.
Pkg
[
"proto"
],
".MarshalMessageSet(m.ExtensionMap())"
)
g
.
Out
()
g
.
P
(
"}"
)
g
.
P
(
"func (m *"
,
ccTypeName
,
") Unmarshal(buf []byte) error {"
)
g
.
In
()
g
.
P
(
"return "
,
g
.
Pkg
[
"proto"
],
".UnmarshalMessageSet(buf, m.ExtensionMap())"
)
g
.
Out
()
g
.
P
(
"}"
)
g
.
P
(
"func (m *"
,
ccTypeName
,
") MarshalJSON() ([]byte, error) {"
)
g
.
In
()
g
.
P
(
"return "
,
g
.
Pkg
[
"proto"
],
".MarshalMessageSetJSON(m.XXX_extensions)"
)
g
.
Out
()
g
.
P
(
"}"
)
g
.
P
(
"func (m *"
,
ccTypeName
,
") UnmarshalJSON(buf []byte) error {"
)
g
.
In
()
g
.
P
(
"return "
,
g
.
Pkg
[
"proto"
],
".UnmarshalMessageSetJSON(buf, m.XXX_extensions)"
)
g
.
Out
()
g
.
P
(
"}"
)
g
.
P
(
"// ensure "
,
ccTypeName
,
" satisfies proto.Marshaler and proto.Unmarshaler"
)
g
.
P
(
"var _ "
,
g
.
Pkg
[
"proto"
],
".Marshaler = (*"
,
ccTypeName
,
")(nil)"
)
g
.
P
(
"var _ "
,
g
.
Pkg
[
"proto"
],
".Unmarshaler = (*"
,
ccTypeName
,
")(nil)"
)
}
g
.
P
()
g
.
P
(
"var extRange_"
,
ccTypeName
,
" = []"
,
g
.
Pkg
[
"proto"
],
".ExtensionRange{"
)
g
.
In
()
for
_
,
r
:=
range
message
.
ExtensionRange
{
end
:=
fmt
.
Sprint
(
*
r
.
End
-
1
)
// make range inclusive on both ends
g
.
P
(
"{"
,
r
.
Start
,
", "
,
end
,
"},"
)
}
g
.
Out
()
g
.
P
(
"}"
)
g
.
P
(
"func (*"
,
ccTypeName
,
") ExtensionRangeArray() []"
,
g
.
Pkg
[
"proto"
],
".ExtensionRange {"
)
g
.
In
()
g
.
P
(
"return extRange_"
,
ccTypeName
)
g
.
Out
()
g
.
P
(
"}"
)
if
gogoproto
.
HasExtensionsMap
(
g
.
file
.
FileDescriptorProto
,
message
.
DescriptorProto
)
{
g
.
P
(
"func (m *"
,
ccTypeName
,
") ExtensionMap() map[int32]"
,
g
.
Pkg
[
"proto"
],
".Extension {"
)
g
.
In
()
g
.
P
(
"if m.XXX_extensions == nil {"
)
g
.
In
()
g
.
P
(
"m.XXX_extensions = make(map[int32]"
,
g
.
Pkg
[
"proto"
],
".Extension)"
)
g
.
Out
()
g
.
P
(
"}"
)
g
.
P
(
"return m.XXX_extensions"
)
g
.
Out
()
g
.
P
(
"}"
)
}
else
{
g
.
P
(
"func (m *"
,
ccTypeName
,
") GetExtensions() *[]byte {"
)
g
.
In
()
g
.
P
(
"if m.XXX_extensions == nil {"
)
g
.
In
()
g
.
P
(
"m.XXX_extensions = make([]byte, 0)"
)
g
.
Out
()
g
.
P
(
"}"
)
g
.
P
(
"return &m.XXX_extensions"
)
g
.
Out
()
g
.
P
(
"}"
)
}
}
// Default constants
defNames
:=
make
(
map
[
*
descriptor
.
FieldDescriptorProto
]
string
)
for
_
,
field
:=
range
message
.
Field
{
def
:=
field
.
GetDefaultValue
()
if
def
==
""
{
continue
}
if
!
gogoproto
.
IsNullable
(
field
)
{
g
.
Fail
(
"illegal default value: "
,
field
.
GetName
(),
" in "
,
message
.
GetName
(),
" is not nullable and is thus not allowed to have a default value"
)
}
fieldname
:=
"Default_"
+
ccTypeName
+
"_"
+
CamelCase
(
*
field
.
Name
)
defNames
[
field
]
=
fieldname
typename
,
_
:=
g
.
GoType
(
message
,
field
)
if
typename
[
0
]
==
'*'
{
typename
=
typename
[
1
:
]
}
kind
:=
"const "
switch
{
case
typename
==
"bool"
:
case
typename
==
"string"
:
def
=
strconv
.
Quote
(
def
)
case
typename
==
"[]byte"
:
def
=
"[]byte("
+
strconv
.
Quote
(
def
)
+
")"
kind
=
"var "
case
def
==
"inf"
,
def
==
"-inf"
,
def
==
"nan"
:
// These names are known to, and defined by, the protocol language.
switch
def
{
case
"inf"
:
def
=
"math.Inf(1)"
case
"-inf"
:
def
=
"math.Inf(-1)"
case
"nan"
:
def
=
"math.NaN()"
}
if
*
field
.
Type
==
descriptor
.
FieldDescriptorProto_TYPE_FLOAT
{
def
=
"float32("
+
def
+
")"
}
kind
=
"var "
case
*
field
.
Type
==
descriptor
.
FieldDescriptorProto_TYPE_ENUM
:
// Must be an enum. Need to construct the prefixed name.
obj
:=
g
.
ObjectNamed
(
field
.
GetTypeName
())
var
enum
*
EnumDescriptor
if
id
,
ok
:=
obj
.
(
*
ImportedDescriptor
);
ok
{
// The enum type has been publicly imported.
enum
,
_
=
id
.
o
.
(
*
EnumDescriptor
)
}
else
{
enum
,
_
=
obj
.
(
*
EnumDescriptor
)
}
if
enum
==
nil
{
log
.
Printf
(
"don't know how to generate constant for %s"
,
fieldname
)
continue
}
if
gogoproto
.
EnabledGoEnumPrefix
(
enum
.
file
,
enum
.
EnumDescriptorProto
)
{
def
=
g
.
DefaultPackageName
(
obj
)
+
enum
.
prefix
()
+
def
}
else
{
def
=
g
.
DefaultPackageName
(
obj
)
+
def
}
}
g
.
P
(
kind
,
fieldname
,
" "
,
typename
,
" = "
,
def
)
g
.
file
.
addExport
(
message
,
constOrVarSymbol
{
fieldname
,
kind
,
""
})
}
g
.
P
()
// Oneof per-field types, discriminants and getters.
if
message
.
allowOneof
()
{
// Generate unexported named types for the discriminant interfaces.
// We shouldn't have to do this, but there was (~19 Aug 2015) a compiler/linker bug
// that was triggered by using anonymous interfaces here.
// TODO: Revisit this and consider reverting back to anonymous interfaces.
for
oi
:=
range
message
.
OneofDecl
{
dname
:=
oneofDisc
[
int32
(
oi
)]
g
.
P
(
"type "
,
dname
,
" interface {"
)
g
.
In
()
g
.
P
(
dname
,
"()"
)
if
gogoproto
.
HasEqual
(
g
.
file
.
FileDescriptorProto
,
message
.
DescriptorProto
)
{
g
.
P
(
`Equal(interface{}) bool`
)
}
if
gogoproto
.
HasVerboseEqual
(
g
.
file
.
FileDescriptorProto
,
message
.
DescriptorProto
)
{
g
.
P
(
`VerboseEqual(interface{}) error`
)
}
if
gogoproto
.
IsMarshaler
(
g
.
file
.
FileDescriptorProto
,
message
.
DescriptorProto
)
||
gogoproto
.
IsUnsafeMarshaler
(
g
.
file
.
FileDescriptorProto
,
message
.
DescriptorProto
)
{
g
.
P
(
`MarshalTo([]byte) (int, error)`
)
}
if
gogoproto
.
IsSizer
(
g
.
file
.
FileDescriptorProto
,
message
.
DescriptorProto
)
{
g
.
P
(
`Size() int`
)
}
g
.
Out
()
g
.
P
(
"}"
)
}
g
.
P
()
for
_
,
field
:=
range
message
.
Field
{
if
field
.
OneofIndex
==
nil
{
continue
}
_
,
wiretype
:=
g
.
GoType
(
message
,
field
)
tag
:=
"protobuf:"
+
g
.
goTag
(
message
,
field
,
wiretype
)
g
.
P
(
"type "
,
oneofTypeName
[
field
],
" struct{ "
,
fieldNames
[
field
],
" "
,
fieldTypes
[
field
],
" `"
,
tag
,
"` }"
)
g
.
RecordTypeUse
(
field
.
GetTypeName
())
}
g
.
P
()
for
_
,
field
:=
range
message
.
Field
{
if
field
.
OneofIndex
==
nil
{
continue
}
g
.
P
(
"func (*"
,
oneofTypeName
[
field
],
") "
,
oneofDisc
[
*
field
.
OneofIndex
],
"() {}"
)
}
g
.
P
()
for
oi
:=
range
message
.
OneofDecl
{
fname
:=
oneofFieldName
[
int32
(
oi
)]
g
.
P
(
"func (m *"
,
ccTypeName
,
") Get"
,
fname
,
"() "
,
oneofDisc
[
int32
(
oi
)],
" {"
)
g
.
P
(
"if m != nil { return m."
,
fname
,
" }"
)
g
.
P
(
"return nil"
)
g
.
P
(
"}"
)
}
g
.
P
()
}
// Field getters
var
getters
[]
getterSymbol
for
_
,
field
:=
range
message
.
Field
{
oneof
:=
field
.
OneofIndex
!=
nil
&&
message
.
allowOneof
()
if
!
oneof
&&
!
gogoproto
.
HasGoGetters
(
g
.
file
.
FileDescriptorProto
,
message
.
DescriptorProto
)
{
continue
}
if
gogoproto
.
IsEmbed
(
field
)
||
gogoproto
.
IsCustomType
(
field
)
{
continue
}
fname
:=
fieldNames
[
field
]
typename
,
_
:=
g
.
GoType
(
message
,
field
)
if
t
,
ok
:=
mapFieldTypes
[
field
];
ok
{
typename
=
t
}
mname
:=
fieldGetterNames
[
field
]
star
:=
""
if
(
*
field
.
Type
!=
descriptor
.
FieldDescriptorProto_TYPE_MESSAGE
)
&&
(
*
field
.
Type
!=
descriptor
.
FieldDescriptorProto_TYPE_GROUP
)
&&
needsStar
(
field
,
g
.
file
.
proto3
,
message
!=
nil
&&
message
.
allowOneof
())
&&
typename
[
0
]
==
'*'
{
typename
=
typename
[
1
:
]
star
=
"*"
}
// In proto3, only generate getters for message fields and oneof fields.
if
message
.
proto3
()
&&
*
field
.
Type
!=
descriptor
.
FieldDescriptorProto_TYPE_MESSAGE
&&
!
oneof
{
continue
}
// Only export getter symbols for basic types,
// and for messages and enums in the same package.
// Groups are not exported.
// Foreign types can't be hoisted through a public import because
// the importer may not already be importing the defining .proto.
// As an example, imagine we have an import tree like this:
// A.proto -> B.proto -> C.proto
// If A publicly imports B, we need to generate the getters from B in A's output,
// but if one such getter returns something from C then we cannot do that
// because A is not importing C already.
var
getter
,
genType
bool
switch
*
field
.
Type
{
case
descriptor
.
FieldDescriptorProto_TYPE_GROUP
:
getter
=
false
case
descriptor
.
FieldDescriptorProto_TYPE_MESSAGE
,
descriptor
.
FieldDescriptorProto_TYPE_ENUM
:
// Only export getter if its return type is in this package.
getter
=
g
.
ObjectNamed
(
field
.
GetTypeName
())
.
PackageName
()
==
message
.
PackageName
()
genType
=
true
default
:
getter
=
true
}
if
getter
{
getters
=
append
(
getters
,
getterSymbol
{
name
:
mname
,
typ
:
typename
,
typeName
:
field
.
GetTypeName
(),
genType
:
genType
,
})
}
g
.
P
(
"func (m *"
,
ccTypeName
,
") "
+
mname
+
"() "
+
typename
+
" {"
)
g
.
In
()
def
,
hasDef
:=
defNames
[
field
]
typeDefaultIsNil
:=
false
// whether this field type's default value is a literal nil unless specified
switch
*
field
.
Type
{
case
descriptor
.
FieldDescriptorProto_TYPE_BYTES
:
typeDefaultIsNil
=
!
hasDef
case
descriptor
.
FieldDescriptorProto_TYPE_GROUP
,
descriptor
.
FieldDescriptorProto_TYPE_MESSAGE
:
typeDefaultIsNil
=
gogoproto
.
IsNullable
(
field
)
}
if
isRepeated
(
field
)
{
typeDefaultIsNil
=
true
}
if
typeDefaultIsNil
&&
!
oneof
{
// A bytes field with no explicit default needs less generated code,
// as does a message or group field, or a repeated field.
g
.
P
(
"if m != nil {"
)
g
.
In
()
g
.
P
(
"return m."
+
fname
)
g
.
Out
()
g
.
P
(
"}"
)
g
.
P
(
"return nil"
)
g
.
Out
()
g
.
P
(
"}"
)
g
.
P
()
continue
}
if
!
gogoproto
.
IsNullable
(
field
)
{
g
.
P
(
"if m != nil {"
)
g
.
In
()
g
.
P
(
"return m."
+
fname
)
g
.
Out
()
g
.
P
(
"}"
)
}
else
if
!
oneof
{
g
.
P
(
"if m != nil && m."
+
fname
+
" != nil {"
)
g
.
In
()
g
.
P
(
"return "
+
star
+
"m."
+
fname
)
g
.
Out
()
g
.
P
(
"}"
)
}
else
{
uname
:=
oneofFieldName
[
*
field
.
OneofIndex
]
tname
:=
oneofTypeName
[
field
]
g
.
P
(
"if x, ok := m.Get"
,
uname
,
"().(*"
,
tname
,
"); ok {"
)
g
.
P
(
"return x."
,
fname
)
g
.
P
(
"}"
)
}
if
hasDef
{
if
*
field
.
Type
!=
descriptor
.
FieldDescriptorProto_TYPE_BYTES
{
g
.
P
(
"return "
+
def
)
}
else
{
// The default is a []byte var.
// Make a copy when returning it to be safe.
g
.
P
(
"return append([]byte(nil), "
,
def
,
"...)"
)
}
}
else
{
switch
*
field
.
Type
{
case
descriptor
.
FieldDescriptorProto_TYPE_GROUP
,
descriptor
.
FieldDescriptorProto_TYPE_MESSAGE
:
if
field
.
OneofIndex
!=
nil
{
g
.
P
(
`return nil`
)
}
else
{
goTyp
,
_
:=
g
.
GoType
(
message
,
field
)
goTypName
:=
GoTypeToName
(
goTyp
)
g
.
P
(
"return "
,
goTypName
,
"{}"
)
}
case
descriptor
.
FieldDescriptorProto_TYPE_BOOL
:
g
.
P
(
"return false"
)
case
descriptor
.
FieldDescriptorProto_TYPE_STRING
:
g
.
P
(
`return ""`
)
case
descriptor
.
FieldDescriptorProto_TYPE_BYTES
:
// This is only possible for oneof fields.
g
.
P
(
"return nil"
)
case
descriptor
.
FieldDescriptorProto_TYPE_ENUM
:
// The default default for an enum is the first value in the enum,
// not zero.
obj
:=
g
.
ObjectNamed
(
field
.
GetTypeName
())
var
enum
*
EnumDescriptor
if
id
,
ok
:=
obj
.
(
*
ImportedDescriptor
);
ok
{
// The enum type has been publicly imported.
enum
,
_
=
id
.
o
.
(
*
EnumDescriptor
)
}
else
{
enum
,
_
=
obj
.
(
*
EnumDescriptor
)
}
if
enum
==
nil
{
log
.
Printf
(
"don't know how to generate getter for %s"
,
field
.
GetName
())
continue
}
if
len
(
enum
.
Value
)
==
0
{
g
.
P
(
"return 0 // empty enum"
)
}
else
{
first
:=
enum
.
Value
[
0
]
.
GetName
()
if
gogoproto
.
EnabledGoEnumPrefix
(
enum
.
file
,
enum
.
EnumDescriptorProto
)
{
g
.
P
(
"return "
,
g
.
DefaultPackageName
(
obj
)
+
enum
.
prefix
()
+
first
)
}
else
{
g
.
P
(
"return "
,
g
.
DefaultPackageName
(
obj
)
+
first
)
}
}
default
:
g
.
P
(
"return 0"
)
}
}
g
.
Out
()
g
.
P
(
"}"
)
g
.
P
()
}
if
!
message
.
group
{
ms
:=
&
messageSymbol
{
sym
:
ccTypeName
,
hasExtensions
:
hasExtensions
,
isMessageSet
:
isMessageSet
,
getters
:
getters
}
g
.
file
.
addExport
(
message
,
ms
)
}
// Oneof functions
if
len
(
message
.
OneofDecl
)
>
0
&&
message
.
allowOneof
()
{
fieldWire
:=
make
(
map
[
*
descriptor
.
FieldDescriptorProto
]
string
)
// method
enc
:=
"_"
+
ccTypeName
+
"_OneofMarshaler"
dec
:=
"_"
+
ccTypeName
+
"_OneofUnmarshaler"
encSig
:=
"(msg "
+
g
.
Pkg
[
"proto"
]
+
".Message, b *"
+
g
.
Pkg
[
"proto"
]
+
".Buffer) error"
decSig
:=
"(msg "
+
g
.
Pkg
[
"proto"
]
+
".Message, tag, wire int, b *"
+
g
.
Pkg
[
"proto"
]
+
".Buffer) (bool, error)"
g
.
P
(
"// XXX_OneofFuncs is for the internal use of the proto package."
)
g
.
P
(
"func (*"
,
ccTypeName
,
") XXX_OneofFuncs() (func"
,
encSig
,
", func"
,
decSig
,
", []interface{}) {"
)
g
.
P
(
"return "
,
enc
,
", "
,
dec
,
", []interface{}{"
)
for
_
,
field
:=
range
message
.
Field
{
if
field
.
OneofIndex
==
nil
{
continue
}
g
.
P
(
"(*"
,
oneofTypeName
[
field
],
")(nil),"
)
}
g
.
P
(
"}"
)
g
.
P
(
"}"
)
g
.
P
()
// marshaler
g
.
P
(
"func "
,
enc
,
encSig
,
" {"
)
g
.
P
(
"m := msg.(*"
,
ccTypeName
,
")"
)
for
oi
,
odp
:=
range
message
.
OneofDecl
{
g
.
P
(
"// "
,
odp
.
GetName
())
fname
:=
oneofFieldName
[
int32
(
oi
)]
g
.
P
(
"switch x := m."
,
fname
,
".(type) {"
)
for
_
,
field
:=
range
message
.
Field
{
if
field
.
OneofIndex
==
nil
||
int
(
*
field
.
OneofIndex
)
!=
oi
{
continue
}
g
.
P
(
"case *"
,
oneofTypeName
[
field
],
":"
)
var
wire
,
pre
,
post
string
val
:=
"x."
+
fieldNames
[
field
]
// overridden for TYPE_BOOL
canFail
:=
false
// only TYPE_MESSAGE and TYPE_GROUP can fail
switch
*
field
.
Type
{
case
descriptor
.
FieldDescriptorProto_TYPE_DOUBLE
:
wire
=
"WireFixed64"
pre
=
"b.EncodeFixed64("
+
g
.
Pkg
[
"math"
]
+
".Float64bits("
post
=
"))"
case
descriptor
.
FieldDescriptorProto_TYPE_FLOAT
:
wire
=
"WireFixed32"
pre
=
"b.EncodeFixed32(uint64("
+
g
.
Pkg
[
"math"
]
+
".Float32bits("
post
=
")))"
case
descriptor
.
FieldDescriptorProto_TYPE_INT64
,
descriptor
.
FieldDescriptorProto_TYPE_UINT64
:
wire
=
"WireVarint"
pre
,
post
=
"b.EncodeVarint(uint64("
,
"))"
case
descriptor
.
FieldDescriptorProto_TYPE_INT32
,
descriptor
.
FieldDescriptorProto_TYPE_UINT32
,
descriptor
.
FieldDescriptorProto_TYPE_ENUM
:
wire
=
"WireVarint"
pre
,
post
=
"b.EncodeVarint(uint64("
,
"))"
case
descriptor
.
FieldDescriptorProto_TYPE_FIXED64
,
descriptor
.
FieldDescriptorProto_TYPE_SFIXED64
:
wire
=
"WireFixed64"
pre
,
post
=
"b.EncodeFixed64(uint64("
,
"))"
case
descriptor
.
FieldDescriptorProto_TYPE_FIXED32
,
descriptor
.
FieldDescriptorProto_TYPE_SFIXED32
:
wire
=
"WireFixed32"
pre
,
post
=
"b.EncodeFixed32(uint64("
,
"))"
case
descriptor
.
FieldDescriptorProto_TYPE_BOOL
:
// bool needs special handling.
g
.
P
(
"t := uint64(0)"
)
g
.
P
(
"if "
,
val
,
" { t = 1 }"
)
val
=
"t"
wire
=
"WireVarint"
pre
,
post
=
"b.EncodeVarint("
,
")"
case
descriptor
.
FieldDescriptorProto_TYPE_STRING
:
wire
=
"WireBytes"
pre
,
post
=
"b.EncodeStringBytes("
,
")"
case
descriptor
.
FieldDescriptorProto_TYPE_GROUP
:
wire
=
"WireStartGroup"
pre
,
post
=
"b.Marshal("
,
")"
canFail
=
true
case
descriptor
.
FieldDescriptorProto_TYPE_MESSAGE
:
wire
=
"WireBytes"
pre
,
post
=
"b.EncodeMessage("
,
")"
canFail
=
true
case
descriptor
.
FieldDescriptorProto_TYPE_BYTES
:
wire
=
"WireBytes"
pre
,
post
=
"b.EncodeRawBytes("
,
")"
case
descriptor
.
FieldDescriptorProto_TYPE_SINT32
:
wire
=
"WireVarint"
pre
,
post
=
"b.EncodeZigzag32(uint64("
,
"))"
case
descriptor
.
FieldDescriptorProto_TYPE_SINT64
:
wire
=
"WireVarint"
pre
,
post
=
"b.EncodeZigzag64(uint64("
,
"))"
default
:
g
.
Fail
(
"unhandled oneof field type "
,
field
.
Type
.
String
())
}
fieldWire
[
field
]
=
wire
g
.
P
(
"_ = b.EncodeVarint("
,
field
.
Number
,
"<<3|"
,
g
.
Pkg
[
"proto"
],
"."
,
wire
,
")"
)
if
*
field
.
Type
==
descriptor
.
FieldDescriptorProto_TYPE_BYTES
&&
gogoproto
.
IsCustomType
(
field
)
{
g
.
P
(
`data, err := `
,
val
,
`.Marshal()`
)
g
.
P
(
`if err != nil {`
)
g
.
In
()
g
.
P
(
`return err`
)
g
.
Out
()
g
.
P
(
`}`
)
val
=
"data"
}
if
!
canFail
{
g
.
P
(
"_ = "
,
pre
,
val
,
post
)
}
else
{
g
.
P
(
"if err := "
,
pre
,
val
,
post
,
"; err != nil {"
)
g
.
In
()
g
.
P
(
"return err"
)
g
.
Out
()
g
.
P
(
"}"
)
}
if
*
field
.
Type
==
descriptor
.
FieldDescriptorProto_TYPE_GROUP
{
g
.
P
(
"_ = b.EncodeVarint("
,
field
.
Number
,
"<<3|"
,
g
.
Pkg
[
"proto"
],
".WireEndGroup)"
)
}
}
g
.
P
(
"case nil:"
)
g
.
P
(
"default: return "
,
g
.
Pkg
[
"fmt"
],
`.Errorf("`
,
ccTypeName
,
"."
,
fname
,
` has unexpected type %T", x)`
)
g
.
P
(
"}"
)
}
g
.
P
(
"return nil"
)
g
.
P
(
"}"
)
g
.
P
()
// unmarshaler
g
.
P
(
"func "
,
dec
,
decSig
,
" {"
)
g
.
P
(
"m := msg.(*"
,
ccTypeName
,
")"
)
g
.
P
(
"switch tag {"
)
for
_
,
field
:=
range
message
.
Field
{
if
field
.
OneofIndex
==
nil
{
continue
}
odp
:=
message
.
OneofDecl
[
int
(
*
field
.
OneofIndex
)]
g
.
P
(
"case "
,
field
.
Number
,
": // "
,
odp
.
GetName
(),
"."
,
*
field
.
Name
)
g
.
P
(
"if wire != "
,
g
.
Pkg
[
"proto"
],
"."
,
fieldWire
[
field
],
" {"
)
g
.
P
(
"return true, "
,
g
.
Pkg
[
"proto"
],
".ErrInternalBadWireType"
)
g
.
P
(
"}"
)
lhs
:=
"x, err"
// overridden for TYPE_MESSAGE and TYPE_GROUP
var
dec
,
cast
,
cast2
string
switch
*
field
.
Type
{
case
descriptor
.
FieldDescriptorProto_TYPE_DOUBLE
:
dec
,
cast
=
"b.DecodeFixed64()"
,
g
.
Pkg
[
"math"
]
+
".Float64frombits"
case
descriptor
.
FieldDescriptorProto_TYPE_FLOAT
:
dec
,
cast
,
cast2
=
"b.DecodeFixed32()"
,
"uint32"
,
g
.
Pkg
[
"math"
]
+
".Float32frombits"
case
descriptor
.
FieldDescriptorProto_TYPE_INT64
:
dec
,
cast
=
"b.DecodeVarint()"
,
"int64"
case
descriptor
.
FieldDescriptorProto_TYPE_UINT64
:
dec
=
"b.DecodeVarint()"
case
descriptor
.
FieldDescriptorProto_TYPE_INT32
:
dec
,
cast
=
"b.DecodeVarint()"
,
"int32"
case
descriptor
.
FieldDescriptorProto_TYPE_FIXED64
:
dec
=
"b.DecodeFixed64()"
case
descriptor
.
FieldDescriptorProto_TYPE_FIXED32
:
dec
,
cast
=
"b.DecodeFixed32()"
,
"uint32"
case
descriptor
.
FieldDescriptorProto_TYPE_BOOL
:
dec
=
"b.DecodeVarint()"
// handled specially below
case
descriptor
.
FieldDescriptorProto_TYPE_STRING
:
dec
=
"b.DecodeStringBytes()"
case
descriptor
.
FieldDescriptorProto_TYPE_GROUP
:
g
.
P
(
"msg := new("
,
fieldTypes
[
field
][
1
:
],
")"
)
// drop star
lhs
=
"err"
dec
=
"b.DecodeGroup(msg)"
// handled specially below
case
descriptor
.
FieldDescriptorProto_TYPE_MESSAGE
:
g
.
P
(
"msg := new("
,
fieldTypes
[
field
][
1
:
],
")"
)
// drop star
lhs
=
"err"
dec
=
"b.DecodeMessage(msg)"
// handled specially below
case
descriptor
.
FieldDescriptorProto_TYPE_BYTES
:
dec
=
"b.DecodeRawBytes(true)"
case
descriptor
.
FieldDescriptorProto_TYPE_UINT32
:
dec
,
cast
=
"b.DecodeVarint()"
,
"uint32"
case
descriptor
.
FieldDescriptorProto_TYPE_ENUM
:
dec
,
cast
=
"b.DecodeVarint()"
,
fieldTypes
[
field
]
case
descriptor
.
FieldDescriptorProto_TYPE_SFIXED32
:
dec
,
cast
=
"b.DecodeFixed32()"
,
"int32"
case
descriptor
.
FieldDescriptorProto_TYPE_SFIXED64
:
dec
,
cast
=
"b.DecodeFixed64()"
,
"int64"
case
descriptor
.
FieldDescriptorProto_TYPE_SINT32
:
dec
,
cast
=
"b.DecodeZigzag32()"
,
"int32"
case
descriptor
.
FieldDescriptorProto_TYPE_SINT64
:
dec
,
cast
=
"b.DecodeZigzag64()"
,
"int64"
default
:
g
.
Fail
(
"unhandled oneof field type "
,
field
.
Type
.
String
())
}
g
.
P
(
lhs
,
" := "
,
dec
)
val
:=
"x"
if
*
field
.
Type
==
descriptor
.
FieldDescriptorProto_TYPE_BYTES
&&
gogoproto
.
IsCustomType
(
field
)
{
g
.
P
(
`if err != nil {`
)
g
.
In
()
g
.
P
(
`return true, err`
)
g
.
Out
()
g
.
P
(
`}`
)
_
,
ctyp
,
err
:=
GetCustomType
(
field
)
if
err
!=
nil
{
panic
(
err
)
}
g
.
P
(
`var cc `
,
ctyp
)
g
.
P
(
`c := &cc`
)
g
.
P
(
`err = c.Unmarshal(`
,
val
,
`)`
)
val
=
"*c"
}
if
cast
!=
""
{
val
=
cast
+
"("
+
val
+
")"
}
if
cast2
!=
""
{
val
=
cast2
+
"("
+
val
+
")"
}
switch
*
field
.
Type
{
case
descriptor
.
FieldDescriptorProto_TYPE_BOOL
:
val
+=
" != 0"
case
descriptor
.
FieldDescriptorProto_TYPE_GROUP
,
descriptor
.
FieldDescriptorProto_TYPE_MESSAGE
:
val
=
"msg"
}
if
gogoproto
.
IsCastType
(
field
)
{
_
,
typ
,
err
:=
getCastType
(
field
)
if
err
!=
nil
{
g
.
Fail
(
err
.
Error
())
}
val
=
typ
+
"("
+
val
+
")"
}
g
.
P
(
"m."
,
oneofFieldName
[
*
field
.
OneofIndex
],
" = &"
,
oneofTypeName
[
field
],
"{"
,
val
,
"}"
)
g
.
P
(
"return true, err"
)
}
g
.
P
(
"default: return false, nil"
)
g
.
P
(
"}"
)
g
.
P
(
"}"
)
g
.
P
()
}
for
_
,
ext
:=
range
message
.
ext
{
g
.
generateExtension
(
ext
)
}
}
func
(
g
*
Generator
)
generateExtension
(
ext
*
ExtensionDescriptor
)
{
ccTypeName
:=
ext
.
DescName
()
extObj
:=
g
.
ObjectNamed
(
*
ext
.
Extendee
)
var
extDesc
*
Descriptor
if
id
,
ok
:=
extObj
.
(
*
ImportedDescriptor
);
ok
{
// This is extending a publicly imported message.
// We need the underlying type for goTag.
extDesc
=
id
.
o
.
(
*
Descriptor
)
}
else
{
extDesc
=
extObj
.
(
*
Descriptor
)
}
extendedType
:=
"*"
+
g
.
TypeName
(
extObj
)
// always use the original
field
:=
ext
.
FieldDescriptorProto
fieldType
,
wireType
:=
g
.
GoType
(
ext
.
parent
,
field
)
tag
:=
g
.
goTag
(
extDesc
,
field
,
wireType
)
g
.
RecordTypeUse
(
*
ext
.
Extendee
)
if
n
:=
ext
.
FieldDescriptorProto
.
TypeName
;
n
!=
nil
{
// foreign extension type
g
.
RecordTypeUse
(
*
n
)
}
typeName
:=
ext
.
TypeName
()
// Special case for proto2 message sets: If this extension is extending
// proto2_bridge.MessageSet, and its final name component is "message_set_extension",
// then drop that last component.
mset
:=
false
if
extendedType
==
"*proto2_bridge.MessageSet"
&&
typeName
[
len
(
typeName
)
-
1
]
==
"message_set_extension"
{
typeName
=
typeName
[
:
len
(
typeName
)
-
1
]
mset
=
true
}
// For text formatting, the package must be exactly what the .proto file declares,
// ignoring overrides such as the go_package option, and with no dot/underscore mapping.
extName
:=
strings
.
Join
(
typeName
,
"."
)
if
g
.
file
.
Package
!=
nil
{
extName
=
*
g
.
file
.
Package
+
"."
+
extName
}
g
.
P
(
"var "
,
ccTypeName
,
" = &"
,
g
.
Pkg
[
"proto"
],
".ExtensionDesc{"
)
g
.
In
()
g
.
P
(
"ExtendedType: ("
,
extendedType
,
")(nil),"
)
g
.
P
(
"ExtensionType: ("
,
fieldType
,
")(nil),"
)
g
.
P
(
"Field: "
,
field
.
Number
,
","
)
g
.
P
(
`Name: "`
,
extName
,
`",`
)
g
.
P
(
"Tag: "
,
tag
,
","
)
g
.
Out
()
g
.
P
(
"}"
)
g
.
P
()
if
mset
{
// Generate a bit more code to register with message_set.go.
g
.
addInitf
(
"%s.RegisterMessageSetType((%s)(nil), %d, %q)"
,
g
.
Pkg
[
"proto"
],
fieldType
,
*
field
.
Number
,
extName
)
}
g
.
file
.
addExport
(
ext
,
constOrVarSymbol
{
ccTypeName
,
"var"
,
""
})
}
func
(
g
*
Generator
)
generateInitFunction
()
{
for
_
,
enum
:=
range
g
.
file
.
enum
{
g
.
generateEnumRegistration
(
enum
)
}
for
_
,
d
:=
range
g
.
file
.
desc
{
for
_
,
ext
:=
range
d
.
ext
{
g
.
generateExtensionRegistration
(
ext
)
}
}
for
_
,
ext
:=
range
g
.
file
.
ext
{
g
.
generateExtensionRegistration
(
ext
)
}
if
len
(
g
.
init
)
==
0
{
return
}
g
.
P
(
"func init() {"
)
g
.
In
()
for
_
,
l
:=
range
g
.
init
{
g
.
P
(
l
)
}
g
.
Out
()
g
.
P
(
"}"
)
g
.
init
=
nil
}
func
(
g
*
Generator
)
generateEnumRegistration
(
enum
*
EnumDescriptor
)
{
// // We always print the full (proto-world) package name here.
pkg
:=
enum
.
File
()
.
GetPackage
()
if
pkg
!=
""
{
pkg
+=
"."
}
// The full type name
typeName
:=
enum
.
TypeName
()
// The full type name, CamelCased.
ccTypeName
:=
CamelCaseSlice
(
typeName
)
g
.
addInitf
(
"%s.RegisterEnum(%q, %[3]s_name, %[3]s_value)"
,
g
.
Pkg
[
"proto"
],
pkg
+
ccTypeName
,
ccTypeName
)
}
func
(
g
*
Generator
)
generateExtensionRegistration
(
ext
*
ExtensionDescriptor
)
{
g
.
addInitf
(
"%s.RegisterExtension(%s)"
,
g
.
Pkg
[
"proto"
],
ext
.
DescName
())
}
// And now lots of helper functions.
// Is c an ASCII lower-case letter?
func
isASCIILower
(
c
byte
)
bool
{
return
'a'
<=
c
&&
c
<=
'z'
}
// Is c an ASCII digit?
func
isASCIIDigit
(
c
byte
)
bool
{
return
'0'
<=
c
&&
c
<=
'9'
}
// CamelCase returns the CamelCased name.
// If there is an interior underscore followed by a lower case letter,
// drop the underscore and convert the letter to upper case.
// There is a remote possibility of this rewrite causing a name collision,
// but it's so remote we're prepared to pretend it's nonexistent - since the
// C++ generator lowercases names, it's extremely unlikely to have two fields
// with different capitalizations.
// In short, _my_field_name_2 becomes XMyFieldName_2.
func
CamelCase
(
s
string
)
string
{
if
s
==
""
{
return
""
}
t
:=
make
([]
byte
,
0
,
32
)
i
:=
0
if
s
[
0
]
==
'_'
{
// Need a capital letter; drop the '_'.
t
=
append
(
t
,
'X'
)
i
++
}
// Invariant: if the next letter is lower case, it must be converted
// to upper case.
// That is, we process a word at a time, where words are marked by _ or
// upper case letter. Digits are treated as words.
for
;
i
<
len
(
s
);
i
++
{
c
:=
s
[
i
]
if
c
==
'_'
&&
i
+
1
<
len
(
s
)
&&
isASCIILower
(
s
[
i
+
1
])
{
continue
// Skip the underscore in s.
}
if
isASCIIDigit
(
c
)
{
t
=
append
(
t
,
c
)
continue
}
// Assume we have a letter now - if not, it's a bogus identifier.
// The next word is a sequence of characters that must start upper case.
if
isASCIILower
(
c
)
{
c
^=
' '
// Make it a capital letter.
}
t
=
append
(
t
,
c
)
// Guaranteed not lower case.
// Accept lower case sequence that follows.
for
i
+
1
<
len
(
s
)
&&
isASCIILower
(
s
[
i
+
1
])
{
i
++
t
=
append
(
t
,
s
[
i
])
}
}
return
string
(
t
)
}
// CamelCaseSlice is like CamelCase, but the argument is a slice of strings to
// be joined with "_".
func
CamelCaseSlice
(
elem
[]
string
)
string
{
return
CamelCase
(
strings
.
Join
(
elem
,
"_"
))
}
// dottedSlice turns a sliced name into a dotted name.
func
dottedSlice
(
elem
[]
string
)
string
{
return
strings
.
Join
(
elem
,
"."
)
}
// Given a .proto file name, return the output name for the generated Go program.
func
goFileName
(
name
string
)
string
{
ext
:=
path
.
Ext
(
name
)
if
ext
==
".proto"
||
ext
==
".protodevel"
{
name
=
name
[
0
:
len
(
name
)
-
len
(
ext
)]
}
return
name
+
".pb.go"
}
// Is this field optional?
func
isOptional
(
field
*
descriptor
.
FieldDescriptorProto
)
bool
{
return
field
.
Label
!=
nil
&&
*
field
.
Label
==
descriptor
.
FieldDescriptorProto_LABEL_OPTIONAL
}
// Is this field required?
func
isRequired
(
field
*
descriptor
.
FieldDescriptorProto
)
bool
{
return
field
.
Label
!=
nil
&&
*
field
.
Label
==
descriptor
.
FieldDescriptorProto_LABEL_REQUIRED
}
// Is this field repeated?
func
isRepeated
(
field
*
descriptor
.
FieldDescriptorProto
)
bool
{
return
field
.
Label
!=
nil
&&
*
field
.
Label
==
descriptor
.
FieldDescriptorProto_LABEL_REPEATED
}
// badToUnderscore is the mapping function used to generate Go names from package names,
// which can be dotted in the input .proto file. It replaces non-identifier characters such as
// dot or dash with underscore.
func
badToUnderscore
(
r
rune
)
rune
{
if
unicode
.
IsLetter
(
r
)
||
unicode
.
IsDigit
(
r
)
||
r
==
'_'
{
return
r
}
return
'_'
}
// baseName returns the last path element of the name, with the last dotted suffix removed.
func
baseName
(
name
string
)
string
{
// First, find the last element
if
i
:=
strings
.
LastIndex
(
name
,
"/"
);
i
>=
0
{
name
=
name
[
i
+
1
:
]
}
// Now drop the suffix
if
i
:=
strings
.
LastIndex
(
name
,
"."
);
i
>=
0
{
name
=
name
[
0
:
i
]
}
return
name
}
// 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
)
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/generator/helper.go
0 → 100644
View file @
8f79df77
// Copyright (c) 2013, Vastech SA (PTY) LTD. All rights reserved.
// http://github.com/gogo/protobuf/gogoproto
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package
generator
import
(
"bytes"
"go/parser"
"go/printer"
"go/token"
"strings"
"path"
"QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/gogoproto"
"QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/proto"
descriptor
"QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/descriptor"
plugin
"QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/plugin"
)
func
(
d
*
FileDescriptor
)
Messages
()
[]
*
Descriptor
{
return
d
.
desc
}
func
(
d
*
FileDescriptor
)
Enums
()
[]
*
EnumDescriptor
{
return
d
.
enum
}
func
(
d
*
Descriptor
)
IsGroup
()
bool
{
return
d
.
group
}
func
(
g
*
Generator
)
IsGroup
(
field
*
descriptor
.
FieldDescriptorProto
)
bool
{
if
d
,
ok
:=
g
.
typeNameToObject
[
field
.
GetTypeName
()]
.
(
*
Descriptor
);
ok
{
return
d
.
IsGroup
()
}
return
false
}
func
(
g
*
Generator
)
TypeNameByObject
(
typeName
string
)
Object
{
o
,
ok
:=
g
.
typeNameToObject
[
typeName
]
if
!
ok
{
g
.
Fail
(
"can't find object with type"
,
typeName
)
}
return
o
}
func
(
g
*
Generator
)
OneOfTypeName
(
message
*
Descriptor
,
field
*
descriptor
.
FieldDescriptorProto
)
string
{
typeName
:=
message
.
TypeName
()
ccTypeName
:=
CamelCaseSlice
(
typeName
)
fieldName
:=
g
.
GetOneOfFieldName
(
message
,
field
)
tname
:=
ccTypeName
+
"_"
+
fieldName
// It is possible for this to collide with a message or enum
// nested in this message. Check for collisions.
ok
:=
true
for
_
,
desc
:=
range
message
.
nested
{
if
strings
.
Join
(
desc
.
TypeName
(),
"_"
)
==
tname
{
ok
=
false
break
}
}
for
_
,
enum
:=
range
message
.
enums
{
if
strings
.
Join
(
enum
.
TypeName
(),
"_"
)
==
tname
{
ok
=
false
break
}
}
if
!
ok
{
tname
+=
"_"
}
return
tname
}
type
PluginImports
interface
{
NewImport
(
pkg
string
)
Single
GenerateImports
(
file
*
FileDescriptor
)
}
type
pluginImports
struct
{
generator
*
Generator
singles
[]
Single
}
func
NewPluginImports
(
generator
*
Generator
)
*
pluginImports
{
return
&
pluginImports
{
generator
,
make
([]
Single
,
0
)}
}
func
(
this
*
pluginImports
)
NewImport
(
pkg
string
)
Single
{
imp
:=
newImportedPackage
(
this
.
generator
.
ImportPrefix
,
pkg
)
this
.
singles
=
append
(
this
.
singles
,
imp
)
return
imp
}
func
(
this
*
pluginImports
)
GenerateImports
(
file
*
FileDescriptor
)
{
for
_
,
s
:=
range
this
.
singles
{
if
s
.
IsUsed
()
{
this
.
generator
.
PrintImport
(
s
.
Name
(),
s
.
Location
())
}
}
}
type
Single
interface
{
Use
()
string
IsUsed
()
bool
Name
()
string
Location
()
string
}
type
importedPackage
struct
{
used
bool
pkg
string
name
string
importPrefix
string
}
func
newImportedPackage
(
importPrefix
,
pkg
string
)
*
importedPackage
{
return
&
importedPackage
{
pkg
:
pkg
,
importPrefix
:
importPrefix
,
}
}
func
(
this
*
importedPackage
)
Use
()
string
{
if
!
this
.
used
{
this
.
name
=
RegisterUniquePackageName
(
this
.
pkg
,
nil
)
this
.
used
=
true
}
return
this
.
name
}
func
(
this
*
importedPackage
)
IsUsed
()
bool
{
return
this
.
used
}
func
(
this
*
importedPackage
)
Name
()
string
{
return
this
.
name
}
func
(
this
*
importedPackage
)
Location
()
string
{
return
this
.
importPrefix
+
this
.
pkg
}
func
(
g
*
Generator
)
GetFieldName
(
message
*
Descriptor
,
field
*
descriptor
.
FieldDescriptorProto
)
string
{
goTyp
,
_
:=
g
.
GoType
(
message
,
field
)
fieldname
:=
CamelCase
(
*
field
.
Name
)
if
gogoproto
.
IsCustomName
(
field
)
{
fieldname
=
gogoproto
.
GetCustomName
(
field
)
}
if
gogoproto
.
IsEmbed
(
field
)
{
fieldname
=
EmbedFieldName
(
goTyp
)
}
if
field
.
OneofIndex
!=
nil
{
fieldname
=
message
.
OneofDecl
[
int
(
*
field
.
OneofIndex
)]
.
GetName
()
fieldname
=
CamelCase
(
fieldname
)
}
for
_
,
f
:=
range
methodNames
{
if
f
==
fieldname
{
return
fieldname
+
"_"
}
}
return
fieldname
}
func
(
g
*
Generator
)
GetOneOfFieldName
(
message
*
Descriptor
,
field
*
descriptor
.
FieldDescriptorProto
)
string
{
goTyp
,
_
:=
g
.
GoType
(
message
,
field
)
fieldname
:=
CamelCase
(
*
field
.
Name
)
if
gogoproto
.
IsCustomName
(
field
)
{
fieldname
=
gogoproto
.
GetCustomName
(
field
)
}
if
gogoproto
.
IsEmbed
(
field
)
{
fieldname
=
EmbedFieldName
(
goTyp
)
}
for
_
,
f
:=
range
methodNames
{
if
f
==
fieldname
{
return
fieldname
+
"_"
}
}
return
fieldname
}
func
GetMap
(
file
*
descriptor
.
FileDescriptorProto
,
field
*
descriptor
.
FieldDescriptorProto
)
*
descriptor
.
DescriptorProto
{
if
!
field
.
IsMessage
()
{
return
nil
}
typeName
:=
strings
.
TrimPrefix
(
field
.
GetTypeName
(),
"."
+
file
.
GetPackage
()
+
"."
)
if
strings
.
Contains
(
typeName
,
"Map"
)
&&
!
strings
.
HasSuffix
(
typeName
,
"Entry"
)
{
typeName
+=
"."
+
CamelCase
(
field
.
GetName
())
+
"Entry"
}
return
file
.
GetMessage
(
typeName
)
}
func
IsMap
(
file
*
descriptor
.
FileDescriptorProto
,
field
*
descriptor
.
FieldDescriptorProto
)
bool
{
msg
:=
GetMap
(
file
,
field
)
if
msg
==
nil
{
return
false
}
return
msg
.
GetOptions
()
.
GetMapEntry
()
}
func
GoTypeToName
(
goTyp
string
)
string
{
return
strings
.
Replace
(
strings
.
Replace
(
goTyp
,
"*"
,
""
,
-
1
),
"[]"
,
""
,
-
1
)
}
func
EmbedFieldName
(
goTyp
string
)
string
{
goTyp
=
GoTypeToName
(
goTyp
)
goTyps
:=
strings
.
Split
(
goTyp
,
"."
)
if
len
(
goTyps
)
==
1
{
return
goTyp
}
if
len
(
goTyps
)
==
2
{
return
goTyps
[
1
]
}
panic
(
"unreachable"
)
}
func
(
g
*
Generator
)
GeneratePlugin
(
p
Plugin
)
{
p
.
Init
(
g
)
// Generate the output. The generator runs for every file, even the files
// that we don't generate output for, so that we can collate the full list
// of exported symbols to support public imports.
genFileMap
:=
make
(
map
[
*
FileDescriptor
]
bool
,
len
(
g
.
genFiles
))
for
_
,
file
:=
range
g
.
genFiles
{
genFileMap
[
file
]
=
true
}
i
:=
0
for
_
,
file
:=
range
g
.
allFiles
{
g
.
Reset
()
g
.
generatePlugin
(
file
,
p
)
if
_
,
ok
:=
genFileMap
[
file
];
!
ok
{
continue
}
g
.
Response
.
File
[
i
]
=
new
(
plugin
.
CodeGeneratorResponse_File
)
g
.
Response
.
File
[
i
]
.
Name
=
proto
.
String
(
goFileName
(
*
file
.
Name
))
g
.
Response
.
File
[
i
]
.
Content
=
proto
.
String
(
g
.
String
())
i
++
}
}
func
(
g
*
Generator
)
SetFile
(
file
*
descriptor
.
FileDescriptorProto
)
{
g
.
file
=
g
.
FileOf
(
file
)
}
func
(
g
*
Generator
)
generatePlugin
(
file
*
FileDescriptor
,
p
Plugin
)
{
g
.
writtenImports
=
make
(
map
[
string
]
bool
)
g
.
file
=
g
.
FileOf
(
file
.
FileDescriptorProto
)
g
.
usedPackages
=
make
(
map
[
string
]
bool
)
// Run the plugins before the imports so we know which imports are necessary.
p
.
Generate
(
file
)
// Generate header and imports last, though they appear first in the output.
rem
:=
g
.
Buffer
g
.
Buffer
=
new
(
bytes
.
Buffer
)
g
.
generateHeader
()
p
.
GenerateImports
(
g
.
file
)
g
.
generateImports
()
g
.
Write
(
rem
.
Bytes
())
// Reformat generated code.
contents
:=
string
(
g
.
Buffer
.
Bytes
())
fset
:=
token
.
NewFileSet
()
ast
,
err
:=
parser
.
ParseFile
(
fset
,
""
,
g
,
parser
.
ParseComments
)
if
err
!=
nil
{
g
.
Fail
(
"bad Go source code was generated:"
,
contents
,
err
.
Error
())
return
}
g
.
Reset
()
err
=
(
&
printer
.
Config
{
Mode
:
printer
.
TabIndent
|
printer
.
UseSpaces
,
Tabwidth
:
8
})
.
Fprint
(
g
,
fset
,
ast
)
if
err
!=
nil
{
g
.
Fail
(
"generated Go source code could not be reformatted:"
,
err
.
Error
())
}
}
func
GetCustomType
(
field
*
descriptor
.
FieldDescriptorProto
)
(
packageName
string
,
typ
string
,
err
error
)
{
return
getCustomType
(
field
)
}
func
getCustomType
(
field
*
descriptor
.
FieldDescriptorProto
)
(
packageName
string
,
typ
string
,
err
error
)
{
if
field
.
Options
!=
nil
{
var
v
interface
{}
v
,
err
=
proto
.
GetExtension
(
field
.
Options
,
gogoproto
.
E_Customtype
)
if
err
==
nil
&&
v
.
(
*
string
)
!=
nil
{
ctype
:=
*
(
v
.
(
*
string
))
packageName
,
typ
=
splitCPackageType
(
ctype
)
return
packageName
,
typ
,
nil
}
}
return
""
,
""
,
err
}
func
splitCPackageType
(
ctype
string
)
(
packageName
string
,
typ
string
)
{
ss
:=
strings
.
Split
(
ctype
,
"."
)
if
len
(
ss
)
==
1
{
return
""
,
ctype
}
packageName
=
strings
.
Join
(
ss
[
0
:
len
(
ss
)
-
1
],
"."
)
typeName
:=
ss
[
len
(
ss
)
-
1
]
importStr
:=
strings
.
Map
(
badToUnderscore
,
packageName
)
typ
=
importStr
+
"."
+
typeName
return
packageName
,
typ
}
func
getCastType
(
field
*
descriptor
.
FieldDescriptorProto
)
(
packageName
string
,
typ
string
,
err
error
)
{
if
field
.
Options
!=
nil
{
var
v
interface
{}
v
,
err
=
proto
.
GetExtension
(
field
.
Options
,
gogoproto
.
E_Casttype
)
if
err
==
nil
&&
v
.
(
*
string
)
!=
nil
{
ctype
:=
*
(
v
.
(
*
string
))
packageName
,
typ
=
splitCPackageType
(
ctype
)
return
packageName
,
typ
,
nil
}
}
return
""
,
""
,
err
}
func
FileName
(
file
*
FileDescriptor
)
string
{
fname
:=
path
.
Base
(
file
.
FileDescriptorProto
.
GetName
())
fname
=
strings
.
Replace
(
fname
,
".proto"
,
""
,
-
1
)
fname
=
strings
.
Replace
(
fname
,
"-"
,
"_"
,
-
1
)
return
CamelCase
(
fname
)
}
func
(
g
*
Generator
)
AllFiles
()
*
descriptor
.
FileDescriptorSet
{
set
:=
&
descriptor
.
FileDescriptorSet
{}
set
.
File
=
make
([]
*
descriptor
.
FileDescriptorProto
,
len
(
g
.
allFiles
))
for
i
:=
range
g
.
allFiles
{
set
.
File
[
i
]
=
g
.
allFiles
[
i
]
.
FileDescriptorProto
}
return
set
}
func
(
d
*
Descriptor
)
Path
()
string
{
return
d
.
path
}
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/generator/name_test.go
0 → 100644
View file @
8f79df77
// Go support for Protocol Buffers - Google's data interchange format
//
// Copyright 2013 The Go Authors. All rights reserved.
// https://github.com/golang/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package
generator
import
(
"testing"
)
func
TestCamelCase
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
in
,
want
string
}{
{
"one"
,
"One"
},
{
"one_two"
,
"OneTwo"
},
{
"_my_field_name_2"
,
"XMyFieldName_2"
},
{
"Something_Capped"
,
"Something_Capped"
},
{
"my_Name"
,
"My_Name"
},
{
"OneTwo"
,
"OneTwo"
},
{
"_"
,
"X"
},
{
"_a_"
,
"XA_"
},
}
for
_
,
tc
:=
range
tests
{
if
got
:=
CamelCase
(
tc
.
in
);
got
!=
tc
.
want
{
t
.
Errorf
(
"CamelCase(%q) = %q, want %q"
,
tc
.
in
,
got
,
tc
.
want
)
}
}
}
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/main.go
0 → 100644
View file @
8f79df77
// Go support for Protocol Buffers - Google's data interchange format
//
// Copyright 2010 The Go Authors. All rights reserved.
// https://github.com/golang/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// protoc-gen-go is a plugin for the Google protocol buffer compiler to generate
// Go code. Run it by building this program and putting it in your path with
// the name
// protoc-gen-gogo
// That word 'gogo' at the end becomes part of the option string set for the
// protocol compiler, so once the protocol compiler (protoc) is installed
// you can run
// protoc --gogo_out=output_directory input_directory/file.proto
// to generate Go bindings for the protocol defined by file.proto.
// With that input, the output will be written to
// output_directory/file.pb.go
//
// The generated code is documented in the package comment for
// the library.
//
// See the README and documentation for protocol buffers to learn more:
// https://developers.google.com/protocol-buffers/
package
main
import
(
"QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/vanity/command"
)
func
main
()
{
command
.
Write
(
command
.
Generate
(
command
.
Read
()))
}
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/plugin/Makefile
0 → 100644
View file @
8f79df77
# Go support for Protocol Buffers - Google's data interchange format
#
# Copyright 2010 The Go Authors. All rights reserved.
# https://github.com/golang/protobuf
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Not stored here, but plugin.proto is in https://github.com/google/protobuf/
# at src/google/protobuf/compiler/plugin.proto
# Also we need to fix an import.
regenerate
:
protoc
--gogo_out
=
Mgoogle/protobuf/descriptor.proto
=
github.com/gogo/protobuf/protoc-gen-gogo/descriptor:.
-I
=
../../protobuf/google/protobuf/compiler/:../../protobuf/ ../../protobuf/google/protobuf/compiler/plugin.proto
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/plugin/plugin.pb.go
0 → 100644
View file @
8f79df77
// Code generated by protoc-gen-gogo.
// source: plugin.proto
// DO NOT EDIT!
/*
Package google_protobuf_compiler is a generated protocol buffer package.
It is generated from these files:
plugin.proto
It has these top-level messages:
CodeGeneratorRequest
CodeGeneratorResponse
*/
package
google_protobuf_compiler
import
proto
"QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/proto"
import
fmt
"fmt"
import
math
"math"
import
google_protobuf
"QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/descriptor"
// Reference imports to suppress errors if they are not otherwise used.
var
_
=
proto
.
Marshal
var
_
=
fmt
.
Errorf
var
_
=
math
.
Inf
// An encoded CodeGeneratorRequest is written to the plugin's stdin.
type
CodeGeneratorRequest
struct
{
// The .proto files that were explicitly listed on the command-line. The
// code generator should generate code only for these files. Each file's
// descriptor will be included in proto_file, below.
FileToGenerate
[]
string
`protobuf:"bytes,1,rep,name=file_to_generate" json:"file_to_generate,omitempty"`
// The generator parameter passed on the command-line.
Parameter
*
string
`protobuf:"bytes,2,opt,name=parameter" json:"parameter,omitempty"`
// FileDescriptorProtos for all files in files_to_generate and everything
// they import. The files will appear in topological order, so each file
// appears before any file that imports it.
//
// protoc guarantees that all proto_files will be written after
// the fields above, even though this is not technically guaranteed by the
// protobuf wire format. This theoretically could allow a plugin to stream
// in the FileDescriptorProtos and handle them one by one rather than read
// the entire set into memory at once. However, as of this writing, this
// is not similarly optimized on protoc's end -- it will store all fields in
// memory at once before sending them to the plugin.
ProtoFile
[]
*
google_protobuf
.
FileDescriptorProto
`protobuf:"bytes,15,rep,name=proto_file" json:"proto_file,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
CodeGeneratorRequest
)
Reset
()
{
*
m
=
CodeGeneratorRequest
{}
}
func
(
m
*
CodeGeneratorRequest
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
CodeGeneratorRequest
)
ProtoMessage
()
{}
func
(
m
*
CodeGeneratorRequest
)
GetFileToGenerate
()
[]
string
{
if
m
!=
nil
{
return
m
.
FileToGenerate
}
return
nil
}
func
(
m
*
CodeGeneratorRequest
)
GetParameter
()
string
{
if
m
!=
nil
&&
m
.
Parameter
!=
nil
{
return
*
m
.
Parameter
}
return
""
}
func
(
m
*
CodeGeneratorRequest
)
GetProtoFile
()
[]
*
google_protobuf
.
FileDescriptorProto
{
if
m
!=
nil
{
return
m
.
ProtoFile
}
return
nil
}
// The plugin writes an encoded CodeGeneratorResponse to stdout.
type
CodeGeneratorResponse
struct
{
// Error message. If non-empty, code generation failed. The plugin process
// should exit with status code zero even if it reports an error in this way.
//
// This should be used to indicate errors in .proto files which prevent the
// code generator from generating correct code. Errors which indicate a
// problem in protoc itself -- such as the input CodeGeneratorRequest being
// unparseable -- should be reported by writing a message to stderr and
// exiting with a non-zero status code.
Error
*
string
`protobuf:"bytes,1,opt,name=error" json:"error,omitempty"`
File
[]
*
CodeGeneratorResponse_File
`protobuf:"bytes,15,rep,name=file" json:"file,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
CodeGeneratorResponse
)
Reset
()
{
*
m
=
CodeGeneratorResponse
{}
}
func
(
m
*
CodeGeneratorResponse
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
CodeGeneratorResponse
)
ProtoMessage
()
{}
func
(
m
*
CodeGeneratorResponse
)
GetError
()
string
{
if
m
!=
nil
&&
m
.
Error
!=
nil
{
return
*
m
.
Error
}
return
""
}
func
(
m
*
CodeGeneratorResponse
)
GetFile
()
[]
*
CodeGeneratorResponse_File
{
if
m
!=
nil
{
return
m
.
File
}
return
nil
}
// Represents a single generated file.
type
CodeGeneratorResponse_File
struct
{
// The file name, relative to the output directory. The name must not
// contain "." or ".." components and must be relative, not be absolute (so,
// the file cannot lie outside the output directory). "/" must be used as
// the path separator, not "\".
//
// If the name is omitted, the content will be appended to the previous
// file. This allows the generator to break large files into small chunks,
// and allows the generated text to be streamed back to protoc so that large
// files need not reside completely in memory at one time. Note that as of
// this writing protoc does not optimize for this -- it will read the entire
// CodeGeneratorResponse before writing files to disk.
Name
*
string
`protobuf:"bytes,1,opt,name=name" json:"name,omitempty"`
// If non-empty, indicates that the named file should already exist, and the
// content here is to be inserted into that file at a defined insertion
// point. This feature allows a code generator to extend the output
// produced by another code generator. The original generator may provide
// insertion points by placing special annotations in the file that look
// like:
// @@protoc_insertion_point(NAME)
// The annotation can have arbitrary text before and after it on the line,
// which allows it to be placed in a comment. NAME should be replaced with
// an identifier naming the point -- this is what other generators will use
// as the insertion_point. Code inserted at this point will be placed
// immediately above the line containing the insertion point (thus multiple
// insertions to the same point will come out in the order they were added).
// The double-@ is intended to make it unlikely that the generated code
// could contain things that look like insertion points by accident.
//
// For example, the C++ code generator places the following line in the
// .pb.h files that it generates:
// // @@protoc_insertion_point(namespace_scope)
// This line appears within the scope of the file's package namespace, but
// outside of any particular class. Another plugin can then specify the
// insertion_point "namespace_scope" to generate additional classes or
// other declarations that should be placed in this scope.
//
// Note that if the line containing the insertion point begins with
// whitespace, the same whitespace will be added to every line of the
// inserted text. This is useful for languages like Python, where
// indentation matters. In these languages, the insertion point comment
// should be indented the same amount as any inserted code will need to be
// in order to work correctly in that context.
//
// The code generator that generates the initial file and the one which
// inserts into it must both run as part of a single invocation of protoc.
// Code generators are executed in the order in which they appear on the
// command line.
//
// If |insertion_point| is present, |name| must also be present.
InsertionPoint
*
string
`protobuf:"bytes,2,opt,name=insertion_point" json:"insertion_point,omitempty"`
// The file contents.
Content
*
string
`protobuf:"bytes,15,opt,name=content" json:"content,omitempty"`
XXX_unrecognized
[]
byte
`json:"-"`
}
func
(
m
*
CodeGeneratorResponse_File
)
Reset
()
{
*
m
=
CodeGeneratorResponse_File
{}
}
func
(
m
*
CodeGeneratorResponse_File
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
CodeGeneratorResponse_File
)
ProtoMessage
()
{}
func
(
m
*
CodeGeneratorResponse_File
)
GetName
()
string
{
if
m
!=
nil
&&
m
.
Name
!=
nil
{
return
*
m
.
Name
}
return
""
}
func
(
m
*
CodeGeneratorResponse_File
)
GetInsertionPoint
()
string
{
if
m
!=
nil
&&
m
.
InsertionPoint
!=
nil
{
return
*
m
.
InsertionPoint
}
return
""
}
func
(
m
*
CodeGeneratorResponse_File
)
GetContent
()
string
{
if
m
!=
nil
&&
m
.
Content
!=
nil
{
return
*
m
.
Content
}
return
""
}
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/testdata/Makefile
0 → 100644
View file @
8f79df77
# Go support for Protocol Buffers - Google's data interchange format
#
# Copyright 2010 The Go Authors. All rights reserved.
# https://github.com/golang/protobuf
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
all
:
@
echo
run make
test
test
:
golden testbuild
#test: golden testbuild extension_test
# ./extension_test
# @echo PASS
golden
:
go
install
github.com/gogo/protobuf/protoc-min-version
protoc-min-version
--version
=
"3.0.0"
--gogo_out
=
.
./my_test/test.proto
diff
-w
my_test/test.pb.go my_test/test.pb.go.golden
nuke
:
clean
testbuild
:
buildprotos
go
test
buildprotos
:
# Invoke protoc once to generate three independent .pb.go files in the same package.
protoc
--gogo_out
=
.
multi/multi
{
1,2,3
}
.proto
#extension_test: extension_test.$O
# $(LD) -L. -o $@ $<
#multi.a: multi3.pb.$O multi2.pb.$O multi1.pb.$O
# rm -f multi.a
# $(QUOTED_GOBIN)/gopack grc $@ $<
#test.pb.go: imp.pb.go
#multi1.pb.go: multi2.pb.go multi3.pb.go
#main.$O: imp.pb.$O test.pb.$O multi.a
#extension_test.$O: extension_base.pb.$O extension_extra.pb.$O extension_user.pb.$O
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/testdata/extension_base.proto
0 → 100644
View file @
8f79df77
// Go support for Protocol Buffers - Google's data interchange format
//
// Copyright 2010 The Go Authors. All rights reserved.
// https://github.com/golang/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax
=
"proto2"
;
package
extension_base
;
message
BaseMessage
{
optional
int32
height
=
1
;
extensions
4
to
9
;
extensions
16
to
max
;
}
// Another message that may be extended, using message_set_wire_format.
message
OldStyleMessage
{
option
message_set_wire_format
=
true
;
extensions
100
to
max
;
}
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/testdata/extension_extra.proto
0 → 100644
View file @
8f79df77
// Go support for Protocol Buffers - Google's data interchange format
//
// Copyright 2011 The Go Authors. All rights reserved.
// https://github.com/golang/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax
=
"proto2"
;
package
extension_extra
;
message
ExtraMessage
{
optional
int32
width
=
1
;
}
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/testdata/extension_test.go
0 → 100644
View file @
8f79df77
// Go support for Protocol Buffers - Google's data interchange format
//
// Copyright 2010 The Go Authors. All rights reserved.
// https://github.com/golang/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Test that we can use protocol buffers that use extensions.
package
testdata
/*
import (
"bytes"
"regexp"
"testing"
"github.com/golang/protobuf/proto"
base "extension_base.pb"
user "extension_user.pb"
)
func TestSingleFieldExtension(t *testing.T) {
bm := &base.BaseMessage{
Height: proto.Int32(178),
}
// Use extension within scope of another type.
vol := proto.Uint32(11)
err := proto.SetExtension(bm, user.E_LoudMessage_Volume, vol)
if err != nil {
t.Fatal("Failed setting extension:", err)
}
buf, err := proto.Marshal(bm)
if err != nil {
t.Fatal("Failed encoding message with extension:", err)
}
bm_new := new(base.BaseMessage)
if err := proto.Unmarshal(buf, bm_new); err != nil {
t.Fatal("Failed decoding message with extension:", err)
}
if !proto.HasExtension(bm_new, user.E_LoudMessage_Volume) {
t.Fatal("Decoded message didn't contain extension.")
}
vol_out, err := proto.GetExtension(bm_new, user.E_LoudMessage_Volume)
if err != nil {
t.Fatal("Failed getting extension:", err)
}
if v := vol_out.(*uint32); *v != *vol {
t.Errorf("vol_out = %v, expected %v", *v, *vol)
}
proto.ClearExtension(bm_new, user.E_LoudMessage_Volume)
if proto.HasExtension(bm_new, user.E_LoudMessage_Volume) {
t.Fatal("Failed clearing extension.")
}
}
func TestMessageExtension(t *testing.T) {
bm := &base.BaseMessage{
Height: proto.Int32(179),
}
// Use extension that is itself a message.
um := &user.UserMessage{
Name: proto.String("Dave"),
Rank: proto.String("Major"),
}
err := proto.SetExtension(bm, user.E_LoginMessage_UserMessage, um)
if err != nil {
t.Fatal("Failed setting extension:", err)
}
buf, err := proto.Marshal(bm)
if err != nil {
t.Fatal("Failed encoding message with extension:", err)
}
bm_new := new(base.BaseMessage)
if err := proto.Unmarshal(buf, bm_new); err != nil {
t.Fatal("Failed decoding message with extension:", err)
}
if !proto.HasExtension(bm_new, user.E_LoginMessage_UserMessage) {
t.Fatal("Decoded message didn't contain extension.")
}
um_out, err := proto.GetExtension(bm_new, user.E_LoginMessage_UserMessage)
if err != nil {
t.Fatal("Failed getting extension:", err)
}
if n := um_out.(*user.UserMessage).Name; *n != *um.Name {
t.Errorf("um_out.Name = %q, expected %q", *n, *um.Name)
}
if r := um_out.(*user.UserMessage).Rank; *r != *um.Rank {
t.Errorf("um_out.Rank = %q, expected %q", *r, *um.Rank)
}
proto.ClearExtension(bm_new, user.E_LoginMessage_UserMessage)
if proto.HasExtension(bm_new, user.E_LoginMessage_UserMessage) {
t.Fatal("Failed clearing extension.")
}
}
func TestTopLevelExtension(t *testing.T) {
bm := &base.BaseMessage{
Height: proto.Int32(179),
}
width := proto.Int32(17)
err := proto.SetExtension(bm, user.E_Width, width)
if err != nil {
t.Fatal("Failed setting extension:", err)
}
buf, err := proto.Marshal(bm)
if err != nil {
t.Fatal("Failed encoding message with extension:", err)
}
bm_new := new(base.BaseMessage)
if err := proto.Unmarshal(buf, bm_new); err != nil {
t.Fatal("Failed decoding message with extension:", err)
}
if !proto.HasExtension(bm_new, user.E_Width) {
t.Fatal("Decoded message didn't contain extension.")
}
width_out, err := proto.GetExtension(bm_new, user.E_Width)
if err != nil {
t.Fatal("Failed getting extension:", err)
}
if w := width_out.(*int32); *w != *width {
t.Errorf("width_out = %v, expected %v", *w, *width)
}
proto.ClearExtension(bm_new, user.E_Width)
if proto.HasExtension(bm_new, user.E_Width) {
t.Fatal("Failed clearing extension.")
}
}
func TestMessageSetWireFormat(t *testing.T) {
osm := new(base.OldStyleMessage)
osp := &user.OldStyleParcel{
Name: proto.String("Dave"),
Height: proto.Int32(178),
}
err := proto.SetExtension(osm, user.E_OldStyleParcel_MessageSetExtension, osp)
if err != nil {
t.Fatal("Failed setting extension:", err)
}
buf, err := proto.Marshal(osm)
if err != nil {
t.Fatal("Failed encoding message:", err)
}
// Data generated from Python implementation.
expected := []byte{
11, 16, 209, 15, 26, 9, 10, 4, 68, 97, 118, 101, 16, 178, 1, 12,
}
if !bytes.Equal(expected, buf) {
t.Errorf("Encoding mismatch.\nwant %+v\n got %+v", expected, buf)
}
// Check that it is restored correctly.
osm = new(base.OldStyleMessage)
if err := proto.Unmarshal(buf, osm); err != nil {
t.Fatal("Failed decoding message:", err)
}
osp_out, err := proto.GetExtension(osm, user.E_OldStyleParcel_MessageSetExtension)
if err != nil {
t.Fatal("Failed getting extension:", err)
}
osp = osp_out.(*user.OldStyleParcel)
if *osp.Name != "Dave" || *osp.Height != 178 {
t.Errorf("Retrieved extension from decoded message is not correct: %+v", osp)
}
}
func main() {
// simpler than rigging up gotest
testing.Main(regexp.MatchString, []testing.InternalTest{
{"TestSingleFieldExtension", TestSingleFieldExtension},
{"TestMessageExtension", TestMessageExtension},
{"TestTopLevelExtension", TestTopLevelExtension},
},
[]testing.InternalBenchmark{},
[]testing.InternalExample{})
}
*/
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/testdata/extension_user.proto
0 → 100644
View file @
8f79df77
// Go support for Protocol Buffers - Google's data interchange format
//
// Copyright 2010 The Go Authors. All rights reserved.
// https://github.com/golang/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax
=
"proto2"
;
import
"extension_base.proto"
;
import
"extension_extra.proto"
;
package
extension_user
;
message
UserMessage
{
optional
string
name
=
1
;
optional
string
rank
=
2
;
}
// Extend with a message
extend
extension_base
.
BaseMessage
{
optional
UserMessage
user_message
=
5
;
}
// Extend with a foreign message
extend
extension_base
.
BaseMessage
{
optional
extension_extra.ExtraMessage
extra_message
=
9
;
}
// Extend with some primitive types
extend
extension_base
.
BaseMessage
{
optional
int32
width
=
6
;
optional
int64
area
=
7
;
}
// Extend inside the scope of another type
message
LoudMessage
{
extend
extension_base
.
BaseMessage
{
optional
uint32
volume
=
8
;
}
extensions
100
to
max
;
}
// Extend inside the scope of another type, using a message.
message
LoginMessage
{
extend
extension_base
.
BaseMessage
{
optional
UserMessage
user_message
=
16
;
}
}
// Extend with a repeated field
extend
extension_base
.
BaseMessage
{
repeated
Detail
detail
=
17
;
}
message
Detail
{
optional
string
color
=
1
;
}
// An extension of an extension
message
Announcement
{
optional
string
words
=
1
;
extend
LoudMessage
{
optional
Announcement
loud_ext
=
100
;
}
}
// Something that can be put in a message set.
message
OldStyleParcel
{
extend
extension_base
.
OldStyleMessage
{
optional
OldStyleParcel
message_set_extension
=
2001
;
}
required
string
name
=
1
;
optional
int32
height
=
2
;
}
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/testdata/golden_test.go
0 → 100644
View file @
8f79df77
// Go support for Protocol Buffers - Google's data interchange format
//
// Copyright 2012 The Go Authors. All rights reserved.
// https://github.com/golang/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Verify that the compiler output for test.proto is unchanged.
package
testdata
import
(
"crypto/sha1"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"testing"
)
// sum returns in string form (for easy comparison) the SHA-1 hash of the named file.
func
sum
(
t
*
testing
.
T
,
name
string
)
string
{
data
,
err
:=
ioutil
.
ReadFile
(
name
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
t
.
Logf
(
"sum(%q): length is %d"
,
name
,
len
(
data
))
hash
:=
sha1
.
New
()
_
,
err
=
hash
.
Write
(
data
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
return
fmt
.
Sprintf
(
"% x"
,
hash
.
Sum
(
nil
))
}
func
run
(
t
*
testing
.
T
,
name
string
,
args
...
string
)
{
cmd
:=
exec
.
Command
(
name
,
args
...
)
cmd
.
Stdin
=
os
.
Stdin
cmd
.
Stdout
=
os
.
Stdout
cmd
.
Stderr
=
os
.
Stderr
err
:=
cmd
.
Run
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
}
func
TestGolden
(
t
*
testing
.
T
)
{
// Compute the original checksum.
goldenSum
:=
sum
(
t
,
"my_test/test.pb.go"
)
// Run the proto compiler.
run
(
t
,
"protoc"
,
"--gogo_out="
+
os
.
TempDir
(),
"my_test/test.proto"
)
newFile
:=
filepath
.
Join
(
os
.
TempDir
(),
"my_test/test.pb.go"
)
defer
os
.
Remove
(
newFile
)
// Compute the new checksum.
newSum
:=
sum
(
t
,
newFile
)
// Verify
if
newSum
!=
goldenSum
{
run
(
t
,
"diff"
,
"-u"
,
"my_test/test.pb.go"
,
newFile
)
t
.
Fatal
(
"Code generated by protoc-gen-go has changed; update test.pb.go"
)
}
}
vendor/QmfH4HuZyN1p2wQLWWkXC91Z76435xKrBVfLQ2MY8ayG5R/gogo-protobuf/protoc-gen-gogo/testdata/grpc.proto
0 → 100644
View file @
8f79df77
// Go support for Protocol Buffers - Google's data interchange format
//
// Copyright 2015 The Go Authors. All rights reserved.
// https://github.com/golang/protobuf
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
syntax
=
"proto3"
;
package
grpc
.
testing
;
message
SimpleRequest
{
}
message
SimpleResponse
{
}
message
StreamMsg
{
}
message
StreamMsg2
{
}
service
Test
{
rpc
UnaryCall
(
SimpleRequest
)
returns
(
SimpleResponse
);
// This RPC streams from the server only.
rpc
Downstream
(
SimpleRequest
)
returns
(
stream
StreamMsg
);
// This RPC streams from the client.
rpc
Upstream
(
stream
StreamMsg
)
returns
(
SimpleResponse
);
// This one streams in both directions.
rpc
Bidi
(
stream
StreamMsg
)
returns
(
stream
StreamMsg2
);
}
Prev
1
2
3
4
5
6
7
8
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment