protobuf 2.2.5-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (256) hide show
  1. data/.gitignore +17 -0
  2. data/.travis.yml +9 -0
  3. data/.yardopts +5 -0
  4. data/Gemfile +3 -0
  5. data/README.md +316 -0
  6. data/Rakefile +29 -0
  7. data/UPGRADING.md +60 -0
  8. data/bin/rpc_server +5 -0
  9. data/bin/rprotoc +62 -0
  10. data/examples/addressbook.pb.rb +55 -0
  11. data/examples/addressbook.proto +24 -0
  12. data/examples/reading_a_message.rb +32 -0
  13. data/examples/writing_a_message.rb +46 -0
  14. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/code_generator.h +142 -0
  15. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/command_line_interface.h +318 -0
  16. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum.h +99 -0
  17. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_enum_field.h +103 -0
  18. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_extension.h +85 -0
  19. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_field.h +167 -0
  20. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_file.h +98 -0
  21. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_generator.h +72 -0
  22. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_helpers.h +159 -0
  23. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message.h +170 -0
  24. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_message_field.h +102 -0
  25. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +103 -0
  26. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_service.h +118 -0
  27. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_string_field.h +104 -0
  28. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.pb.h +2721 -0
  29. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/importer.h +303 -0
  30. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum.h +84 -0
  31. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_enum_field.h +121 -0
  32. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_extension.h +77 -0
  33. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_field.h +108 -0
  34. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_file.h +101 -0
  35. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_generator.h +72 -0
  36. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_helpers.h +213 -0
  37. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message.h +109 -0
  38. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_message_field.h +134 -0
  39. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_primitive_field.h +121 -0
  40. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_service.h +113 -0
  41. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/java/java_string_field.h +120 -0
  42. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/mock_code_generator.h +113 -0
  43. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/package_info.h +64 -0
  44. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/parser.h +434 -0
  45. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.h +73 -0
  46. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/plugin.pb.h +790 -0
  47. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/python/python_generator.h +156 -0
  48. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/subprocess.h +108 -0
  49. data/ext/protobuf-2.4.1/src/google/protobuf/compiler/zip_writer.h +93 -0
  50. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.h +1367 -0
  51. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor.pb.h +5223 -0
  52. data/ext/protobuf-2.4.1/src/google/protobuf/descriptor_database.h +366 -0
  53. data/ext/protobuf-2.4.1/src/google/protobuf/dynamic_message.h +136 -0
  54. data/ext/protobuf-2.4.1/src/google/protobuf/extension_set.h +904 -0
  55. data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_reflection.h +424 -0
  56. data/ext/protobuf-2.4.1/src/google/protobuf/generated_message_util.h +82 -0
  57. data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream.h +1102 -0
  58. data/ext/protobuf-2.4.1/src/google/protobuf/io/coded_stream_inl.h +64 -0
  59. data/ext/protobuf-2.4.1/src/google/protobuf/io/gzip_stream.h +207 -0
  60. data/ext/protobuf-2.4.1/src/google/protobuf/io/package_info.h +54 -0
  61. data/ext/protobuf-2.4.1/src/google/protobuf/io/printer.h +136 -0
  62. data/ext/protobuf-2.4.1/src/google/protobuf/io/tokenizer.h +313 -0
  63. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream.h +238 -0
  64. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl.h +357 -0
  65. data/ext/protobuf-2.4.1/src/google/protobuf/io/zero_copy_stream_impl_lite.h +340 -0
  66. data/ext/protobuf-2.4.1/src/google/protobuf/message.h +692 -0
  67. data/ext/protobuf-2.4.1/src/google/protobuf/message_lite.h +239 -0
  68. data/ext/protobuf-2.4.1/src/google/protobuf/package_info.h +64 -0
  69. data/ext/protobuf-2.4.1/src/google/protobuf/reflection_ops.h +80 -0
  70. data/ext/protobuf-2.4.1/src/google/protobuf/repeated_field.h +1295 -0
  71. data/ext/protobuf-2.4.1/src/google/protobuf/service.h +291 -0
  72. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/common.h +1211 -0
  73. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/hash.h +220 -0
  74. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/map-util.h +119 -0
  75. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/once.h +123 -0
  76. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/stl_util-inl.h +121 -0
  77. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/strutil.h +457 -0
  78. data/ext/protobuf-2.4.1/src/google/protobuf/stubs/substitute.h +170 -0
  79. data/ext/protobuf-2.4.1/src/google/protobuf/test_util.h +174 -0
  80. data/ext/protobuf-2.4.1/src/google/protobuf/test_util_lite.h +101 -0
  81. data/ext/protobuf-2.4.1/src/google/protobuf/testing/file.h +83 -0
  82. data/ext/protobuf-2.4.1/src/google/protobuf/testing/googletest.h +98 -0
  83. data/ext/protobuf-2.4.1/src/google/protobuf/text_format.h +285 -0
  84. data/ext/protobuf-2.4.1/src/google/protobuf/unittest.pb.h +11915 -0
  85. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_custom_options.pb.h +2895 -0
  86. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_embed_optimize_for.pb.h +211 -0
  87. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_empty.pb.h +56 -0
  88. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import.pb.h +188 -0
  89. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_import_lite.pb.h +151 -0
  90. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite.pb.h +4752 -0
  91. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_lite_imports_nonlite.pb.h +150 -0
  92. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_mset.pb.h +816 -0
  93. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_no_generic_services.pb.h +197 -0
  94. data/ext/protobuf-2.4.1/src/google/protobuf/unittest_optimize_for.pb.h +403 -0
  95. data/ext/protobuf-2.4.1/src/google/protobuf/unknown_field_set.h +268 -0
  96. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format.h +304 -0
  97. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite.h +620 -0
  98. data/ext/protobuf-2.4.1/src/google/protobuf/wire_format_lite_inl.h +774 -0
  99. data/ext/ruby_generator/Makefile +10 -0
  100. data/ext/ruby_generator/RubyGenerator.cpp +450 -0
  101. data/ext/ruby_generator/RubyGenerator.h +199 -0
  102. data/ext/ruby_generator/extconf.rb +36 -0
  103. data/ext/ruby_generator/protoc-ruby +0 -0
  104. data/lib/protobuf/cli.rb +188 -0
  105. data/lib/protobuf/enum.rb +58 -0
  106. data/lib/protobuf/enum_value.rb +59 -0
  107. data/lib/protobuf/evented.rb +22 -0
  108. data/lib/protobuf/exceptions.rb +11 -0
  109. data/lib/protobuf/ext/eventmachine.rb +14 -0
  110. data/lib/protobuf/field/base_field.rb +240 -0
  111. data/lib/protobuf/field/bool_field.rb +36 -0
  112. data/lib/protobuf/field/bytes_field.rb +38 -0
  113. data/lib/protobuf/field/double_field.rb +19 -0
  114. data/lib/protobuf/field/enum_field.rb +50 -0
  115. data/lib/protobuf/field/extension_fields.rb +32 -0
  116. data/lib/protobuf/field/field_array.rb +65 -0
  117. data/lib/protobuf/field/fixed32_field.rb +19 -0
  118. data/lib/protobuf/field/fixed64_field.rb +22 -0
  119. data/lib/protobuf/field/float_field.rb +31 -0
  120. data/lib/protobuf/field/int32_field.rb +12 -0
  121. data/lib/protobuf/field/int64_field.rb +12 -0
  122. data/lib/protobuf/field/integer_field.rb +19 -0
  123. data/lib/protobuf/field/message_field.rb +53 -0
  124. data/lib/protobuf/field/sfixed32_field.rb +21 -0
  125. data/lib/protobuf/field/sfixed64_field.rb +24 -0
  126. data/lib/protobuf/field/signed_integer_field.rb +23 -0
  127. data/lib/protobuf/field/sint32_field.rb +12 -0
  128. data/lib/protobuf/field/sint64_field.rb +12 -0
  129. data/lib/protobuf/field/string_field.rb +14 -0
  130. data/lib/protobuf/field/uint32_field.rb +12 -0
  131. data/lib/protobuf/field/uint64_field.rb +12 -0
  132. data/lib/protobuf/field/varint_field.rb +61 -0
  133. data/lib/protobuf/field.rb +57 -0
  134. data/lib/protobuf/logger.rb +86 -0
  135. data/lib/protobuf/message/decoder.rb +83 -0
  136. data/lib/protobuf/message/encoder.rb +48 -0
  137. data/lib/protobuf/message/extend.rb +8 -0
  138. data/lib/protobuf/message/message.rb +1 -0
  139. data/lib/protobuf/message.rb +320 -0
  140. data/lib/protobuf/rpc/buffer.rb +79 -0
  141. data/lib/protobuf/rpc/client.rb +166 -0
  142. data/lib/protobuf/rpc/connector.rb +19 -0
  143. data/lib/protobuf/rpc/connectors/base.rb +38 -0
  144. data/lib/protobuf/rpc/connectors/common.rb +156 -0
  145. data/lib/protobuf/rpc/connectors/em_client.rb +84 -0
  146. data/lib/protobuf/rpc/connectors/eventmachine.rb +87 -0
  147. data/lib/protobuf/rpc/connectors/socket.rb +73 -0
  148. data/lib/protobuf/rpc/connectors/zmq.rb +69 -0
  149. data/lib/protobuf/rpc/error/client_error.rb +31 -0
  150. data/lib/protobuf/rpc/error/server_error.rb +43 -0
  151. data/lib/protobuf/rpc/error.rb +25 -0
  152. data/lib/protobuf/rpc/rpc.pb.rb +118 -0
  153. data/lib/protobuf/rpc/server.rb +89 -0
  154. data/lib/protobuf/rpc/servers/evented/server.rb +41 -0
  155. data/lib/protobuf/rpc/servers/evented_runner.rb +21 -0
  156. data/lib/protobuf/rpc/servers/socket/server.rb +111 -0
  157. data/lib/protobuf/rpc/servers/socket/worker.rb +66 -0
  158. data/lib/protobuf/rpc/servers/socket_runner.rb +27 -0
  159. data/lib/protobuf/rpc/servers/zmq/broker.rb +87 -0
  160. data/lib/protobuf/rpc/servers/zmq/server.rb +50 -0
  161. data/lib/protobuf/rpc/servers/zmq/util.rb +27 -0
  162. data/lib/protobuf/rpc/servers/zmq/worker.rb +60 -0
  163. data/lib/protobuf/rpc/servers/zmq_runner.rb +25 -0
  164. data/lib/protobuf/rpc/service.rb +173 -0
  165. data/lib/protobuf/rpc/service_dispatcher.rb +130 -0
  166. data/lib/protobuf/rpc/service_filters.rb +267 -0
  167. data/lib/protobuf/rpc/stat.rb +83 -0
  168. data/lib/protobuf/socket.rb +22 -0
  169. data/lib/protobuf/version.rb +4 -0
  170. data/lib/protobuf/wire_type.rb +10 -0
  171. data/lib/protobuf/zmq.rb +21 -0
  172. data/lib/protobuf.rb +86 -0
  173. data/proto/rpc.pb.rb +48 -0
  174. data/proto/rpc.proto +73 -0
  175. data/protobuf.gemspec +44 -0
  176. data/spec/benchmark/tasks.rb +179 -0
  177. data/spec/functional/embedded_service_spec.rb +7 -0
  178. data/spec/functional/evented_server_spec.rb +64 -0
  179. data/spec/functional/socket_server_spec.rb +58 -0
  180. data/spec/functional/zmq_server_spec.rb +58 -0
  181. data/spec/lib/protobuf/cli_spec.rb +212 -0
  182. data/spec/lib/protobuf/enum_spec.rb +98 -0
  183. data/spec/lib/protobuf/enum_value_spec.rb +15 -0
  184. data/spec/lib/protobuf/logger_spec.rb +131 -0
  185. data/spec/lib/protobuf/message/encoder_spec.rb +19 -0
  186. data/spec/lib/protobuf/message_spec.rb +209 -0
  187. data/spec/lib/protobuf/rpc/client_spec.rb +158 -0
  188. data/spec/lib/protobuf/rpc/connector_spec.rb +32 -0
  189. data/spec/lib/protobuf/rpc/connectors/base_spec.rb +50 -0
  190. data/spec/lib/protobuf/rpc/connectors/common_spec.rb +128 -0
  191. data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +36 -0
  192. data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +22 -0
  193. data/spec/lib/protobuf/rpc/servers/evented_server_spec.rb +18 -0
  194. data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +43 -0
  195. data/spec/lib/protobuf/rpc/servers/zmq/broker_spec.rb +35 -0
  196. data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +41 -0
  197. data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +45 -0
  198. data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +44 -0
  199. data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +116 -0
  200. data/spec/lib/protobuf/rpc/service_filters_spec.rb +451 -0
  201. data/spec/lib/protobuf/rpc/service_spec.rb +165 -0
  202. data/spec/lib/protobuf_spec.rb +62 -0
  203. data/spec/spec_helper.rb +51 -0
  204. data/spec/support/all.rb +6 -0
  205. data/spec/support/server.rb +101 -0
  206. data/spec/support/test/enum.pb.rb +34 -0
  207. data/spec/support/test/enum.proto +12 -0
  208. data/spec/support/test/resource.pb.rb +58 -0
  209. data/spec/support/test/resource.proto +31 -0
  210. data/spec/support/test/resource_service.rb +14 -0
  211. data/spec/support/test_app_file.rb +2 -0
  212. data/spec/support/tolerance_matcher.rb +40 -0
  213. data/test/data/data.bin +3 -0
  214. data/test/data/data_source.py +14 -0
  215. data/test/data/types.bin +0 -0
  216. data/test/data/types_source.py +22 -0
  217. data/test/data/unk.png +0 -0
  218. data/test/proto/addressbook.pb.rb +66 -0
  219. data/test/proto/addressbook.proto +33 -0
  220. data/test/proto/addressbook_base.pb.rb +58 -0
  221. data/test/proto/addressbook_base.proto +26 -0
  222. data/test/proto/addressbook_ext.pb.rb +20 -0
  223. data/test/proto/addressbook_ext.proto +6 -0
  224. data/test/proto/collision.pb.rb +17 -0
  225. data/test/proto/collision.proto +5 -0
  226. data/test/proto/ext_collision.pb.rb +24 -0
  227. data/test/proto/ext_collision.proto +8 -0
  228. data/test/proto/ext_range.pb.rb +22 -0
  229. data/test/proto/ext_range.proto +7 -0
  230. data/test/proto/float_default.proto +10 -0
  231. data/test/proto/lowercase.pb.rb +30 -0
  232. data/test/proto/lowercase.proto +9 -0
  233. data/test/proto/merge.pb.rb +39 -0
  234. data/test/proto/merge.proto +15 -0
  235. data/test/proto/nested.pb.rb +30 -0
  236. data/test/proto/nested.proto +9 -0
  237. data/test/proto/optional_field.pb.rb +35 -0
  238. data/test/proto/optional_field.proto +12 -0
  239. data/test/proto/packed.pb.rb +22 -0
  240. data/test/proto/packed.proto +6 -0
  241. data/test/proto/rpc.proto +6 -0
  242. data/test/proto/types.pb.rb +84 -0
  243. data/test/proto/types.proto +37 -0
  244. data/test/test_addressbook.rb +56 -0
  245. data/test/test_enum_value.rb +41 -0
  246. data/test/test_extension.rb +36 -0
  247. data/test/test_lowercase.rb +11 -0
  248. data/test/test_message.rb +128 -0
  249. data/test/test_optional_field.rb +103 -0
  250. data/test/test_packed_field.rb +40 -0
  251. data/test/test_parse.rb +15 -0
  252. data/test/test_repeated_types.rb +132 -0
  253. data/test/test_serialize.rb +61 -0
  254. data/test/test_standard_message.rb +96 -0
  255. data/test/test_types.rb +226 -0
  256. metadata +461 -0
