Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
cfa2d8aa
Commit
cfa2d8aa
authored
Apr 18, 2009
by
kenton@google.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Generate field number constants. Patch from Michael Poole.
parent
eb26a1ef
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
313 additions
and
37 deletions
+313
-37
CHANGES.txt
CHANGES.txt
+9
-0
CONTRIBUTORS.txt
CONTRIBUTORS.txt
+1
-0
GeneratedMessageTest.java
...c/test/java/com/google/protobuf/GeneratedMessageTest.java
+27
-0
reflection_test.py
python/google/protobuf/internal/reflection_test.py
+41
-0
reflection.py
python/google/protobuf/reflection.py
+12
-0
cpp_extension.cc
src/google/protobuf/compiler/cpp/cpp_extension.cc
+20
-8
cpp_helpers.cc
src/google/protobuf/compiler/cpp/cpp_helpers.cc
+30
-0
cpp_helpers.h
src/google/protobuf/compiler/cpp/cpp_helpers.h
+4
-0
cpp_message.cc
src/google/protobuf/compiler/cpp/cpp_message.cc
+16
-1
cpp_string_field.cc
src/google/protobuf/compiler/cpp/cpp_string_field.cc
+2
-2
java_extension.cc
src/google/protobuf/compiler/java/java_extension.cc
+4
-0
java_helpers.cc
src/google/protobuf/compiler/java/java_helpers.cc
+6
-0
java_helpers.h
src/google/protobuf/compiler/java/java_helpers.h
+4
-0
java_message.cc
src/google/protobuf/compiler/java/java_message.cc
+3
-0
python_generator.cc
src/google/protobuf/compiler/python/python_generator.cc
+5
-0
descriptor.pb.cc
src/google/protobuf/descriptor.pb.cc
+99
-26
descriptor.pb.h
src/google/protobuf/descriptor.pb.h
+0
-0
message_unittest.cc
src/google/protobuf/message_unittest.cc
+30
-0
No files found.
CHANGES.txt
View file @
cfa2d8aa
...
...
@@ -8,6 +8,15 @@
this blob, the individual values are encoded the same way they would
be normally except without a tag before each value (thus, they are
tightly "packed").
* For each field, the generated code contains an integer constant assigned
to the field number. For example, the .proto file:
message Foo { optional int bar_baz = 123; }
would generate the following constants, all with the integer value 123:
C++: Foo::kBarBazFieldNumber
Java: Foo.BAR_BAZ_FIELD_NUMBER
Python: Foo.BAR_BAZ_FIELD_NUMBER
Constants are also generated for extensions, with the same naming scheme.
These constants may be used as switch cases.
protoc
* --error_format=msvs option causes errors to be printed in Visual Studio
...
...
CONTRIBUTORS.txt
View file @
cfa2d8aa
...
...
@@ -62,3 +62,4 @@ Patch contributors:
Michael Poole <mdpoole@troilus.org>
* Fixed warnings about generated constructors not explicitly initializing
all fields (only present with certain compiler settings).
* Added generation of field number constants.
java/src/test/java/com/google/protobuf/GeneratedMessageTest.java
View file @
cfa2d8aa
...
...
@@ -488,4 +488,31 @@ public class GeneratedMessageTest extends TestCase {
TestAllTypes
message
=
builder
.
build
();
TestUtil
.
assertAllFieldsSet
(
message
.
toBuilder
().
build
());
}
public
void
testFieldConstantValues
()
throws
Exception
{
assertEquals
(
TestAllTypes
.
NestedMessage
.
BB_FIELD_NUMBER
,
1
);
assertEquals
(
TestAllTypes
.
OPTIONAL_INT32_FIELD_NUMBER
,
1
);
assertEquals
(
TestAllTypes
.
OPTIONALGROUP_FIELD_NUMBER
,
16
);
assertEquals
(
TestAllTypes
.
OPTIONAL_NESTED_MESSAGE_FIELD_NUMBER
,
18
);
assertEquals
(
TestAllTypes
.
OPTIONAL_NESTED_ENUM_FIELD_NUMBER
,
21
);
assertEquals
(
TestAllTypes
.
REPEATED_INT32_FIELD_NUMBER
,
31
);
assertEquals
(
TestAllTypes
.
REPEATEDGROUP_FIELD_NUMBER
,
46
);
assertEquals
(
TestAllTypes
.
REPEATED_NESTED_MESSAGE_FIELD_NUMBER
,
48
);
assertEquals
(
TestAllTypes
.
REPEATED_NESTED_ENUM_FIELD_NUMBER
,
51
);
}
public
void
testExtensionConstantValues
()
throws
Exception
{
assertEquals
(
UnittestProto
.
TestRequired
.
SINGLE_FIELD_NUMBER
,
1000
);
assertEquals
(
UnittestProto
.
TestRequired
.
MULTI_FIELD_NUMBER
,
1001
);
assertEquals
(
UnittestProto
.
OPTIONAL_INT32_EXTENSION_FIELD_NUMBER
,
1
);
assertEquals
(
UnittestProto
.
OPTIONALGROUP_EXTENSION_FIELD_NUMBER
,
16
);
assertEquals
(
UnittestProto
.
OPTIONAL_NESTED_MESSAGE_EXTENSION_FIELD_NUMBER
,
18
);
assertEquals
(
UnittestProto
.
OPTIONAL_NESTED_ENUM_EXTENSION_FIELD_NUMBER
,
21
);
assertEquals
(
UnittestProto
.
REPEATED_INT32_EXTENSION_FIELD_NUMBER
,
31
);
assertEquals
(
UnittestProto
.
REPEATEDGROUP_EXTENSION_FIELD_NUMBER
,
46
);
assertEquals
(
UnittestProto
.
REPEATED_NESTED_MESSAGE_EXTENSION_FIELD_NUMBER
,
48
);
assertEquals
(
UnittestProto
.
REPEATED_NESTED_ENUM_EXTENSION_FIELD_NUMBER
,
51
);
}
}
python/google/protobuf/internal/reflection_test.py
View file @
cfa2d8aa
...
...
@@ -1787,6 +1787,47 @@ class SerializationTest(unittest.TestCase):
self
.
assertEqual
(
1000.0
,
d
.
ReadDouble
())
self
.
assertTrue
(
d
.
EndOfStream
())
def
testFieldNumbers
(
self
):
proto
=
unittest_pb2
.
TestAllTypes
()
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
.
NestedMessage
.
BB_FIELD_NUMBER
,
1
)
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
.
OPTIONAL_INT32_FIELD_NUMBER
,
1
)
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
.
OPTIONALGROUP_FIELD_NUMBER
,
16
)
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
.
OPTIONAL_NESTED_MESSAGE_FIELD_NUMBER
,
18
)
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
.
OPTIONAL_NESTED_ENUM_FIELD_NUMBER
,
21
)
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
.
REPEATED_INT32_FIELD_NUMBER
,
31
)
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
.
REPEATEDGROUP_FIELD_NUMBER
,
46
)
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
.
REPEATED_NESTED_MESSAGE_FIELD_NUMBER
,
48
)
self
.
assertEqual
(
unittest_pb2
.
TestAllTypes
.
REPEATED_NESTED_ENUM_FIELD_NUMBER
,
51
)
def
testExtensionFieldNumbers
(
self
):
self
.
assertEqual
(
unittest_pb2
.
TestRequired
.
single
.
number
,
1000
)
self
.
assertEqual
(
unittest_pb2
.
TestRequired
.
SINGLE_FIELD_NUMBER
,
1000
)
self
.
assertEqual
(
unittest_pb2
.
TestRequired
.
multi
.
number
,
1001
)
self
.
assertEqual
(
unittest_pb2
.
TestRequired
.
MULTI_FIELD_NUMBER
,
1001
)
self
.
assertEqual
(
unittest_pb2
.
optional_int32_extension
.
number
,
1
)
self
.
assertEqual
(
unittest_pb2
.
OPTIONAL_INT32_EXTENSION_FIELD_NUMBER
,
1
)
self
.
assertEqual
(
unittest_pb2
.
optionalgroup_extension
.
number
,
16
)
self
.
assertEqual
(
unittest_pb2
.
OPTIONALGROUP_EXTENSION_FIELD_NUMBER
,
16
)
self
.
assertEqual
(
unittest_pb2
.
optional_nested_message_extension
.
number
,
18
)
self
.
assertEqual
(
unittest_pb2
.
OPTIONAL_NESTED_MESSAGE_EXTENSION_FIELD_NUMBER
,
18
)
self
.
assertEqual
(
unittest_pb2
.
optional_nested_enum_extension
.
number
,
21
)
self
.
assertEqual
(
unittest_pb2
.
OPTIONAL_NESTED_ENUM_EXTENSION_FIELD_NUMBER
,
21
)
self
.
assertEqual
(
unittest_pb2
.
repeated_int32_extension
.
number
,
31
)
self
.
assertEqual
(
unittest_pb2
.
REPEATED_INT32_EXTENSION_FIELD_NUMBER
,
31
)
self
.
assertEqual
(
unittest_pb2
.
repeatedgroup_extension
.
number
,
46
)
self
.
assertEqual
(
unittest_pb2
.
REPEATEDGROUP_EXTENSION_FIELD_NUMBER
,
46
)
self
.
assertEqual
(
unittest_pb2
.
repeated_nested_message_extension
.
number
,
48
)
self
.
assertEqual
(
unittest_pb2
.
REPEATED_NESTED_MESSAGE_EXTENSION_FIELD_NUMBER
,
48
)
self
.
assertEqual
(
unittest_pb2
.
repeated_nested_enum_extension
.
number
,
51
)
self
.
assertEqual
(
unittest_pb2
.
REPEATED_NESTED_ENUM_EXTENSION_FIELD_NUMBER
,
51
)
class
OptionsTest
(
unittest
.
TestCase
):
...
...
python/google/protobuf/reflection.py
View file @
cfa2d8aa
...
...
@@ -149,6 +149,7 @@ class GeneratedProtocolMessageType(type):
_AddEnumValues
(
descriptor
,
cls
)
_AddInitMethod
(
descriptor
,
cls
)
_AddPropertiesForFields
(
descriptor
,
cls
)
_AddPropertiesForExtensions
(
descriptor
,
cls
)
_AddStaticMethods
(
cls
)
_AddMessageMethods
(
descriptor
,
cls
)
_AddPrivateHelperMethods
(
cls
)
...
...
@@ -331,6 +332,9 @@ def _AddPropertiesForField(field, cls):
# handle specially here.
assert
_FieldDescriptor
.
MAX_CPPTYPE
==
10
constant_name
=
field
.
name
.
upper
()
+
"_FIELD_NUMBER"
setattr
(
cls
,
constant_name
,
field
.
number
)
if
field
.
label
==
_FieldDescriptor
.
LABEL_REPEATED
:
_AddPropertiesForRepeatedField
(
field
,
cls
)
elif
field
.
cpp_type
==
_FieldDescriptor
.
CPPTYPE_MESSAGE
:
...
...
@@ -455,6 +459,14 @@ def _AddPropertiesForNonRepeatedCompositeField(field, cls):
setattr
(
cls
,
property_name
,
property
(
getter
,
setter
,
doc
=
doc
))
def
_AddPropertiesForExtensions
(
descriptor
,
cls
):
"""Adds properties for all fields in this protocol message type."""
extension_dict
=
descriptor
.
extensions_by_name
for
extension_name
,
extension_field
in
extension_dict
.
iteritems
():
constant_name
=
extension_name
.
upper
()
+
"_FIELD_NUMBER"
setattr
(
cls
,
constant_name
,
extension_field
.
number
)
def
_AddStaticMethods
(
cls
):
# TODO(robinson): This probably needs to be thread-safe(?)
def
RegisterExtension
(
extension_handle
):
...
...
src/google/protobuf/compiler/cpp/cpp_extension.cc
View file @
cfa2d8aa
...
...
@@ -77,9 +77,11 @@ ExtensionGenerator::~ExtensionGenerator() {}
void
ExtensionGenerator
::
GenerateDeclaration
(
io
::
Printer
*
printer
)
{
map
<
string
,
string
>
vars
;
vars
[
"extendee"
]
=
ClassName
(
descriptor_
->
containing_type
(),
true
);
vars
[
"type_traits"
]
=
type_traits_
;
vars
[
"name"
]
=
descriptor_
->
name
();
vars
[
"extendee"
]
=
ClassName
(
descriptor_
->
containing_type
(),
true
);
vars
[
"number"
]
=
SimpleItoa
(
descriptor_
->
number
());
vars
[
"type_traits"
]
=
type_traits_
;
vars
[
"name"
]
=
descriptor_
->
name
();
vars
[
"constant_name"
]
=
FieldConstantName
(
descriptor_
);
// If this is a class member, it needs to be declared "static". Otherwise,
// it needs to be "extern".
...
...
@@ -91,24 +93,34 @@ void ExtensionGenerator::GenerateDeclaration(io::Printer* printer) {
}
printer
->
Print
(
vars
,
"static const int $constant_name$ = $number$;
\n
"
"$qualifier$ ::google::protobuf::internal::ExtensionIdentifier< $extendee$,
\n
"
" ::google::protobuf::internal::$type_traits$ > $name$;
\n
"
);
}
void
ExtensionGenerator
::
GenerateDefinition
(
io
::
Printer
*
printer
)
{
map
<
string
,
string
>
vars
;
vars
[
"extendee"
]
=
ClassName
(
descriptor_
->
containing_type
(),
true
);
vars
[
"
number"
]
=
SimpleItoa
(
descriptor_
->
number
())
;
vars
[
"
type_traits"
]
=
type_traits_
;
vars
[
"
name"
]
=
descriptor_
->
name
(
);
vars
[
"extendee"
]
=
ClassName
(
descriptor_
->
containing_type
(),
true
);
vars
[
"
type_traits"
]
=
type_traits_
;
vars
[
"
name"
]
=
descriptor_
->
name
()
;
vars
[
"
constant_name"
]
=
FieldConstantName
(
descriptor_
);
// If this is a class member, it needs to be declared in its class scope.
vars
[
"scope"
]
=
(
descriptor_
->
extension_scope
()
==
NULL
)
?
""
:
ClassName
(
descriptor_
->
extension_scope
(),
false
)
+
"::"
;
// Likewise, class members need to declare the field constant variable.
if
(
descriptor_
->
extension_scope
()
!=
NULL
)
{
printer
->
Print
(
vars
,
"#ifndef _MSC_VER
\n
"
"const int $scope$$constant_name$;
\n
"
"#endif
\n
"
);
}
printer
->
Print
(
vars
,
"::google::protobuf::internal::ExtensionIdentifier< $extendee$,
\n
"
" ::google::protobuf::internal::$type_traits$ > $scope$$name$($number$);
\n
"
);
" ::google::protobuf::internal::$type_traits$ > $scope$$name$("
"$constant_name$);
\n
"
);
}
}
// namespace cpp
...
...
src/google/protobuf/compiler/cpp/cpp_helpers.cc
View file @
cfa2d8aa
...
...
@@ -77,6 +77,31 @@ hash_set<string> MakeKeywordsMap() {
hash_set
<
string
>
kKeywords
=
MakeKeywordsMap
();
string
UnderscoresToCamelCase
(
const
string
&
input
,
bool
cap_next_letter
)
{
string
result
;
// Note: I distrust ctype.h due to locales.
for
(
int
i
=
0
;
i
<
input
.
size
();
i
++
)
{
if
(
'a'
<=
input
[
i
]
&&
input
[
i
]
<=
'z'
)
{
if
(
cap_next_letter
)
{
result
+=
input
[
i
]
+
(
'A'
-
'a'
);
}
else
{
result
+=
input
[
i
];
}
cap_next_letter
=
false
;
}
else
if
(
'A'
<=
input
[
i
]
&&
input
[
i
]
<=
'Z'
)
{
// Capital letters are left as-is.
result
+=
input
[
i
];
cap_next_letter
=
false
;
}
else
if
(
'0'
<=
input
[
i
]
&&
input
[
i
]
<=
'9'
)
{
result
+=
input
[
i
];
cap_next_letter
=
true
;
}
else
{
cap_next_letter
=
true
;
}
}
return
result
;
}
}
// namespace
const
char
kThickSeparator
[]
=
...
...
@@ -124,6 +149,11 @@ string FieldName(const FieldDescriptor* field) {
return
result
;
}
string
FieldConstantName
(
const
FieldDescriptor
*
field
)
{
string
field_name
=
UnderscoresToCamelCase
(
field
->
name
(),
true
);
return
"k"
+
field_name
+
"FieldNumber"
;
}
string
StripProto
(
const
string
&
filename
)
{
if
(
HasSuffixString
(
filename
,
".protodevel"
))
{
return
StripSuffixString
(
filename
,
".protodevel"
);
...
...
src/google/protobuf/compiler/cpp/cpp_helpers.h
View file @
cfa2d8aa
...
...
@@ -65,6 +65,10 @@ string ClassName(const EnumDescriptor* enum_descriptor, bool qualified);
// anyway, so normally this just returns field->name().
string
FieldName
(
const
FieldDescriptor
*
field
);
// Get the unqualified name that should be used for a field's field
// number constant.
string
FieldConstantName
(
const
FieldDescriptor
*
field
);
// Returns the scope where the field was defined (for extensions, this is
// different from the message type to which the field applies).
inline
const
Descriptor
*
FieldScope
(
const
FieldDescriptor
*
field
)
{
...
...
src/google/protobuf/compiler/cpp/cpp_message.cc
View file @
cfa2d8aa
...
...
@@ -204,6 +204,8 @@ GenerateFieldAccessorDeclarations(io::Printer* printer) {
map
<
string
,
string
>
vars
;
vars
[
"name"
]
=
FieldName
(
field
);
vars
[
"constant_name"
]
=
FieldConstantName
(
field
);
vars
[
"number"
]
=
SimpleItoa
(
field
->
number
());
if
(
field
->
is_repeated
())
{
printer
->
Print
(
vars
,
"inline int $name$_size() const;
\n
"
);
...
...
@@ -212,6 +214,7 @@ GenerateFieldAccessorDeclarations(io::Printer* printer) {
}
printer
->
Print
(
vars
,
"inline void clear_$name$();
\n
"
);
printer
->
Print
(
vars
,
"static const int $constant_name$ = $number$;
\n
"
);
// Generate type-specific accessor declarations.
field_generators_
.
get
(
field
).
GenerateAccessorDeclarations
(
printer
);
...
...
@@ -665,9 +668,21 @@ GenerateClassMethods(io::Printer* printer) {
for
(
int
i
=
0
;
i
<
descriptor_
->
field_count
();
i
++
)
{
field_generators_
.
get
(
descriptor_
->
field
(
i
))
.
GenerateNonInlineAccessorDefinitions
(
printer
);
printer
->
Print
(
"
\n
"
);
}
// Generate field number constants.
printer
->
Print
(
"#ifndef _MSC_VER
\n
"
);
for
(
int
i
=
0
;
i
<
descriptor_
->
field_count
();
i
++
)
{
const
FieldDescriptor
*
field
=
descriptor_
->
field
(
i
);
printer
->
Print
(
"const int $classname$::$constant_name$;
\n
"
,
"classname"
,
ClassName
(
FieldScope
(
field
),
false
),
"constant_name"
,
FieldConstantName
(
field
));
}
printer
->
Print
(
"#endif // !_MSC_VER
\n
"
"
\n
"
);
// Define extension identifiers.
for
(
int
i
=
0
;
i
<
descriptor_
->
extension_count
();
i
++
)
{
extension_generators_
[
i
]
->
GenerateDefinition
(
printer
);
...
...
src/google/protobuf/compiler/cpp/cpp_string_field.cc
View file @
cfa2d8aa
...
...
@@ -180,10 +180,10 @@ void StringFieldGenerator::
GenerateNonInlineAccessorDefinitions
(
io
::
Printer
*
printer
)
const
{
if
(
descriptor_
->
default_value_string
().
empty
())
{
printer
->
Print
(
variables_
,
"const ::std::string $classname$::_default_$name$_;"
);
"const ::std::string $classname$::_default_$name$_;
\n
"
);
}
else
{
printer
->
Print
(
variables_
,
"const ::std::string $classname$::_default_$name$_($default$);"
);
"const ::std::string $classname$::_default_$name$_($default$);
\n
"
);
}
}
...
...
src/google/protobuf/compiler/java/java_extension.cc
View file @
cfa2d8aa
...
...
@@ -57,6 +57,8 @@ void ExtensionGenerator::Generate(io::Printer* printer) {
map
<
string
,
string
>
vars
;
vars
[
"name"
]
=
UnderscoresToCamelCase
(
descriptor_
);
vars
[
"containing_type"
]
=
ClassName
(
descriptor_
->
containing_type
());
vars
[
"number"
]
=
SimpleItoa
(
descriptor_
->
number
());
vars
[
"constant_name"
]
=
FieldConstantName
(
descriptor_
);
JavaType
java_type
=
GetJavaType
(
descriptor_
);
string
singular_type
;
...
...
@@ -72,6 +74,8 @@ void ExtensionGenerator::Generate(io::Printer* printer) {
break
;
}
printer
->
Print
(
vars
,
"public static final int $constant_name$ = $number$;
\n
"
);
if
(
descriptor_
->
is_repeated
())
{
printer
->
Print
(
vars
,
"public static
\n
"
...
...
src/google/protobuf/compiler/java/java_helpers.cc
View file @
cfa2d8aa
...
...
@@ -171,6 +171,12 @@ string ClassName(const FileDescriptor* descriptor) {
return
result
;
}
string
FieldConstantName
(
const
FieldDescriptor
*
field
)
{
string
name
=
field
->
name
()
+
"_FIELD_NUMBER"
;
UpperString
(
&
name
);
return
name
;
}
JavaType
GetJavaType
(
FieldDescriptor
::
Type
field_type
)
{
switch
(
field_type
)
{
case
FieldDescriptor
:
:
TYPE_INT32
:
...
...
src/google/protobuf/compiler/java/java_helpers.h
View file @
cfa2d8aa
...
...
@@ -88,6 +88,10 @@ inline string ExtensionIdentifierName(const FieldDescriptor* descriptor) {
}
string
ClassName
(
const
FileDescriptor
*
descriptor
);
// Get the unqualified name that should be used for a field's field
// number constant.
string
FieldConstantName
(
const
FieldDescriptor
*
field
);
enum
JavaType
{
JAVATYPE_INT
,
JAVATYPE_LONG
,
...
...
src/google/protobuf/compiler/java/java_message.cc
View file @
cfa2d8aa
...
...
@@ -311,6 +311,9 @@ void MessageGenerator::Generate(io::Printer* printer) {
// Fields
for
(
int
i
=
0
;
i
<
descriptor_
->
field_count
();
i
++
)
{
PrintFieldComment
(
printer
,
descriptor_
->
field
(
i
));
printer
->
Print
(
"public static final int $constant_name$ = $number$;
\n
"
,
"constant_name"
,
FieldConstantName
(
descriptor_
->
field
(
i
)),
"number"
,
SimpleItoa
(
descriptor_
->
field
(
i
)
->
number
()));
field_generators_
.
get
(
descriptor_
->
field
(
i
)).
GenerateMembers
(
printer
);
printer
->
Print
(
"
\n
"
);
}
...
...
src/google/protobuf/compiler/python/python_generator.cc
View file @
cfa2d8aa
...
...
@@ -319,6 +319,11 @@ void Generator::PrintTopLevelExtensions() const {
const
bool
is_extension
=
true
;
for
(
int
i
=
0
;
i
<
file_
->
extension_count
();
++
i
)
{
const
FieldDescriptor
&
extension_field
=
*
file_
->
extension
(
i
);
string
constant_name
=
extension_field
.
name
()
+
"_FIELD_NUMBER"
;
UpperString
(
&
constant_name
);
printer_
->
Print
(
"$constant_name$ = $number$
\n
"
,
"constant_name"
,
constant_name
,
"number"
,
SimpleItoa
(
extension_field
.
number
()));
printer_
->
Print
(
"$name$ = "
,
"name"
,
extension_field
.
name
());
PrintFieldDescriptor
(
extension_field
,
is_extension
);
printer_
->
Print
(
"
\n
"
);
...
...
src/google/protobuf/descriptor.pb.cc
View file @
cfa2d8aa
...
...
@@ -557,6 +557,9 @@ struct StaticDescriptorInitializer_google_2fprotobuf_2fdescriptor_2eproto {
// ===================================================================
#ifndef _MSC_VER
const
int
FileDescriptorSet
::
kFileFieldNumber
;
#endif // !_MSC_VER
FileDescriptorSet
::
FileDescriptorSet
()
:
::
google
::
protobuf
::
Message
(),
...
...
@@ -736,11 +739,16 @@ const ::google::protobuf::Reflection* FileDescriptorSet::GetReflection() const {
const
::
std
::
string
FileDescriptorProto
::
_default_name_
;
const
::
std
::
string
FileDescriptorProto
::
_default_package_
;
#ifndef _MSC_VER
const
int
FileDescriptorProto
::
kNameFieldNumber
;
const
int
FileDescriptorProto
::
kPackageFieldNumber
;
const
int
FileDescriptorProto
::
kDependencyFieldNumber
;
const
int
FileDescriptorProto
::
kMessageTypeFieldNumber
;
const
int
FileDescriptorProto
::
kEnumTypeFieldNumber
;
const
int
FileDescriptorProto
::
kServiceFieldNumber
;
const
int
FileDescriptorProto
::
kExtensionFieldNumber
;
const
int
FileDescriptorProto
::
kOptionsFieldNumber
;
#endif // !_MSC_VER
FileDescriptorProto
::
FileDescriptorProto
()
:
::
google
::
protobuf
::
Message
(),
...
...
@@ -1172,7 +1180,10 @@ const ::google::protobuf::Reflection* FileDescriptorProto::GetReflection() const
// ===================================================================
#ifndef _MSC_VER
const
int
DescriptorProto_ExtensionRange
::
kStartFieldNumber
;
const
int
DescriptorProto_ExtensionRange
::
kEndFieldNumber
;
#endif // !_MSC_VER
DescriptorProto_ExtensionRange
::
DescriptorProto_ExtensionRange
()
:
::
google
::
protobuf
::
Message
(),
...
...
@@ -1387,11 +1398,15 @@ const ::google::protobuf::Reflection* DescriptorProto_ExtensionRange::GetReflect
// -------------------------------------------------------------------
const
::
std
::
string
DescriptorProto
::
_default_name_
;
#ifndef _MSC_VER
const
int
DescriptorProto
::
kNameFieldNumber
;
const
int
DescriptorProto
::
kFieldFieldNumber
;
const
int
DescriptorProto
::
kExtensionFieldNumber
;
const
int
DescriptorProto
::
kNestedTypeFieldNumber
;
const
int
DescriptorProto
::
kEnumTypeFieldNumber
;
const
int
DescriptorProto
::
kExtensionRangeFieldNumber
;
const
int
DescriptorProto
::
kOptionsFieldNumber
;
#endif // !_MSC_VER
DescriptorProto
::
DescriptorProto
()
:
::
google
::
protobuf
::
Message
(),
...
...
@@ -1862,12 +1877,19 @@ const FieldDescriptorProto_Label FieldDescriptorProto::Label_MIN;
const
FieldDescriptorProto_Label
FieldDescriptorProto
::
Label_MAX
;
#endif // _MSC_VER
const
::
std
::
string
FieldDescriptorProto
::
_default_name_
;
const
::
std
::
string
FieldDescriptorProto
::
_default_type_name_
;
const
::
std
::
string
FieldDescriptorProto
::
_default_extendee_
;
const
::
std
::
string
FieldDescriptorProto
::
_default_default_value_
;
#ifndef _MSC_VER
const
int
FieldDescriptorProto
::
kNameFieldNumber
;
const
int
FieldDescriptorProto
::
kNumberFieldNumber
;
const
int
FieldDescriptorProto
::
kLabelFieldNumber
;
const
int
FieldDescriptorProto
::
kTypeFieldNumber
;
const
int
FieldDescriptorProto
::
kTypeNameFieldNumber
;
const
int
FieldDescriptorProto
::
kExtendeeFieldNumber
;
const
int
FieldDescriptorProto
::
kDefaultValueFieldNumber
;
const
int
FieldDescriptorProto
::
kOptionsFieldNumber
;
#endif // !_MSC_VER
FieldDescriptorProto
::
FieldDescriptorProto
()
:
::
google
::
protobuf
::
Message
(),
...
...
@@ -2308,7 +2330,11 @@ const ::google::protobuf::Reflection* FieldDescriptorProto::GetReflection() cons
// ===================================================================
const
::
std
::
string
EnumDescriptorProto
::
_default_name_
;
#ifndef _MSC_VER
const
int
EnumDescriptorProto
::
kNameFieldNumber
;
const
int
EnumDescriptorProto
::
kValueFieldNumber
;
const
int
EnumDescriptorProto
::
kOptionsFieldNumber
;
#endif // !_MSC_VER
EnumDescriptorProto
::
EnumDescriptorProto
()
:
::
google
::
protobuf
::
Message
(),
...
...
@@ -2568,7 +2594,11 @@ const ::google::protobuf::Reflection* EnumDescriptorProto::GetReflection() const
// ===================================================================
const
::
std
::
string
EnumValueDescriptorProto
::
_default_name_
;
#ifndef _MSC_VER
const
int
EnumValueDescriptorProto
::
kNameFieldNumber
;
const
int
EnumValueDescriptorProto
::
kNumberFieldNumber
;
const
int
EnumValueDescriptorProto
::
kOptionsFieldNumber
;
#endif // !_MSC_VER
EnumValueDescriptorProto
::
EnumValueDescriptorProto
()
:
::
google
::
protobuf
::
Message
(),
...
...
@@ -2826,7 +2856,11 @@ const ::google::protobuf::Reflection* EnumValueDescriptorProto::GetReflection()
// ===================================================================
const
::
std
::
string
ServiceDescriptorProto
::
_default_name_
;
#ifndef _MSC_VER
const
int
ServiceDescriptorProto
::
kNameFieldNumber
;
const
int
ServiceDescriptorProto
::
kMethodFieldNumber
;
const
int
ServiceDescriptorProto
::
kOptionsFieldNumber
;
#endif // !_MSC_VER
ServiceDescriptorProto
::
ServiceDescriptorProto
()
:
::
google
::
protobuf
::
Message
(),
...
...
@@ -3088,6 +3122,12 @@ const ::google::protobuf::Reflection* ServiceDescriptorProto::GetReflection() co
const
::
std
::
string
MethodDescriptorProto
::
_default_name_
;
const
::
std
::
string
MethodDescriptorProto
::
_default_input_type_
;
const
::
std
::
string
MethodDescriptorProto
::
_default_output_type_
;
#ifndef _MSC_VER
const
int
MethodDescriptorProto
::
kNameFieldNumber
;
const
int
MethodDescriptorProto
::
kInputTypeFieldNumber
;
const
int
MethodDescriptorProto
::
kOutputTypeFieldNumber
;
const
int
MethodDescriptorProto
::
kOptionsFieldNumber
;
#endif // !_MSC_VER
MethodDescriptorProto
::
MethodDescriptorProto
()
:
::
google
::
protobuf
::
Message
(),
...
...
@@ -3407,8 +3447,13 @@ const FileOptions_OptimizeMode FileOptions::OptimizeMode_MAX;
#endif // _MSC_VER
const
::
std
::
string
FileOptions
::
_default_java_package_
;
const
::
std
::
string
FileOptions
::
_default_java_outer_classname_
;
#ifndef _MSC_VER
const
int
FileOptions
::
kJavaPackageFieldNumber
;
const
int
FileOptions
::
kJavaOuterClassnameFieldNumber
;
const
int
FileOptions
::
kJavaMultipleFilesFieldNumber
;
const
int
FileOptions
::
kOptimizeForFieldNumber
;
const
int
FileOptions
::
kUninterpretedOptionFieldNumber
;
#endif // !_MSC_VER
FileOptions
::
FileOptions
()
:
::
google
::
protobuf
::
Message
(),
...
...
@@ -3752,7 +3797,10 @@ const ::google::protobuf::Reflection* FileOptions::GetReflection() const {
// ===================================================================
#ifndef _MSC_VER
const
int
MessageOptions
::
kMessageSetWireFormatFieldNumber
;
const
int
MessageOptions
::
kUninterpretedOptionFieldNumber
;
#endif // !_MSC_VER
MessageOptions
::
MessageOptions
()
:
::
google
::
protobuf
::
Message
(),
...
...
@@ -4006,9 +4054,13 @@ const FieldOptions_CType FieldOptions::STRING_PIECE;
const
FieldOptions_CType
FieldOptions
::
CType_MIN
;
const
FieldOptions_CType
FieldOptions
::
CType_MAX
;
#endif // _MSC_VER
const
::
std
::
string
FieldOptions
::
_default_experimental_map_key_
;
#ifndef _MSC_VER
const
int
FieldOptions
::
kCtypeFieldNumber
;
const
int
FieldOptions
::
kPackedFieldNumber
;
const
int
FieldOptions
::
kExperimentalMapKeyFieldNumber
;
const
int
FieldOptions
::
kUninterpretedOptionFieldNumber
;
#endif // !_MSC_VER
FieldOptions
::
FieldOptions
()
:
::
google
::
protobuf
::
Message
(),
...
...
@@ -4315,6 +4367,9 @@ const ::google::protobuf::Reflection* FieldOptions::GetReflection() const {
// ===================================================================
#ifndef _MSC_VER
const
int
EnumOptions
::
kUninterpretedOptionFieldNumber
;
#endif // !_MSC_VER
EnumOptions
::
EnumOptions
()
:
::
google
::
protobuf
::
Message
(),
...
...
@@ -4512,6 +4567,9 @@ const ::google::protobuf::Reflection* EnumOptions::GetReflection() const {
// ===================================================================
#ifndef _MSC_VER
const
int
EnumValueOptions
::
kUninterpretedOptionFieldNumber
;
#endif // !_MSC_VER
EnumValueOptions
::
EnumValueOptions
()
:
::
google
::
protobuf
::
Message
(),
...
...
@@ -4709,6 +4767,9 @@ const ::google::protobuf::Reflection* EnumValueOptions::GetReflection() const {
// ===================================================================
#ifndef _MSC_VER
const
int
ServiceOptions
::
kUninterpretedOptionFieldNumber
;
#endif // !_MSC_VER
ServiceOptions
::
ServiceOptions
()
:
::
google
::
protobuf
::
Message
(),
...
...
@@ -4906,6 +4967,9 @@ const ::google::protobuf::Reflection* ServiceOptions::GetReflection() const {
// ===================================================================
#ifndef _MSC_VER
const
int
MethodOptions
::
kUninterpretedOptionFieldNumber
;
#endif // !_MSC_VER
MethodOptions
::
MethodOptions
()
:
::
google
::
protobuf
::
Message
(),
...
...
@@ -5104,6 +5168,10 @@ const ::google::protobuf::Reflection* MethodOptions::GetReflection() const {
// ===================================================================
const
::
std
::
string
UninterpretedOption_NamePart
::
_default_name_part_
;
#ifndef _MSC_VER
const
int
UninterpretedOption_NamePart
::
kNamePartFieldNumber
;
const
int
UninterpretedOption_NamePart
::
kIsExtensionFieldNumber
;
#endif // !_MSC_VER
UninterpretedOption_NamePart
::
UninterpretedOption_NamePart
()
:
::
google
::
protobuf
::
Message
(),
...
...
@@ -5320,12 +5388,17 @@ const ::google::protobuf::Reflection* UninterpretedOption_NamePart::GetReflectio
// -------------------------------------------------------------------
const
::
std
::
string
UninterpretedOption
::
_default_identifier_value_
;
const
::
std
::
string
UninterpretedOption
::
_default_string_value_
;
#ifndef _MSC_VER
const
int
UninterpretedOption
::
kNameFieldNumber
;
const
int
UninterpretedOption
::
kIdentifierValueFieldNumber
;
const
int
UninterpretedOption
::
kPositiveIntValueFieldNumber
;
const
int
UninterpretedOption
::
kNegativeIntValueFieldNumber
;
const
int
UninterpretedOption
::
kDoubleValueFieldNumber
;
const
int
UninterpretedOption
::
kStringValueFieldNumber
;
#endif // !_MSC_VER
UninterpretedOption
::
UninterpretedOption
()
:
::
google
::
protobuf
::
Message
(),
_unknown_fields_
(),
...
...
src/google/protobuf/descriptor.pb.h
View file @
cfa2d8aa
This diff is collapsed.
Click to expand it.
src/google/protobuf/message_unittest.cc
View file @
cfa2d8aa
...
...
@@ -248,6 +248,36 @@ TEST(MessageTest, ParseFailsOnInvalidMessageEnd) {
EXPECT_FALSE
(
message
.
ParseFromArray
(
"
\014
"
,
1
));
}
TEST
(
MessageTest
,
FieldConstantValues
)
{
unittest
::
TestRequired
message
;
EXPECT_EQ
(
protobuf_unittest
::
TestAllTypes_NestedMessage
::
kBbFieldNumber
,
1
);
EXPECT_EQ
(
protobuf_unittest
::
TestAllTypes
::
kOptionalInt32FieldNumber
,
1
);
EXPECT_EQ
(
protobuf_unittest
::
TestAllTypes
::
kOptionalgroupFieldNumber
,
16
);
EXPECT_EQ
(
protobuf_unittest
::
TestAllTypes
::
kOptionalNestedMessageFieldNumber
,
18
);
EXPECT_EQ
(
protobuf_unittest
::
TestAllTypes
::
kOptionalNestedEnumFieldNumber
,
21
);
EXPECT_EQ
(
protobuf_unittest
::
TestAllTypes
::
kRepeatedInt32FieldNumber
,
31
);
EXPECT_EQ
(
protobuf_unittest
::
TestAllTypes
::
kRepeatedgroupFieldNumber
,
46
);
EXPECT_EQ
(
protobuf_unittest
::
TestAllTypes
::
kRepeatedNestedMessageFieldNumber
,
48
);
EXPECT_EQ
(
protobuf_unittest
::
TestAllTypes
::
kRepeatedNestedEnumFieldNumber
,
51
);
}
TEST
(
MessageTest
,
ExtensionConstantValues
)
{
EXPECT_EQ
(
protobuf_unittest
::
TestRequired
::
kSingleFieldNumber
,
1000
);
EXPECT_EQ
(
protobuf_unittest
::
TestRequired
::
kMultiFieldNumber
,
1001
);
EXPECT_EQ
(
protobuf_unittest
::
kOptionalInt32ExtensionFieldNumber
,
1
);
EXPECT_EQ
(
protobuf_unittest
::
kOptionalgroupExtensionFieldNumber
,
16
);
EXPECT_EQ
(
protobuf_unittest
::
kOptionalNestedMessageExtensionFieldNumber
,
18
);
EXPECT_EQ
(
protobuf_unittest
::
kOptionalNestedEnumExtensionFieldNumber
,
21
);
EXPECT_EQ
(
protobuf_unittest
::
kRepeatedInt32ExtensionFieldNumber
,
31
);
EXPECT_EQ
(
protobuf_unittest
::
kRepeatedgroupExtensionFieldNumber
,
46
);
EXPECT_EQ
(
protobuf_unittest
::
kRepeatedNestedMessageExtensionFieldNumber
,
48
);
EXPECT_EQ
(
protobuf_unittest
::
kRepeatedNestedEnumExtensionFieldNumber
,
51
);
}
TEST
(
MessageFactoryTest
,
GeneratedFactoryLookup
)
{
EXPECT_EQ
(
MessageFactory
::
generated_factory
()
->
GetPrototype
(
...
...
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