protobuf 2.8.0.beta9 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +0 -1
  3. data/{UPGRADING.md → CHANGES.md} +20 -12
  4. data/LICENSE.txt +14 -0
  5. data/README.md +60 -74
  6. data/bin/protoc-gen-ruby +26 -0
  7. data/bin/rprotoc +4 -58
  8. data/lib/protobuf.rb +15 -13
  9. data/lib/protobuf/code_generator.rb +41 -0
  10. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +51 -0
  11. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +248 -0
  12. data/lib/protobuf/field/base_field.rb +0 -1
  13. data/lib/protobuf/field/bytes_field.rb +1 -1
  14. data/lib/protobuf/field/message_field.rb +2 -4
  15. data/lib/protobuf/field/varint_field.rb +4 -7
  16. data/lib/protobuf/generators/base.rb +71 -0
  17. data/lib/protobuf/generators/enum_generator.rb +31 -0
  18. data/lib/protobuf/generators/extension_generator.rb +28 -0
  19. data/lib/protobuf/generators/field_generator.rb +132 -0
  20. data/lib/protobuf/generators/file_generator.rb +140 -0
  21. data/lib/protobuf/generators/group_generator.rb +113 -0
  22. data/lib/protobuf/generators/message_generator.rb +99 -0
  23. data/lib/protobuf/generators/printable.rb +161 -0
  24. data/lib/protobuf/generators/service_generator.rb +27 -0
  25. data/lib/protobuf/lifecycle.rb +7 -3
  26. data/lib/protobuf/message.rb +51 -34
  27. data/lib/protobuf/rpc/connectors/common.rb +4 -6
  28. data/lib/protobuf/rpc/server.rb +1 -1
  29. data/lib/protobuf/rpc/servers/zmq/server.rb +2 -2
  30. data/lib/protobuf/rpc/servers/zmq/worker.rb +2 -2
  31. data/lib/protobuf/rpc/service.rb +3 -3
  32. data/lib/protobuf/rpc/service_directory.rb +24 -12
  33. data/lib/protobuf/version.rb +1 -1
  34. data/proto/google/protobuf/compiler/plugin.proto +147 -0
  35. data/proto/google/protobuf/descriptor.proto +620 -0
  36. data/protobuf.gemspec +12 -21
  37. data/spec/bin/protoc-gen-ruby_spec.rb +18 -0
  38. data/spec/data/data.bin +3 -0
  39. data/{test/data/unk.png → spec/data/types.bin} +0 -0
  40. data/spec/encoding/all_types_spec.rb +91 -0
  41. data/spec/encoding/extreme_values_spec.rb +0 -0
  42. data/spec/lib/protobuf/code_generator_spec.rb +60 -0
  43. data/spec/lib/protobuf/generators/base_spec.rb +87 -0
  44. data/spec/lib/protobuf/generators/enum_generator_spec.rb +45 -0
  45. data/spec/lib/protobuf/generators/extension_generator_spec.rb +43 -0
  46. data/spec/lib/protobuf/generators/field_generator_spec.rb +99 -0
  47. data/spec/lib/protobuf/generators/file_generator_spec.rb +29 -0
  48. data/spec/lib/protobuf/generators/message_generator_spec.rb +0 -0
  49. data/spec/lib/protobuf/generators/service_generator_spec.rb +43 -0
  50. data/spec/lib/protobuf/lifecycle_spec.rb +31 -1
  51. data/spec/lib/protobuf/logger_spec.rb +5 -0
  52. data/spec/lib/protobuf/message_spec.rb +22 -8
  53. data/spec/lib/protobuf/rpc/connectors/common_spec.rb +1 -1
  54. data/spec/lib/protobuf/rpc/service_directory_spec.rb +45 -7
  55. data/spec/lib/protobuf/rpc/service_spec.rb +3 -3
  56. data/spec/spec_helper.rb +15 -16
  57. data/spec/support/test/all_types.data.bin +0 -0
  58. data/spec/support/test/all_types.data.txt +119 -0
  59. data/spec/support/test/defaults.pb.rb +25 -0
  60. data/spec/support/test/defaults.proto +9 -0
  61. data/spec/support/test/enum.pb.rb +10 -8
  62. data/spec/support/test/extended.pb.rb +5 -3
  63. data/spec/support/test/extreme_values.data.bin +0 -0
  64. data/spec/support/test/google_unittest.pb.rb +543 -0
  65. data/spec/support/test/google_unittest.proto +713 -0
  66. data/spec/support/test/google_unittest_import.pb.rb +37 -0
  67. data/{ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h → spec/support/test/google_unittest_import.proto} +27 -17
  68. data/spec/support/test/google_unittest_import_public.pb.rb +8 -0
  69. data/{ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h → spec/support/test/google_unittest_import_public.proto} +5 -31
  70. data/spec/support/test/multi_field_extensions.pb.rb +29 -7
  71. data/spec/support/test/multi_field_extensions.proto +12 -2
  72. data/spec/support/test/resource.pb.rb +20 -16
  73. metadata +149 -236
  74. data/examples/addressbook.pb.rb +0 -55
  75. data/examples/addressbook.proto +0 -24
  76. data/examples/reading_a_message.rb +0 -32
  77. data/examples/writing_a_message.rb +0 -46
  78. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h +0 -142
  79. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h +0 -318
  80. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h +0 -99
  81. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h +0 -103
  82. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h +0 -85
  83. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h +0 -167
  84. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h +0 -98
  85. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h +0 -72
  86. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h +0 -159
  87. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h +0 -170
  88. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h +0 -102
  89. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +0 -103
  90. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h +0 -118
  91. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h +0 -104
  92. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h +0 -2721
  93. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h +0 -303
  94. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h +0 -84
  95. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h +0 -121
  96. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h +0 -77
  97. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h +0 -108
  98. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h +0 -101
  99. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h +0 -72
  100. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h +0 -213
  101. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h +0 -109
  102. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h +0 -134
  103. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h +0 -121
  104. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h +0 -113
  105. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h +0 -120
  106. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h +0 -113
  107. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h +0 -64
  108. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h +0 -434
  109. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h +0 -73
  110. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h +0 -790
  111. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h +0 -156
  112. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h +0 -108
  113. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h +0 -93
  114. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.h +0 -1367
  115. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h +0 -5223
  116. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h +0 -366
  117. data/ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h +0 -136
  118. data/ext/protobuf-2.4.1/src/google/protobuf/extension_set.h +0 -904
  119. data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h +0 -424
  120. data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h +0 -82
  121. data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h +0 -1102
  122. data/ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h +0 -207
  123. data/ext/protobuf-2.4.1/src/google/protobuf/io/printer.h +0 -136
  124. data/ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h +0 -313
  125. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h +0 -238
  126. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h +0 -357
  127. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h +0 -340
  128. data/ext/protobuf-2.4.1/src/google/protobuf/message.h +0 -692
  129. data/ext/protobuf-2.4.1/src/google/protobuf/message_lite.h +0 -239
  130. data/ext/protobuf-2.4.1/src/google/protobuf/package_info.h +0 -64
  131. data/ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h +0 -80
  132. data/ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h +0 -1295
  133. data/ext/protobuf-2.4.1/src/google/protobuf/service.h +0 -291
  134. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h +0 -1211
  135. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h +0 -220
  136. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h +0 -119
  137. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h +0 -123
  138. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h +0 -121
  139. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h +0 -457
  140. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h +0 -170
  141. data/ext/protobuf-2.4.1/src/google/protobuf/test_util.h +0 -174
  142. data/ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h +0 -101
  143. data/ext/protobuf-2.4.1/src/google/protobuf/testing/file.h +0 -83
  144. data/ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h +0 -98
  145. data/ext/protobuf-2.4.1/src/google/protobuf/text_format.h +0 -285
  146. data/ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h +0 -11915
  147. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h +0 -2895
  148. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h +0 -211
  149. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h +0 -56
  150. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h +0 -188
  151. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h +0 -151
  152. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h +0 -4752
  153. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h +0 -150
  154. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h +0 -816
  155. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h +0 -197
  156. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h +0 -403
  157. data/ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h +0 -268
  158. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format.h +0 -304
  159. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h +0 -620
  160. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h +0 -774
  161. data/ext/ruby_generator/Makefile +0 -10
  162. data/ext/ruby_generator/RubyGenerator.cpp +0 -544
  163. data/ext/ruby_generator/RubyGenerator.h +0 -206
  164. data/ext/ruby_generator/extconf.rb +0 -35
  165. data/test/data/data_source.py +0 -14
  166. data/test/data/types_source.py +0 -22
  167. data/test/proto/addressbook.pb.rb +0 -66
  168. data/test/proto/addressbook.proto +0 -33
  169. data/test/proto/addressbook_base.pb.rb +0 -58
  170. data/test/proto/addressbook_base.proto +0 -26
  171. data/test/proto/addressbook_ext.pb.rb +0 -20
  172. data/test/proto/addressbook_ext.proto +0 -6
  173. data/test/proto/collision.pb.rb +0 -17
  174. data/test/proto/collision.proto +0 -5
  175. data/test/proto/ext_collision.pb.rb +0 -24
  176. data/test/proto/ext_collision.proto +0 -8
  177. data/test/proto/ext_range.pb.rb +0 -22
  178. data/test/proto/ext_range.proto +0 -7
  179. data/test/proto/float_default.proto +0 -10
  180. data/test/proto/lowercase.pb.rb +0 -30
  181. data/test/proto/lowercase.proto +0 -9
  182. data/test/proto/merge.pb.rb +0 -39
  183. data/test/proto/merge.proto +0 -15
  184. data/test/proto/nested.pb.rb +0 -30
  185. data/test/proto/nested.proto +0 -9
  186. data/test/proto/optional_field.pb.rb +0 -35
  187. data/test/proto/optional_field.proto +0 -12
  188. data/test/proto/packed.pb.rb +0 -22
  189. data/test/proto/packed.proto +0 -6
  190. data/test/proto/rpc.proto +0 -6
  191. data/test/proto/types.pb.rb +0 -84
  192. data/test/proto/types.proto +0 -37
  193. data/test/test_addressbook.rb +0 -56
  194. data/test/test_enum_value.rb +0 -41
  195. data/test/test_extension.rb +0 -36
  196. data/test/test_lowercase.rb +0 -11
  197. data/test/test_message.rb +0 -128
  198. data/test/test_optional_field.rb +0 -103
  199. data/test/test_packed_field.rb +0 -40
  200. data/test/test_parse.rb +0 -15
  201. data/test/test_repeated_types.rb +0 -132
  202. data/test/test_serialize.rb +0 -61
  203. data/test/test_standard_message.rb +0 -96
  204. data/test/test_types.rb +0 -226