@@ -0,0 +1,1211 @@
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) and others
32
+ //
33
+ // Contains basic types and utilities used by the rest of the library.
34
+
35
+ #ifndef GOOGLE_PROTOBUF_COMMON_H__
36
+ #define GOOGLE_PROTOBUF_COMMON_H__
37
+
38
+ #include <assert.h>
39
+ #include <stdlib.h>
40
+ #include <cstddef>
41
+ #include <string>
42
+ #include <string.h>
43
+ #if defined(__osf__)
44
+ // Tru64 lacks stdint.h, but has inttypes.h which defines a superset of
45
+ // what stdint.h would define.
46
+ #include <inttypes.h>
47
+ #elif !defined(_MSC_VER)
48
+ #include <stdint.h>
49
+ #endif
50
+
51
+ #if defined(_MSC_VER) && defined(_CPPUNWIND)
52
+ #define PROTOBUF_USE_EXCEPTIONS
53
+ #elif defined(__EXCEPTIONS)
54
+ #define PROTOBUF_USE_EXCEPTIONS
55
+ #endif
56
+ #ifdef PROTOBUF_USE_EXCEPTIONS
57
+ #include <exception>
58
+ #endif
59
+
60
+ #if defined(_WIN32) && defined(GetMessage)
61
+ // Allow GetMessage to be used as a valid method name in protobuf classes.
62
+ // windows.h defines GetMessage() as a macro. Let's re-define it as an inline
63
+ // function. The inline function should be equivalent for C++ users.
64
+ inline BOOL GetMessage_Win32(
65
+ LPMSG lpMsg, HWND hWnd,
66
+ UINT wMsgFilterMin, UINT wMsgFilterMax) {
67
+ return GetMessage(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
68
+ }
69
+ #undef GetMessage
70
+ inline BOOL GetMessage(
71
+ LPMSG lpMsg, HWND hWnd,
72
+ UINT wMsgFilterMin, UINT wMsgFilterMax) {
73
+ return GetMessage_Win32(lpMsg, hWnd, wMsgFilterMin, wMsgFilterMax);
74
+ }
75
+ #endif
76
+
77
+
78
+ namespace std {}
79
+
80
+ namespace google {
81
+ namespace protobuf {
82
+
83
+ #undef GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
84
+ #define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName) \
85
+ TypeName(const TypeName&); \
86
+ void operator=(const TypeName&)
87
+
88
+ #if defined(_MSC_VER) && defined(PROTOBUF_USE_DLLS)
89
+ #ifdef LIBPROTOBUF_EXPORTS
90
+ #define LIBPROTOBUF_EXPORT __declspec(dllexport)
91
+ #else
92
+ #define LIBPROTOBUF_EXPORT __declspec(dllimport)
93
+ #endif
94
+ #ifdef LIBPROTOC_EXPORTS
95
+ #define LIBPROTOC_EXPORT __declspec(dllexport)
96
+ #else
97
+ #define LIBPROTOC_EXPORT __declspec(dllimport)
98
+ #endif
99
+ #else
100
+ #define LIBPROTOBUF_EXPORT
101
+ #define LIBPROTOC_EXPORT
102
+ #endif
103
+
104
+ namespace internal {
105
+
106
+ // Some of these constants are macros rather than const ints so that they can
107
+ // be used in #if directives.
108
+
109
+ // The current version, represented as a single integer to make comparison
110
+ // easier: major * 10^6 + minor * 10^3 + micro
111
+ #define GOOGLE_PROTOBUF_VERSION 2004001
112
+
113
+ // The minimum library version which works with the current version of the
114
+ // headers.
115
+ #define GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION 2004000
116
+
117
+ // The minimum header version which works with the current version of
118
+ // the library. This constant should only be used by protoc's C++ code
119
+ // generator.
120
+ static const int kMinHeaderVersionForLibrary = 2004000;
121
+
122
+ // The minimum protoc version which works with the current version of the
123
+ // headers.
124
+ #define GOOGLE_PROTOBUF_MIN_PROTOC_VERSION 2004000
125
+
126
+ // The minimum header version which works with the current version of
127
+ // protoc. This constant should only be used in VerifyVersion().
128
+ static const int kMinHeaderVersionForProtoc = 2004000;
129
+
130
+ // Verifies that the headers and libraries are compatible. Use the macro
131
+ // below to call this.
132
+ void LIBPROTOBUF_EXPORT VerifyVersion(int headerVersion, int minLibraryVersion,
133
+ const char* filename);
134
+
135
+ // Converts a numeric version number to a string.
136
+ std::string LIBPROTOBUF_EXPORT VersionString(int version);
137
+
138
+ } // namespace internal
139
+
140
+ // Place this macro in your main() function (or somewhere before you attempt
141
+ // to use the protobuf library) to verify that the version you link against
142
+ // matches the headers you compiled against. If a version mismatch is
143
+ // detected, the process will abort.
144
+ #define GOOGLE_PROTOBUF_VERIFY_VERSION \
145
+ ::google::protobuf::internal::VerifyVersion( \
146
+ GOOGLE_PROTOBUF_VERSION, GOOGLE_PROTOBUF_MIN_LIBRARY_VERSION, \
147
+ __FILE__)
148
+
149
+ // ===================================================================
150
+ // from google3/base/port.h
151
+
152
+ typedef unsigned int uint;
153
+
154
+ #ifdef _MSC_VER
155
+ typedef __int8 int8;
156
+ typedef __int16 int16;
157
+ typedef __int32 int32;
158
+ typedef __int64 int64;
159
+
160
+ typedef unsigned __int8 uint8;
161
+ typedef unsigned __int16 uint16;
162
+ typedef unsigned __int32 uint32;
163
+ typedef unsigned __int64 uint64;
164
+ #else
165
+ typedef int8_t int8;
166
+ typedef int16_t int16;
167
+ typedef int32_t int32;
168
+ typedef int64_t int64;
169
+
170
+ typedef uint8_t uint8;
171
+ typedef uint16_t uint16;
172
+ typedef uint32_t uint32;
173
+ typedef uint64_t uint64;
174
+ #endif
175
+
176
+ // long long macros to be used because gcc and vc++ use different suffixes,
177
+ // and different size specifiers in format strings
178
+ #undef GOOGLE_LONGLONG
179
+ #undef GOOGLE_ULONGLONG
180
+ #undef GOOGLE_LL_FORMAT
181
+
182
+ #ifdef _MSC_VER
183
+ #define GOOGLE_LONGLONG(x) x##I64
184
+ #define GOOGLE_ULONGLONG(x) x##UI64
185
+ #define GOOGLE_LL_FORMAT "I64" // As in printf("%I64d", ...)
186
+ #else
187
+ #define GOOGLE_LONGLONG(x) x##LL
188
+ #define GOOGLE_ULONGLONG(x) x##ULL
189
+ #define GOOGLE_LL_FORMAT "ll" // As in "%lld". Note that "q" is poor form also.
190
+ #endif
191
+
192
+ static const int32 kint32max = 0x7FFFFFFF;
193
+ static const int32 kint32min = -kint32max - 1;
194
+ static const int64 kint64max = GOOGLE_LONGLONG(0x7FFFFFFFFFFFFFFF);
195
+ static const int64 kint64min = -kint64max - 1;
196
+ static const uint32 kuint32max = 0xFFFFFFFFu;
197
+ static const uint64 kuint64max = GOOGLE_ULONGLONG(0xFFFFFFFFFFFFFFFF);
198
+
199
+ // -------------------------------------------------------------------
200
+ // Annotations: Some parts of the code have been annotated in ways that might
201
+ // be useful to some compilers or tools, but are not supported universally.
202
+ // You can #define these annotations yourself if the default implementation
203
+ // is not right for you.
204
+
205
+ #ifndef GOOGLE_ATTRIBUTE_ALWAYS_INLINE
206
+ #if defined(__GNUC__) && (__GNUC__ > 3 ||(__GNUC__ == 3 && __GNUC_MINOR__ >= 1))
207
+ // For functions we want to force inline.
208
+ // Introduced in gcc 3.1.
209
+ #define GOOGLE_ATTRIBUTE_ALWAYS_INLINE __attribute__ ((always_inline))
210
+ #else
211
+ // Other compilers will have to figure it out for themselves.
212
+ #define GOOGLE_ATTRIBUTE_ALWAYS_INLINE
213
+ #endif
214
+ #endif
215
+
216
+ #ifndef GOOGLE_ATTRIBUTE_DEPRECATED
217
+ #ifdef __GNUC__
218
+ // If the method/variable/type is used anywhere, produce a warning.
219
+ #define GOOGLE_ATTRIBUTE_DEPRECATED __attribute__((deprecated))
220
+ #else
221
+ #define GOOGLE_ATTRIBUTE_DEPRECATED
222
+ #endif
223
+ #endif
224
+
225
+ #ifndef GOOGLE_PREDICT_TRUE
226
+ #ifdef __GNUC__
227
+ // Provided at least since GCC 3.0.
228
+ #define GOOGLE_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
229
+ #else
230
+ #define GOOGLE_PREDICT_TRUE
231
+ #endif
232
+ #endif
233
+
234
+ // Delimits a block of code which may write to memory which is simultaneously
235
+ // written by other threads, but which has been determined to be thread-safe
236
+ // (e.g. because it is an idempotent write).
237
+ #ifndef GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN
238
+ #define GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN()
239
+ #endif
240
+ #ifndef GOOGLE_SAFE_CONCURRENT_WRITES_END
241
+ #define GOOGLE_SAFE_CONCURRENT_WRITES_END()
242
+ #endif
243
+
244
+ // ===================================================================
245
+ // from google3/base/basictypes.h
246
+
247
+ // The GOOGLE_ARRAYSIZE(arr) macro returns the # of elements in an array arr.
248
+ // The expression is a compile-time constant, and therefore can be
249
+ // used in defining new arrays, for example.
250
+ //
251
+ // GOOGLE_ARRAYSIZE catches a few type errors. If you see a compiler error
252
+ //
253
+ // "warning: division by zero in ..."
254
+ //
255
+ // when using GOOGLE_ARRAYSIZE, you are (wrongfully) giving it a pointer.
256
+ // You should only use GOOGLE_ARRAYSIZE on statically allocated arrays.
257
+ //
258
+ // The following comments are on the implementation details, and can
259
+ // be ignored by the users.
260
+ //
261
+ // ARRAYSIZE(arr) works by inspecting sizeof(arr) (the # of bytes in
262
+ // the array) and sizeof(*(arr)) (the # of bytes in one array
263
+ // element). If the former is divisible by the latter, perhaps arr is
264
+ // indeed an array, in which case the division result is the # of
265
+ // elements in the array. Otherwise, arr cannot possibly be an array,
266
+ // and we generate a compiler error to prevent the code from
267
+ // compiling.
268
+ //
269
+ // Since the size of bool is implementation-defined, we need to cast
270
+ // !(sizeof(a) & sizeof(*(a))) to size_t in order to ensure the final
271
+ // result has type size_t.
272
+ //
273
+ // This macro is not perfect as it wrongfully accepts certain
274
+ // pointers, namely where the pointer size is divisible by the pointee
275
+ // size. Since all our code has to go through a 32-bit compiler,
276
+ // where a pointer is 4 bytes, this means all pointers to a type whose
277
+ // size is 3 or greater than 4 will be (righteously) rejected.
278
+ //
279
+ // Kudos to Jorg Brown for this simple and elegant implementation.
280
+
281
+ #undef GOOGLE_ARRAYSIZE
282
+ #define GOOGLE_ARRAYSIZE(a) \
283
+ ((sizeof(a) / sizeof(*(a))) / \
284
+ static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
285
+
286
+ namespace internal {
287
+
288
+ // Use implicit_cast as a safe version of static_cast or const_cast
289
+ // for upcasting in the type hierarchy (i.e. casting a pointer to Foo
290
+ // to a pointer to SuperclassOfFoo or casting a pointer to Foo to
291
+ // a const pointer to Foo).
292
+ // When you use implicit_cast, the compiler checks that the cast is safe.
293
+ // Such explicit implicit_casts are necessary in surprisingly many
294
+ // situations where C++ demands an exact type match instead of an
295
+ // argument type convertable to a target type.
296
+ //
297
+ // The From type can be inferred, so the preferred syntax for using
298
+ // implicit_cast is the same as for static_cast etc.:
299
+ //
300
+ // implicit_cast<ToType>(expr)
301
+ //
302
+ // implicit_cast would have been part of the C++ standard library,
303
+ // but the proposal was submitted too late. It will probably make
304
+ // its way into the language in the future.
305
+ template<typename To, typename From>
306
+ inline To implicit_cast(From const &f) {
307
+ return f;
308
+ }
309
+
310
+ // When you upcast (that is, cast a pointer from type Foo to type
311
+ // SuperclassOfFoo), it's fine to use implicit_cast<>, since upcasts
312
+ // always succeed. When you downcast (that is, cast a pointer from
313
+ // type Foo to type SubclassOfFoo), static_cast<> isn't safe, because
314
+ // how do you know the pointer is really of type SubclassOfFoo? It
315
+ // could be a bare Foo, or of type DifferentSubclassOfFoo. Thus,
316
+ // when you downcast, you should use this macro. In debug mode, we
317
+ // use dynamic_cast<> to double-check the downcast is legal (we die
318
+ // if it's not). In normal mode, we do the efficient static_cast<>
319
+ // instead. Thus, it's important to test in debug mode to make sure
320
+ // the cast is legal!
321
+ // This is the only place in the code we should use dynamic_cast<>.
322
+ // In particular, you SHOULDN'T be using dynamic_cast<> in order to
323
+ // do RTTI (eg code like this:
324
+ // if (dynamic_cast<Subclass1>(foo)) HandleASubclass1Object(foo);
325
+ // if (dynamic_cast<Subclass2>(foo)) HandleASubclass2Object(foo);
326
+ // You should design the code some other way not to need this.
327
+
328
+ template<typename To, typename From> // use like this: down_cast<T*>(foo);
329
+ inline To down_cast(From* f) { // so we only accept pointers
330
+ // Ensures that To is a sub-type of From *. This test is here only
331
+ // for compile-time type checking, and has no overhead in an
332
+ // optimized build at run-time, as it will be optimized away
333
+ // completely.
334
+ if (false) {
335
+ implicit_cast<From*, To>(0);
336
+ }
337
+
338
+ #if !defined(NDEBUG) && !defined(GOOGLE_PROTOBUF_NO_RTTI)
339
+ assert(f == NULL || dynamic_cast<To>(f) != NULL); // RTTI: debug mode only!
340
+ #endif
341
+ return static_cast<To>(f);
342
+ }
343
+
344
+ } // namespace internal
345
+
346
+ // We made these internal so that they would show up as such in the docs,
347
+ // but we don't want to stick "internal::" in front of them everywhere.
348
+ using internal::implicit_cast;
349
+ using internal::down_cast;
350
+
351
+ // The COMPILE_ASSERT macro can be used to verify that a compile time
352
+ // expression is true. For example, you could use it to verify the
353
+ // size of a static array:
354
+ //
355
+ // COMPILE_ASSERT(ARRAYSIZE(content_type_names) == CONTENT_NUM_TYPES,
356
+ // content_type_names_incorrect_size);
357
+ //
358
+ // or to make sure a struct is smaller than a certain size:
359
+ //
360
+ // COMPILE_ASSERT(sizeof(foo) < 128, foo_too_large);
361
+ //
362
+ // The second argument to the macro is the name of the variable. If
363
+ // the expression is false, most compilers will issue a warning/error
364
+ // containing the name of the variable.
365
+
366
+ namespace internal {
367
+
368
+ template <bool>
369
+ struct CompileAssert {
370
+ };
371
+
372
+ } // namespace internal
373
+
374
+ #undef GOOGLE_COMPILE_ASSERT
375
+ #define GOOGLE_COMPILE_ASSERT(expr, msg) \
376
+ typedef ::google::protobuf::internal::CompileAssert<(bool(expr))> \
377
+ msg[bool(expr) ? 1 : -1]
378
+
379
+
380
+ // Implementation details of COMPILE_ASSERT:
381
+ //
382
+ // - COMPILE_ASSERT works by defining an array type that has -1
383
+ // elements (and thus is invalid) when the expression is false.
384
+ //
385
+ // - The simpler definition
386
+ //
387
+ // #define COMPILE_ASSERT(expr, msg) typedef char msg[(expr) ? 1 : -1]
388
+ //
389
+ // does not work, as gcc supports variable-length arrays whose sizes
390
+ // are determined at run-time (this is gcc's extension and not part
391
+ // of the C++ standard). As a result, gcc fails to reject the
392
+ // following code with the simple definition:
393
+ //
394
+ // int foo;
395
+ // COMPILE_ASSERT(foo, msg); // not supposed to compile as foo is
396
+ // // not a compile-time constant.
397
+ //
398
+ // - By using the type CompileAssert<(bool(expr))>, we ensures that
399
+ // expr is a compile-time constant. (Template arguments must be
400
+ // determined at compile-time.)
401
+ //
402
+ // - The outter parentheses in CompileAssert<(bool(expr))> are necessary
403
+ // to work around a bug in gcc 3.4.4 and 4.0.1. If we had written
404
+ //
405
+ // CompileAssert<bool(expr)>
406
+ //
407
+ // instead, these compilers will refuse to compile
408
+ //
409
+ // COMPILE_ASSERT(5 > 0, some_message);
410
+ //
411
+ // (They seem to think the ">" in "5 > 0" marks the end of the
412
+ // template argument list.)
413
+ //
414
+ // - The array size is (bool(expr) ? 1 : -1), instead of simply
415
+ //
416
+ // ((expr) ? 1 : -1).
417
+ //
418
+ // This is to avoid running into a bug in MS VC 7.1, which
419
+ // causes ((0.0) ? 1 : -1) to incorrectly evaluate to 1.
420
+
421
+ // ===================================================================
422
+ // from google3/base/scoped_ptr.h
423
+
424
+ namespace internal {
425
+
426
+ // This is an implementation designed to match the anticipated future TR2
427
+ // implementation of the scoped_ptr class, and its closely-related brethren,
428
+ // scoped_array, scoped_ptr_malloc, and make_scoped_ptr.
429
+
430
+ template <class C> class scoped_ptr;
431
+ template <class C> class scoped_array;
432
+
433
+ // A scoped_ptr<T> is like a T*, except that the destructor of scoped_ptr<T>
434
+ // automatically deletes the pointer it holds (if any).
435
+ // That is, scoped_ptr<T> owns the T object that it points to.
436
+ // Like a T*, a scoped_ptr<T> may hold either NULL or a pointer to a T object.
437
+ //
438
+ // The size of a scoped_ptr is small:
439
+ // sizeof(scoped_ptr<C>) == sizeof(C*)
440
+ template <class C>
441
+ class scoped_ptr {
442
+ public:
443
+
444
+ // The element type
445
+ typedef C element_type;
446
+
447
+ // Constructor. Defaults to intializing with NULL.
448
+ // There is no way to create an uninitialized scoped_ptr.
449
+ // The input parameter must be allocated with new.
450
+ explicit scoped_ptr(C* p = NULL) : ptr_(p) { }
451
+
452
+ // Destructor. If there is a C object, delete it.
453
+ // We don't need to test ptr_ == NULL because C++ does that for us.
454
+ ~scoped_ptr() {
455
+ enum { type_must_be_complete = sizeof(C) };
456
+ delete ptr_;
457
+ }
458
+
459
+ // Reset. Deletes the current owned object, if any.
460
+ // Then takes ownership of a new object, if given.
461
+ // this->reset(this->get()) works.
462
+ void reset(C* p = NULL) {
463
+ if (p != ptr_) {
464
+ enum { type_must_be_complete = sizeof(C) };
465
+ delete ptr_;
466
+ ptr_ = p;
467
+ }
468
+ }
469
+
470
+ // Accessors to get the owned object.
471
+ // operator* and operator-> will assert() if there is no current object.
472
+ C& operator*() const {
473
+ assert(ptr_ != NULL);
474
+ return *ptr_;
475
+ }
476
+ C* operator->() const {
477
+ assert(ptr_ != NULL);
478
+ return ptr_;
479
+ }
480
+ C* get() const { return ptr_; }
481
+
482
+ // Comparison operators.
483
+ // These return whether two scoped_ptr refer to the same object, not just to
484
+ // two different but equal objects.
485
+ bool operator==(C* p) const { return ptr_ == p; }
486
+ bool operator!=(C* p) const { return ptr_ != p; }
487
+
488
+ // Swap two scoped pointers.
489
+ void swap(scoped_ptr& p2) {
490
+ C* tmp = ptr_;
491
+ ptr_ = p2.ptr_;
492
+ p2.ptr_ = tmp;
493
+ }
494
+
495
+ // Release a pointer.
496
+ // The return value is the current pointer held by this object.
497
+ // If this object holds a NULL pointer, the return value is NULL.
498
+ // After this operation, this object will hold a NULL pointer,
499
+ // and will not own the object any more.
500
+ C* release() {
501
+ C* retVal = ptr_;
502
+ ptr_ = NULL;
503
+ return retVal;
504
+ }
505
+
506
+ private:
507
+ C* ptr_;
508
+
509
+ // Forbid comparison of scoped_ptr types. If C2 != C, it totally doesn't
510
+ // make sense, and if C2 == C, it still doesn't make sense because you should
511
+ // never have the same object owned by two different scoped_ptrs.
512
+ template <class C2> bool operator==(scoped_ptr<C2> const& p2) const;
513
+ template <class C2> bool operator!=(scoped_ptr<C2> const& p2) const;
514
+
515
+ // Disallow evil constructors
516
+ scoped_ptr(const scoped_ptr&);
517
+ void operator=(const scoped_ptr&);
518
+ };
519
+
520
+ // scoped_array<C> is like scoped_ptr<C>, except that the caller must allocate
521
+ // with new [] and the destructor deletes objects with delete [].
522
+ //
523
+ // As with scoped_ptr<C>, a scoped_array<C> either points to an object
524
+ // or is NULL. A scoped_array<C> owns the object that it points to.
525
+ //
526
+ // Size: sizeof(scoped_array<C>) == sizeof(C*)
527
+ template <class C>
528
+ class scoped_array {
529
+ public:
530
+
531
+ // The element type
532
+ typedef C element_type;
533
+
534
+ // Constructor. Defaults to intializing with NULL.
535
+ // There is no way to create an uninitialized scoped_array.
536
+ // The input parameter must be allocated with new [].
537
+ explicit scoped_array(C* p = NULL) : array_(p) { }
538
+
539
+ // Destructor. If there is a C object, delete it.
540
+ // We don't need to test ptr_ == NULL because C++ does that for us.
541
+ ~scoped_array() {
542
+ enum { type_must_be_complete = sizeof(C) };
543
+ delete[] array_;
544
+ }
545
+
546
+ // Reset. Deletes the current owned object, if any.
547
+ // Then takes ownership of a new object, if given.
548
+ // this->reset(this->get()) works.
549
+ void reset(C* p = NULL) {
550
+ if (p != array_) {
551
+ enum { type_must_be_complete = sizeof(C) };
552
+ delete[] array_;
553
+ array_ = p;
554
+ }
555
+ }
556
+
557
+ // Get one element of the current object.
558
+ // Will assert() if there is no current object, or index i is negative.
559
+ C& operator[](std::ptrdiff_t i) const {
560
+ assert(i >= 0);
561
+ assert(array_ != NULL);
562
+ return array_[i];
563
+ }
564
+
565
+ // Get a pointer to the zeroth element of the current object.
566
+ // If there is no current object, return NULL.
567
+ C* get() const {
568
+ return array_;
569
+ }
570
+
571
+ // Comparison operators.
572
+ // These return whether two scoped_array refer to the same object, not just to
573
+ // two different but equal objects.
574
+ bool operator==(C* p) const { return array_ == p; }
575
+ bool operator!=(C* p) const { return array_ != p; }
576
+
577
+ // Swap two scoped arrays.
578
+ void swap(scoped_array& p2) {
579
+ C* tmp = array_;
580
+ array_ = p2.array_;
581
+ p2.array_ = tmp;
582
+ }
583
+
584
+ // Release an array.
585
+ // The return value is the current pointer held by this object.
586
+ // If this object holds a NULL pointer, the return value is NULL.
587
+ // After this operation, this object will hold a NULL pointer,
588
+ // and will not own the object any more.
589
+ C* release() {
590
+ C* retVal = array_;
591
+ array_ = NULL;
592
+ return retVal;
593
+ }
594
+
595
+ private:
596
+ C* array_;
597
+
598
+ // Forbid comparison of different scoped_array types.
599
+ template <class C2> bool operator==(scoped_array<C2> const& p2) const;
600
+ template <class C2> bool operator!=(scoped_array<C2> const& p2) const;
601
+
602
+ // Disallow evil constructors
603
+ scoped_array(const scoped_array&);
604
+ void operator=(const scoped_array&);
605
+ };
606
+
607
+ } // namespace internal
608
+
609
+ // We made these internal so that they would show up as such in the docs,
610
+ // but we don't want to stick "internal::" in front of them everywhere.
611
+ using internal::scoped_ptr;
612
+ using internal::scoped_array;
613
+
614
+ // ===================================================================
615
+ // emulates google3/base/logging.h
616
+
617
+ enum LogLevel {
618
+ LOGLEVEL_INFO, // Informational. This is never actually used by
619
+ // libprotobuf.
620
+ LOGLEVEL_WARNING, // Warns about issues that, although not technically a
621
+ // problem now, could cause problems in the future. For
622
+ // example, a // warning will be printed when parsing a
623
+ // message that is near the message size limit.
624
+ LOGLEVEL_ERROR, // An error occurred which should never happen during
625
+ // normal use.
626
+ LOGLEVEL_FATAL, // An error occurred from which the library cannot
627
+ // recover. This usually indicates a programming error
628
+ // in the code which calls the library, especially when
629
+ // compiled in debug mode.
630
+
631
+ #ifdef NDEBUG
632
+ LOGLEVEL_DFATAL = LOGLEVEL_ERROR
633
+ #else
634
+ LOGLEVEL_DFATAL = LOGLEVEL_FATAL
635
+ #endif
636
+ };
637
+
638
+ namespace internal {
639
+
640
+ class LogFinisher;
641
+
642
+ class LIBPROTOBUF_EXPORT LogMessage {
643
+ public:
644
+ LogMessage(LogLevel level, const char* filename, int line);
645
+ ~LogMessage();
646
+
647
+ LogMessage& operator<<(const std::string& value);
648
+ LogMessage& operator<<(const char* value);
649
+ LogMessage& operator<<(char value);
650
+ LogMessage& operator<<(int value);
651
+ LogMessage& operator<<(uint value);
652
+ LogMessage& operator<<(long value);
653
+ LogMessage& operator<<(unsigned long value);
654
+ LogMessage& operator<<(double value);
655
+
656
+ private:
657
+ friend class LogFinisher;
658
+ void Finish();
659
+
660
+ LogLevel level_;
661
+ const char* filename_;
662
+ int line_;
663
+ std::string message_;
664
+ };
665
+
666
+ // Used to make the entire "LOG(BLAH) << etc." expression have a void return
667
+ // type and print a newline after each message.
668
+ class LIBPROTOBUF_EXPORT LogFinisher {
669
+ public:
670
+ void operator=(LogMessage& other);
671
+ };
672
+
673
+ } // namespace internal
674
+
675
+ // Undef everything in case we're being mixed with some other Google library
676
+ // which already defined them itself. Presumably all Google libraries will
677
+ // support the same syntax for these so it should not be a big deal if they
678
+ // end up using our definitions instead.
679
+ #undef GOOGLE_LOG
680
+ #undef GOOGLE_LOG_IF
681
+
682
+ #undef GOOGLE_CHECK
683
+ #undef GOOGLE_CHECK_EQ
684
+ #undef GOOGLE_CHECK_NE
685
+ #undef GOOGLE_CHECK_LT
686
+ #undef GOOGLE_CHECK_LE
687
+ #undef GOOGLE_CHECK_GT
688
+ #undef GOOGLE_CHECK_GE
689
+
690
+ #undef GOOGLE_DLOG
691
+ #undef GOOGLE_DCHECK
692
+ #undef GOOGLE_DCHECK_EQ
693
+ #undef GOOGLE_DCHECK_NE
694
+ #undef GOOGLE_DCHECK_LT
695
+ #undef GOOGLE_DCHECK_LE
696
+ #undef GOOGLE_DCHECK_GT
697
+ #undef GOOGLE_DCHECK_GE
698
+
699
+ #define GOOGLE_LOG(LEVEL) \
700
+ ::google::protobuf::internal::LogFinisher() = \
701
+ ::google::protobuf::internal::LogMessage( \
702
+ ::google::protobuf::LOGLEVEL_##LEVEL, __FILE__, __LINE__)
703
+ #define GOOGLE_LOG_IF(LEVEL, CONDITION) \
704
+ !(CONDITION) ? (void)0 : GOOGLE_LOG(LEVEL)
705
+
706
+ #define GOOGLE_CHECK(EXPRESSION) \
707
+ GOOGLE_LOG_IF(FATAL, !(EXPRESSION)) << "CHECK failed: " #EXPRESSION ": "
708
+ #define GOOGLE_CHECK_EQ(A, B) GOOGLE_CHECK((A) == (B))
709
+ #define GOOGLE_CHECK_NE(A, B) GOOGLE_CHECK((A) != (B))
710
+ #define GOOGLE_CHECK_LT(A, B) GOOGLE_CHECK((A) < (B))
711
+ #define GOOGLE_CHECK_LE(A, B) GOOGLE_CHECK((A) <= (B))
712
+ #define GOOGLE_CHECK_GT(A, B) GOOGLE_CHECK((A) > (B))
713
+ #define GOOGLE_CHECK_GE(A, B) GOOGLE_CHECK((A) >= (B))
714
+
715
+ #ifdef NDEBUG
716
+
717
+ #define GOOGLE_DLOG GOOGLE_LOG_IF(INFO, false)
718
+
719
+ #define GOOGLE_DCHECK(EXPRESSION) while(false) GOOGLE_CHECK(EXPRESSION)
720
+ #define GOOGLE_DCHECK_EQ(A, B) GOOGLE_DCHECK((A) == (B))
721
+ #define GOOGLE_DCHECK_NE(A, B) GOOGLE_DCHECK((A) != (B))
722
+ #define GOOGLE_DCHECK_LT(A, B) GOOGLE_DCHECK((A) < (B))
723
+ #define GOOGLE_DCHECK_LE(A, B) GOOGLE_DCHECK((A) <= (B))
724
+ #define GOOGLE_DCHECK_GT(A, B) GOOGLE_DCHECK((A) > (B))
725
+ #define GOOGLE_DCHECK_GE(A, B) GOOGLE_DCHECK((A) >= (B))
726
+
727
+ #else // NDEBUG
728
+
729
+ #define GOOGLE_DLOG GOOGLE_LOG
730
+
731
+ #define GOOGLE_DCHECK GOOGLE_CHECK
732
+ #define GOOGLE_DCHECK_EQ GOOGLE_CHECK_EQ
733
+ #define GOOGLE_DCHECK_NE GOOGLE_CHECK_NE
734
+ #define GOOGLE_DCHECK_LT GOOGLE_CHECK_LT
735
+ #define GOOGLE_DCHECK_LE GOOGLE_CHECK_LE
736
+ #define GOOGLE_DCHECK_GT GOOGLE_CHECK_GT
737
+ #define GOOGLE_DCHECK_GE GOOGLE_CHECK_GE
738
+
739
+ #endif // !NDEBUG
740
+
741
+ typedef void LogHandler(LogLevel level, const char* filename, int line,
742
+ const std::string& message);
743
+
744
+ // The protobuf library sometimes writes warning and error messages to
745
+ // stderr. These messages are primarily useful for developers, but may
746
+ // also help end users figure out a problem. If you would prefer that
747
+ // these messages be sent somewhere other than stderr, call SetLogHandler()
748
+ // to set your own handler. This returns the old handler. Set the handler
749
+ // to NULL to ignore log messages (but see also LogSilencer, below).
750
+ //
751
+ // Obviously, SetLogHandler is not thread-safe. You should only call it
752
+ // at initialization time, and probably not from library code. If you
753
+ // simply want to suppress log messages temporarily (e.g. because you
754
+ // have some code that tends to trigger them frequently and you know
755
+ // the warnings are not important to you), use the LogSilencer class
756
+ // below.
757
+ LIBPROTOBUF_EXPORT LogHandler* SetLogHandler(LogHandler* new_func);
758
+
759
+ // Create a LogSilencer if you want to temporarily suppress all log
760
+ // messages. As long as any LogSilencer objects exist, non-fatal
761
+ // log messages will be discarded (the current LogHandler will *not*
762
+ // be called). Constructing a LogSilencer is thread-safe. You may
763
+ // accidentally suppress log messages occurring in another thread, but
764
+ // since messages are generally for debugging purposes only, this isn't
765
+ // a big deal. If you want to intercept log messages, use SetLogHandler().
766
+ class LIBPROTOBUF_EXPORT LogSilencer {
767
+ public:
768
+ LogSilencer();
769
+ ~LogSilencer();
770
+ };
771
+
772
+ // ===================================================================
773
+ // emulates google3/base/callback.h
774
+
775
+ // Abstract interface for a callback. When calling an RPC, you must provide
776
+ // a Closure to call when the procedure completes. See the Service interface
777
+ // in service.h.
778
+ //
779
+ // To automatically construct a Closure which calls a particular function or
780
+ // method with a particular set of parameters, use the NewCallback() function.
781
+ // Example:
782
+ // void FooDone(const FooResponse* response) {
783
+ // ...
784
+ // }
785
+ //
786
+ // void CallFoo() {
787
+ // ...
788
+ // // When done, call FooDone() and pass it a pointer to the response.
789
+ // Closure* callback = NewCallback(&FooDone, response);
790
+ // // Make the call.
791
+ // service->Foo(controller, request, response, callback);
792
+ // }
793
+ //
794
+ // Example that calls a method:
795
+ // class Handler {
796
+ // public:
797
+ // ...
798
+ //
799
+ // void FooDone(const FooResponse* response) {
800
+ // ...
801
+ // }
802
+ //
803
+ // void CallFoo() {
804
+ // ...
805
+ // // When done, call FooDone() and pass it a pointer to the response.
806
+ // Closure* callback = NewCallback(this, &Handler::FooDone, response);
807
+ // // Make the call.
808
+ // service->Foo(controller, request, response, callback);
809
+ // }
810
+ // };
811
+ //
812
+ // Currently NewCallback() supports binding zero, one, or two arguments.
813
+ //
814
+ // Callbacks created with NewCallback() automatically delete themselves when
815
+ // executed. They should be used when a callback is to be called exactly
816
+ // once (usually the case with RPC callbacks). If a callback may be called
817
+ // a different number of times (including zero), create it with
818
+ // NewPermanentCallback() instead. You are then responsible for deleting the
819
+ // callback (using the "delete" keyword as normal).
820
+ //
821
+ // Note that NewCallback() is a bit touchy regarding argument types. Generally,
822
+ // the values you provide for the parameter bindings must exactly match the
823
+ // types accepted by the callback function. For example:
824
+ // void Foo(string s);
825
+ // NewCallback(&Foo, "foo"); // WON'T WORK: const char* != string
826
+ // NewCallback(&Foo, string("foo")); // WORKS
827
+ // Also note that the arguments cannot be references:
828
+ // void Foo(const string& s);
829
+ // string my_str;
830
+ // NewCallback(&Foo, my_str); // WON'T WORK: Can't use referecnes.
831
+ // However, correctly-typed pointers will work just fine.
832
+ class LIBPROTOBUF_EXPORT Closure {
833
+ public:
834
+ Closure() {}
835
+ virtual ~Closure();
836
+
837
+ virtual void Run() = 0;
838
+
839
+ private:
840
+ GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Closure);
841
+ };
842
+
843
+ namespace internal {
844
+
845
+ class LIBPROTOBUF_EXPORT FunctionClosure0 : public Closure {
846
+ public:
847
+ typedef void (*FunctionType)();
848
+
849
+ FunctionClosure0(FunctionType function, bool self_deleting)
850
+ : function_(function), self_deleting_(self_deleting) {}
851
+ ~FunctionClosure0();
852
+
853
+ void Run() {
854
+ bool needs_delete = self_deleting_; // read in case callback deletes
855
+ function_();
856
+ if (needs_delete) delete this;
857
+ }
858
+
859
+ private:
860
+ FunctionType function_;
861
+ bool self_deleting_;
862
+ };
863
+
864
+ template <typename Class>
865
+ class MethodClosure0 : public Closure {
866
+ public:
867
+ typedef void (Class::*MethodType)();
868
+
869
+ MethodClosure0(Class* object, MethodType method, bool self_deleting)
870
+ : object_(object), method_(method), self_deleting_(self_deleting) {}
871
+ ~MethodClosure0() {}
872
+
873
+ void Run() {
874
+ bool needs_delete = self_deleting_; // read in case callback deletes
875
+ (object_->*method_)();
876
+ if (needs_delete) delete this;
877
+ }
878
+
879
+ private:
880
+ Class* object_;
881
+ MethodType method_;
882
+ bool self_deleting_;
883
+ };
884
+
885
+ template <typename Arg1>
886
+ class FunctionClosure1 : public Closure {
887
+ public:
888
+ typedef void (*FunctionType)(Arg1 arg1);
889
+
890
+ FunctionClosure1(FunctionType function, bool self_deleting,
891
+ Arg1 arg1)
892
+ : function_(function), self_deleting_(self_deleting),
893
+ arg1_(arg1) {}
894
+ ~FunctionClosure1() {}
895
+
896
+ void Run() {
897
+ bool needs_delete = self_deleting_; // read in case callback deletes
898
+ function_(arg1_);
899
+ if (needs_delete) delete this;
900
+ }
901
+
902
+ private:
903
+ FunctionType function_;
904
+ bool self_deleting_;
905
+ Arg1 arg1_;
906
+ };
907
+
908
+ template <typename Class, typename Arg1>
909
+ class MethodClosure1 : public Closure {
910
+ public:
911
+ typedef void (Class::*MethodType)(Arg1 arg1);
912
+
913
+ MethodClosure1(Class* object, MethodType method, bool self_deleting,
914
+ Arg1 arg1)
915
+ : object_(object), method_(method), self_deleting_(self_deleting),
916
+ arg1_(arg1) {}
917
+ ~MethodClosure1() {}
918
+
919
+ void Run() {
920
+ bool needs_delete = self_deleting_; // read in case callback deletes
921
+ (object_->*method_)(arg1_);
922
+ if (needs_delete) delete this;
923
+ }
924
+
925
+ private:
926
+ Class* object_;
927
+ MethodType method_;
928
+ bool self_deleting_;
929
+ Arg1 arg1_;
930
+ };
931
+
932
+ template <typename Arg1, typename Arg2>
933
+ class FunctionClosure2 : public Closure {
934
+ public:
935
+ typedef void (*FunctionType)(Arg1 arg1, Arg2 arg2);
936
+
937
+ FunctionClosure2(FunctionType function, bool self_deleting,
938
+ Arg1 arg1, Arg2 arg2)
939
+ : function_(function), self_deleting_(self_deleting),
940
+ arg1_(arg1), arg2_(arg2) {}
941
+ ~FunctionClosure2() {}
942
+
943
+ void Run() {
944
+ bool needs_delete = self_deleting_; // read in case callback deletes
945
+ function_(arg1_, arg2_);
946
+ if (needs_delete) delete this;
947
+ }
948
+
949
+ private:
950
+ FunctionType function_;
951
+ bool self_deleting_;
952
+ Arg1 arg1_;
953
+ Arg2 arg2_;
954
+ };
955
+
956
+ template <typename Class, typename Arg1, typename Arg2>
957
+ class MethodClosure2 : public Closure {
958
+ public:
959
+ typedef void (Class::*MethodType)(Arg1 arg1, Arg2 arg2);
960
+
961
+ MethodClosure2(Class* object, MethodType method, bool self_deleting,
962
+ Arg1 arg1, Arg2 arg2)
963
+ : object_(object), method_(method), self_deleting_(self_deleting),
964
+ arg1_(arg1), arg2_(arg2) {}
965
+ ~MethodClosure2() {}
966
+
967
+ void Run() {
968
+ bool needs_delete = self_deleting_; // read in case callback deletes
969
+ (object_->*method_)(arg1_, arg2_);
970
+ if (needs_delete) delete this;
971
+ }
972
+
973
+ private:
974
+ Class* object_;
975
+ MethodType method_;
976
+ bool self_deleting_;
977
+ Arg1 arg1_;
978
+ Arg2 arg2_;
979
+ };
980
+
981
+ } // namespace internal
982
+
983
+ // See Closure.
984
+ inline Closure* NewCallback(void (*function)()) {
985
+ return new internal::FunctionClosure0(function, true);
986
+ }
987
+
988
+ // See Closure.
989
+ inline Closure* NewPermanentCallback(void (*function)()) {
990
+ return new internal::FunctionClosure0(function, false);
991
+ }
992
+
993
+ // See Closure.
994
+ template <typename Class>
995
+ inline Closure* NewCallback(Class* object, void (Class::*method)()) {
996
+ return new internal::MethodClosure0<Class>(object, method, true);
997
+ }
998
+
999
+ // See Closure.
1000
+ template <typename Class>
1001
+ inline Closure* NewPermanentCallback(Class* object, void (Class::*method)()) {
1002
+ return new internal::MethodClosure0<Class>(object, method, false);
1003
+ }
1004
+
1005
+ // See Closure.
1006
+ template <typename Arg1>
1007
+ inline Closure* NewCallback(void (*function)(Arg1),
1008
+ Arg1 arg1) {
1009
+ return new internal::FunctionClosure1<Arg1>(function, true, arg1);
1010
+ }
1011
+
1012
+ // See Closure.
1013
+ template <typename Arg1>
1014
+ inline Closure* NewPermanentCallback(void (*function)(Arg1),
1015
+ Arg1 arg1) {
1016
+ return new internal::FunctionClosure1<Arg1>(function, false, arg1);
1017
+ }
1018
+
1019
+ // See Closure.
1020
+ template <typename Class, typename Arg1>
1021
+ inline Closure* NewCallback(Class* object, void (Class::*method)(Arg1),
1022
+ Arg1 arg1) {
1023
+ return new internal::MethodClosure1<Class, Arg1>(object, method, true, arg1);
1024
+ }
1025
+
1026
+ // See Closure.
1027
+ template <typename Class, typename Arg1>
1028
+ inline Closure* NewPermanentCallback(Class* object, void (Class::*method)(Arg1),
1029
+ Arg1 arg1) {
1030
+ return new internal::MethodClosure1<Class, Arg1>(object, method, false, arg1);
1031
+ }
1032
+
1033
+ // See Closure.
1034
+ template <typename Arg1, typename Arg2>
1035
+ inline Closure* NewCallback(void (*function)(Arg1, Arg2),
1036
+ Arg1 arg1, Arg2 arg2) {
1037
+ return new internal::FunctionClosure2<Arg1, Arg2>(
1038
+ function, true, arg1, arg2);
1039
+ }
1040
+
1041
+ // See Closure.
1042
+ template <typename Arg1, typename Arg2>
1043
+ inline Closure* NewPermanentCallback(void (*function)(Arg1, Arg2),
1044
+ Arg1 arg1, Arg2 arg2) {
1045
+ return new internal::FunctionClosure2<Arg1, Arg2>(
1046
+ function, false, arg1, arg2);
1047
+ }
1048
+
1049
+ // See Closure.
1050
+ template <typename Class, typename Arg1, typename Arg2>
1051
+ inline Closure* NewCallback(Class* object, void (Class::*method)(Arg1, Arg2),
1052
+ Arg1 arg1, Arg2 arg2) {
1053
+ return new internal::MethodClosure2<Class, Arg1, Arg2>(
1054
+ object, method, true, arg1, arg2);
1055
+ }
1056
+
1057
+ // See Closure.
1058
+ template <typename Class, typename Arg1, typename Arg2>
1059
+ inline Closure* NewPermanentCallback(
1060
+ Class* object, void (Class::*method)(Arg1, Arg2),
1061
+ Arg1 arg1, Arg2 arg2) {
1062
+ return new internal::MethodClosure2<Class, Arg1, Arg2>(
1063
+ object, method, false, arg1, arg2);
1064
+ }
1065
+
1066
+ // A function which does nothing. Useful for creating no-op callbacks, e.g.:
1067
+ // Closure* nothing = NewCallback(&DoNothing);
1068
+ void LIBPROTOBUF_EXPORT DoNothing();
1069
+
1070
+ // ===================================================================
1071
+ // emulates google3/base/mutex.h
1072
+
1073
+ namespace internal {
1074
+
1075
+ // A Mutex is a non-reentrant (aka non-recursive) mutex. At most one thread T
1076
+ // may hold a mutex at a given time. If T attempts to Lock() the same Mutex
1077
+ // while holding it, T will deadlock.
1078
+ class LIBPROTOBUF_EXPORT Mutex {
1079
+ public:
1080
+ // Create a Mutex that is not held by anybody.
1081
+ Mutex();
1082
+
1083
+ // Destructor
1084
+ ~Mutex();
1085
+
1086
+ // Block if necessary until this Mutex is free, then acquire it exclusively.
1087
+ void Lock();
1088
+
1089
+ // Release this Mutex. Caller must hold it exclusively.
1090
+ void Unlock();
1091
+
1092
+ // Crash if this Mutex is not held exclusively by this thread.
1093
+ // May fail to crash when it should; will never crash when it should not.
1094
+ void AssertHeld();
1095
+
1096
+ private:
1097
+ struct Internal;
1098
+ Internal* mInternal;
1099
+
1100
+ GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Mutex);
1101
+ };
1102
+
1103
+ // MutexLock(mu) acquires mu when constructed and releases it when destroyed.
1104
+ class LIBPROTOBUF_EXPORT MutexLock {
1105
+ public:
1106
+ explicit MutexLock(Mutex *mu) : mu_(mu) { this->mu_->Lock(); }
1107
+ ~MutexLock() { this->mu_->Unlock(); }
1108
+ private:
1109
+ Mutex *const mu_;
1110
+ GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MutexLock);
1111
+ };
1112
+
1113
+ // TODO(kenton): Implement these? Hard to implement portably.
1114
+ typedef MutexLock ReaderMutexLock;
1115
+ typedef MutexLock WriterMutexLock;
1116
+
1117
+ // MutexLockMaybe is like MutexLock, but is a no-op when mu is NULL.
1118
+ class LIBPROTOBUF_EXPORT MutexLockMaybe {
1119
+ public:
1120
+ explicit MutexLockMaybe(Mutex *mu) :
1121
+ mu_(mu) { if (this->mu_ != NULL) { this->mu_->Lock(); } }
1122
+ ~MutexLockMaybe() { if (this->mu_ != NULL) { this->mu_->Unlock(); } }
1123
+ private:
1124
+ Mutex *const mu_;
1125
+ GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MutexLockMaybe);
1126
+ };
1127
+
1128
+ } // namespace internal
1129
+
1130
+ // We made these internal so that they would show up as such in the docs,
1131
+ // but we don't want to stick "internal::" in front of them everywhere.
1132
+ using internal::Mutex;
1133
+ using internal::MutexLock;
1134
+ using internal::ReaderMutexLock;
1135
+ using internal::WriterMutexLock;
1136
+ using internal::MutexLockMaybe;
1137
+
1138
+ // ===================================================================
1139
+ // from google3/base/type_traits.h
1140
+
1141
+ namespace internal {
1142
+
1143
+ // Specified by TR1 [4.7.4] Pointer modifications.
1144
+ template<typename T> struct remove_pointer { typedef T type; };
1145
+ template<typename T> struct remove_pointer<T*> { typedef T type; };
1146
+ template<typename T> struct remove_pointer<T* const> { typedef T type; };
1147
+ template<typename T> struct remove_pointer<T* volatile> { typedef T type; };
1148
+ template<typename T> struct remove_pointer<T* const volatile> {
1149
+ typedef T type; };
1150
+
1151
+ // ===================================================================
1152
+
1153
+ // Checks if the buffer contains structurally-valid UTF-8. Implemented in
1154
+ // structurally_valid.cc.
1155
+ LIBPROTOBUF_EXPORT bool IsStructurallyValidUTF8(const char* buf, int len);
1156
+
1157
+ } // namespace internal
1158
+
1159
+ // ===================================================================
1160
+ // Shutdown support.
1161
+
1162
+ // Shut down the entire protocol buffers library, deleting all static-duration
1163
+ // objects allocated by the library or by generated .pb.cc files.
1164
+ //
1165
+ // There are two reasons you might want to call this:
1166
+ // * You use a draconian definition of "memory leak" in which you expect
1167
+ // every single malloc() to have a corresponding free(), even for objects
1168
+ // which live until program exit.
1169
+ // * You are writing a dynamically-loaded library which needs to clean up
1170
+ // after itself when the library is unloaded.
1171
+ //
1172
+ // It is safe to call this multiple times. However, it is not safe to use
1173
+ // any other part of the protocol buffers library after
1174
+ // ShutdownProtobufLibrary() has been called.
1175
+ LIBPROTOBUF_EXPORT void ShutdownProtobufLibrary();
1176
+
1177
+ namespace internal {
1178
+
1179
+ // Register a function to be called when ShutdownProtocolBuffers() is called.
1180
+ LIBPROTOBUF_EXPORT void OnShutdown(void (*func)());
1181
+
1182
+ } // namespace internal
1183
+
1184
+ #ifdef PROTOBUF_USE_EXCEPTIONS
1185
+ class FatalException : public std::exception {
1186
+ public:
1187
+ FatalException(const char* filename, int line, const std::string& message)
1188
+ : filename_(filename), line_(line), message_(message) {}
1189
+ virtual ~FatalException() throw();
1190
+
1191
+ virtual const char* what() const throw();
1192
+
1193
+ const char* filename() const { return filename_; }
1194
+ int line() const { return line_; }
1195
+ const std::string& message() const { return message_; }
1196
+
1197
+ private:
1198
+ const char* filename_;
1199
+ const int line_;
1200
+ const std::string message_;
1201
+ };
1202
+ #endif
1203
+
1204
+ // This is at the end of the file instead of the beginning to work around a bug
1205
+ // in some versions of MSVC.
1206
+ using namespace std; // Don't do this at home, kids.
1207
+
1208
+ } // namespace protobuf
1209
+ } // namespace google
1210
+
1211
+ #endif // GOOGLE_PROTOBUF_COMMON_H__