@@ -1,98 +0,0 @@
1
- // Protocol Buffers - Google's data interchange format
2
- // Copyright 2008 Google Inc. All rights reserved.
3
- // http://code.google.com/p/protobuf/
4
- //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
-
31
- // Author: kenton@google.com (Kenton Varda)
32
- // Based on original Protocol Buffers design by
33
- // Sanjay Ghemawat, Jeff Dean, and others.
34
-
35
- #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_FILE_H__
36
- #define GOOGLE_PROTOBUF_COMPILER_CPP_FILE_H__
37
-
38
- #include <string>
39
- #include <vector>
40
- #include <google/protobuf/stubs/common.h>
41
- #include <google/protobuf/compiler/cpp/cpp_field.h>
42
-
43
- namespace google {
44
- namespace protobuf {
45
- class FileDescriptor; // descriptor.h
46
- namespace io {
47
- class Printer; // printer.h
48
- }
49
- }
50
-
51
- namespace protobuf {
52
- namespace compiler {
53
- namespace cpp {
54
-
55
- class EnumGenerator; // enum.h
56
- class MessageGenerator; // message.h
57
- class ServiceGenerator; // service.h
58
- class ExtensionGenerator; // extension.h
59
-
60
- class FileGenerator {
61
- public:
62
- // See generator.cc for the meaning of dllexport_decl.
63
- explicit FileGenerator(const FileDescriptor* file,
64
- const string& dllexport_decl);
65
- ~FileGenerator();
66
-
67
- void GenerateHeader(io::Printer* printer);
68
- void GenerateSource(io::Printer* printer);
69
-
70
- private:
71
- // Generate the BuildDescriptors() procedure, which builds all descriptors
72
- // for types defined in the file.
73
- void GenerateBuildDescriptors(io::Printer* printer);
74
-
75
- void GenerateNamespaceOpeners(io::Printer* printer);
76
- void GenerateNamespaceClosers(io::Printer* printer);
77
-
78
- const FileDescriptor* file_;
79
-
80
- scoped_array<scoped_ptr<MessageGenerator> > message_generators_;
81
- scoped_array<scoped_ptr<EnumGenerator> > enum_generators_;
82
- scoped_array<scoped_ptr<ServiceGenerator> > service_generators_;
83
- scoped_array<scoped_ptr<ExtensionGenerator> > extension_generators_;
84
-
85
- // E.g. if the package is foo.bar, package_parts_ is {"foo", "bar"}.
86
- vector<string> package_parts_;
87
-
88
- string dllexport_decl_;
89
-
90
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileGenerator);
91
- };
92
-
93
- } // namespace cpp
94
- } // namespace compiler
95
- } // namespace protobuf
96
-
97
- } // namespace google
98
- #endif // GOOGLE_PROTOBUF_COMPILER_CPP_FILE_H__
@@ -1,72 +0,0 @@
1
- // Protocol Buffers - Google's data interchange format
2
- // Copyright 2008 Google Inc. All rights reserved.
3
- // http://code.google.com/p/protobuf/
4
- //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
-
31
- // Author: kenton@google.com (Kenton Varda)
32
- // Based on original Protocol Buffers design by
33
- // Sanjay Ghemawat, Jeff Dean, and others.
34
- //
35
- // Generates C++ code for a given .proto file.
36
-
37
- #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__
38
- #define GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__
39
-
40
- #include <string>
41
- #include <google/protobuf/compiler/code_generator.h>
42
-
43
- namespace google {
44
- namespace protobuf {
45
- namespace compiler {
46
- namespace cpp {
47
-
48
- // CodeGenerator implementation which generates a C++ source file and
49
- // header. If you create your own protocol compiler binary and you want
50
- // it to support C++ output, you can do so by registering an instance of this
51
- // CodeGenerator with the CommandLineInterface in your main() function.
52
- class LIBPROTOC_EXPORT CppGenerator : public CodeGenerator {
53
- public:
54
- CppGenerator();
55
- ~CppGenerator();
56
-
57
- // implements CodeGenerator ----------------------------------------
58
- bool Generate(const FileDescriptor* file,
59
- const string& parameter,
60
- GeneratorContext* generator_context,
61
- string* error) const;
62
-
63
- private:
64
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CppGenerator);
65
- };
66
-
67
- } // namespace cpp
68
- } // namespace compiler
69
- } // namespace protobuf
70
-
71
- } // namespace google
72
- #endif // GOOGLE_PROTOBUF_COMPILER_CPP_GENERATOR_H__
@@ -1,159 +0,0 @@
1
- // Protocol Buffers - Google's data interchange format
2
- // Copyright 2008 Google Inc. All rights reserved.
3
- // http://code.google.com/p/protobuf/
4
- //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
-
31
- // Author: kenton@google.com (Kenton Varda)
32
- // Based on original Protocol Buffers design by
33
- // Sanjay Ghemawat, Jeff Dean, and others.
34
-
35
- #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__
36
- #define GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__
37
-
38
- #include <string>
39
- #include <google/protobuf/descriptor.h>
40
- #include <google/protobuf/descriptor.pb.h>
41
-
42
- namespace google {
43
- namespace protobuf {
44
- namespace compiler {
45
- namespace cpp {
46
-
47
- // Commonly-used separator comments. Thick is a line of '=', thin is a line
48
- // of '-'.
49
- extern const char kThickSeparator[];
50
- extern const char kThinSeparator[];
51
-
52
- // Returns the non-nested type name for the given type. If "qualified" is
53
- // true, prefix the type with the full namespace. For example, if you had:
54
- // package foo.bar;
55
- // message Baz { message Qux {} }
56
- // Then the qualified ClassName for Qux would be:
57
- // ::foo::bar::Baz_Qux
58
- // While the non-qualified version would be:
59
- // Baz_Qux
60
- string ClassName(const Descriptor* descriptor, bool qualified);
61
- string ClassName(const EnumDescriptor* enum_descriptor, bool qualified);
62
-
63
- string SuperClassName(const Descriptor* descriptor);
64
-
65
- // Get the (unqualified) name that should be used for this field in C++ code.
66
- // The name is coerced to lower-case to emulate proto1 behavior. People
67
- // should be using lowercase-with-underscores style for proto field names
68
- // anyway, so normally this just returns field->name().
69
- string FieldName(const FieldDescriptor* field);
70
-
71
- // Get the unqualified name that should be used for a field's field
72
- // number constant.
73
- string FieldConstantName(const FieldDescriptor *field);
74
-
75
- // Returns the scope where the field was defined (for extensions, this is
76
- // different from the message type to which the field applies).
77
- inline const Descriptor* FieldScope(const FieldDescriptor* field) {
78
- return field->is_extension() ?
79
- field->extension_scope() : field->containing_type();
80
- }
81
-
82
- // Returns the fully-qualified type name field->message_type(). Usually this
83
- // is just ClassName(field->message_type(), true);
84
- string FieldMessageTypeName(const FieldDescriptor* field);
85
-
86
- // Strips ".proto" or ".protodevel" from the end of a filename.
87
- string StripProto(const string& filename);
88
-
89
- // Get the C++ type name for a primitive type (e.g. "double", "::google::protobuf::int32", etc.).
90
- // Note: non-built-in type names will be qualified, meaning they will start
91
- // with a ::. If you are using the type as a template parameter, you will
92
- // need to insure there is a space between the < and the ::, because the
93
- // ridiculous C++ standard defines "<:" to be a synonym for "[".
94
- const char* PrimitiveTypeName(FieldDescriptor::CppType type);
95
-
96
- // Get the declared type name in CamelCase format, as is used e.g. for the
97
- // methods of WireFormat. For example, TYPE_INT32 becomes "Int32".
98
- const char* DeclaredTypeMethodName(FieldDescriptor::Type type);
99
-
100
- // Get code that evaluates to the field's default value.
101
- string DefaultValue(const FieldDescriptor* field);
102
-
103
- // Convert a file name into a valid identifier.
104
- string FilenameIdentifier(const string& filename);
105
-
106
- // Return the name of the AddDescriptors() function for a given file.
107
- string GlobalAddDescriptorsName(const string& filename);
108
-
109
- // Return the name of the AssignDescriptors() function for a given file.
110
- string GlobalAssignDescriptorsName(const string& filename);
111
-
112
- // Return the name of the ShutdownFile() function for a given file.
113
- string GlobalShutdownFileName(const string& filename);
114
-
115
- // Escape C++ trigraphs by escaping question marks to \?
116
- string EscapeTrigraphs(const string& to_escape);
117
-
118
- // Do message classes in this file keep track of unknown fields?
119
- inline bool HasUnknownFields(const FileDescriptor *file) {
120
- return file->options().optimize_for() != FileOptions::LITE_RUNTIME;
121
- }
122
-
123
- // Does this file have generated parsing, serialization, and other
124
- // standard methods for which reflection-based fallback implementations exist?
125
- inline bool HasGeneratedMethods(const FileDescriptor *file) {
126
- return file->options().optimize_for() != FileOptions::CODE_SIZE;
127
- }
128
-
129
- // Do message classes in this file have descriptor and refelction methods?
130
- inline bool HasDescriptorMethods(const FileDescriptor *file) {
131
- return file->options().optimize_for() != FileOptions::LITE_RUNTIME;
132
- }
133
-
134
- // Should we generate generic services for this file?
135
- inline bool HasGenericServices(const FileDescriptor *file) {
136
- return file->service_count() > 0 &&
137
- file->options().optimize_for() != FileOptions::LITE_RUNTIME &&
138
- file->options().cc_generic_services();
139
- }
140
-
141
- // Should string fields in this file verify that their contents are UTF-8?
142
- inline bool HasUtf8Verification(const FileDescriptor* file) {
143
- return file->options().optimize_for() != FileOptions::LITE_RUNTIME;
144
- }
145
-
146
- // Should we generate a separate, super-optimized code path for serializing to
147
- // flat arrays? We don't do this in Lite mode because we'd rather reduce code
148
- // size.
149
- inline bool HasFastArraySerialization(const FileDescriptor* file) {
150
- return file->options().optimize_for() == FileOptions::SPEED;
151
- }
152
-
153
-
154
- } // namespace cpp
155
- } // namespace compiler
156
- } // namespace protobuf
157
-
158
- } // namespace google
159
- #endif // GOOGLE_PROTOBUF_COMPILER_CPP_HELPERS_H__
@@ -1,170 +0,0 @@
1
- // Protocol Buffers - Google's data interchange format
2
- // Copyright 2008 Google Inc. All rights reserved.
3
- // http://code.google.com/p/protobuf/
4
- //
5
- // Redistribution and use in source and binary forms, with or without
6
- // modification, are permitted provided that the following conditions are
7
- // met:
8
- //
9
- // * Redistributions of source code must retain the above copyright
10
- // notice, this list of conditions and the following disclaimer.
11
- // * Redistributions in binary form must reproduce the above
12
- // copyright notice, this list of conditions and the following disclaimer
13
- // in the documentation and/or other materials provided with the
14
- // distribution.
15
- // * Neither the name of Google Inc. nor the names of its
16
- // contributors may be used to endorse or promote products derived from
17
- // this software without specific prior written permission.
18
- //
19
- // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
-
31
- // Author: kenton@google.com (Kenton Varda)
32
- // Based on original Protocol Buffers design by
33
- // Sanjay Ghemawat, Jeff Dean, and others.
34
-
35
- #ifndef GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__
36
- #define GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__
37
-
38
- #include <string>
39
- #include <google/protobuf/stubs/common.h>
40
- #include <google/protobuf/compiler/cpp/cpp_field.h>
41
-
42
- namespace google {
43
- namespace protobuf {
44
- namespace io {
45
- class Printer; // printer.h
46
- }
47
- }
48
-
49
- namespace protobuf {
50
- namespace compiler {
51
- namespace cpp {
52
-
53
- class EnumGenerator; // enum.h
54
- class ExtensionGenerator; // extension.h
55
-
56
- class MessageGenerator {
57
- public:
58
- // See generator.cc for the meaning of dllexport_decl.
59
- explicit MessageGenerator(const Descriptor* descriptor,
60
- const string& dllexport_decl);
61
- ~MessageGenerator();
62
-
63
- // Header stuff.
64
-
65
- // Generate foward declarations for this class and all its nested types.
66
- void GenerateForwardDeclaration(io::Printer* printer);
67
-
68
- // Generate definitions of all nested enums (must come before class
69
- // definitions because those classes use the enums definitions).
70
- void GenerateEnumDefinitions(io::Printer* printer);
71
-
72
- // Generate specializations of GetEnumDescriptor<MyEnum>().
73
- // Precondition: in ::google::protobuf namespace.
74
- void GenerateGetEnumDescriptorSpecializations(io::Printer* printer);
75
-
76
- // Generate definitions for this class and all its nested types.
77
- void GenerateClassDefinition(io::Printer* printer);
78
-
79
- // Generate definitions of inline methods (placed at the end of the header
80
- // file).
81
- void GenerateInlineMethods(io::Printer* printer);
82
-
83
- // Source file stuff.
84
-
85
- // Generate code which declares all the global descriptor pointers which
86
- // will be initialized by the methods below.
87
- void GenerateDescriptorDeclarations(io::Printer* printer);
88
-
89
- // Generate code that initializes the global variable storing the message's
90
- // descriptor.
91
- void GenerateDescriptorInitializer(io::Printer* printer, int index);
92
-
93
- // Generate code that calls MessageFactory::InternalRegisterGeneratedMessage()
94
- // for all types.
95
- void GenerateTypeRegistrations(io::Printer* printer);
96
-
97
- // Generates code that allocates the message's default instance.
98
- void GenerateDefaultInstanceAllocator(io::Printer* printer);
99
-
100
- // Generates code that initializes the message's default instance. This
101
- // is separate from allocating because all default instances must be
102
- // allocated before any can be initialized.
103
- void GenerateDefaultInstanceInitializer(io::Printer* printer);
104
-
105
- // Generates code that should be run when ShutdownProtobufLibrary() is called,
106
- // to delete all dynamically-allocated objects.
107
- void GenerateShutdownCode(io::Printer* printer);
108
-
109
- // Generate all non-inline methods for this class.
110
- void GenerateClassMethods(io::Printer* printer);
111
-
112
- private:
113
- // Generate declarations and definitions of accessors for fields.
114
- void GenerateFieldAccessorDeclarations(io::Printer* printer);
115
- void GenerateFieldAccessorDefinitions(io::Printer* printer);
116
-
117
- // Generate the field offsets array.
118
- void GenerateOffsets(io::Printer* printer);
119
-
120
- // Generate constructors and destructor.
121
- void GenerateStructors(io::Printer* printer);
122
-
123
- // The compiler typically generates multiple copies of each constructor and
124
- // destructor: http://gcc.gnu.org/bugs.html#nonbugs_cxx
125
- // Placing common code in a separate method reduces the generated code size.
126
- //
127
- // Generate the shared constructor code.
128
- void GenerateSharedConstructorCode(io::Printer* printer);
129
- // Generate the shared destructor code.
130
- void GenerateSharedDestructorCode(io::Printer* printer);
131
-
132
- // Generate standard Message methods.
133
- void GenerateClear(io::Printer* printer);
134
- void GenerateMergeFromCodedStream(io::Printer* printer);
135
- void GenerateSerializeWithCachedSizes(io::Printer* printer);
136
- void GenerateSerializeWithCachedSizesToArray(io::Printer* printer);
137
- void GenerateSerializeWithCachedSizesBody(io::Printer* printer,
138
- bool to_array);
139
- void GenerateByteSize(io::Printer* printer);
140
- void GenerateMergeFrom(io::Printer* printer);
141
- void GenerateCopyFrom(io::Printer* printer);
142
- void GenerateSwap(io::Printer* printer);
143
- void GenerateIsInitialized(io::Printer* printer);
144
-
145
- // Helpers for GenerateSerializeWithCachedSizes().
146
- void GenerateSerializeOneField(io::Printer* printer,
147
- const FieldDescriptor* field,
148
- bool unbounded);
149
- void GenerateSerializeOneExtensionRange(
150
- io::Printer* printer, const Descriptor::ExtensionRange* range,
151
- bool unbounded);
152
-
153
-
154
- const Descriptor* descriptor_;
155
- string classname_;
156
- string dllexport_decl_;
157
- FieldGeneratorMap field_generators_;
158
- scoped_array<scoped_ptr<MessageGenerator> > nested_generators_;
159
- scoped_array<scoped_ptr<EnumGenerator> > enum_generators_;
160
- scoped_array<scoped_ptr<ExtensionGenerator> > extension_generators_;
161
-
162
- GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageGenerator);
163
- };
164
-
165
- } // namespace cpp
166
- } // namespace compiler
167
- } // namespace protobuf
168
-
169
- } // namespace google
170
- #endif // GOOGLE_PROTOBUF_COMPILER_CPP_MESSAGE_H__