protoc 2.6.1.1 → 2.6.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (479) hide show
  1. checksums.yaml +4 -4
  2. data/ext/protoc/Makefile.in +10 -13
  3. data/ext/protoc/extconf.rb +0 -1
  4. data/ext/protoc/protobuf/CHANGES.txt +593 -0
  5. data/ext/protoc/protobuf/CONTRIBUTORS.txt +93 -0
  6. data/ext/protoc/protobuf/INSTALL.txt +237 -0
  7. data/ext/protoc/protobuf/LICENSE +33 -0
  8. data/ext/protoc/protobuf/Makefile.am +267 -0
  9. data/ext/protoc/protobuf/README.md +167 -0
  10. data/ext/protoc/protobuf/autogen.sh +41 -0
  11. data/ext/protoc/protobuf/benchmarks/ProtoBench.java +203 -0
  12. data/ext/protoc/protobuf/benchmarks/google_message1.dat +0 -0
  13. data/ext/protoc/protobuf/benchmarks/google_message2.dat +0 -0
  14. data/ext/protoc/protobuf/benchmarks/google_size.proto +136 -0
  15. data/ext/protoc/protobuf/benchmarks/google_speed.proto +136 -0
  16. data/ext/protoc/protobuf/benchmarks/readme.txt +50 -0
  17. data/ext/protoc/protobuf/configure.ac +159 -0
  18. data/ext/protoc/protobuf/editors/README.txt +5 -0
  19. data/ext/protoc/protobuf/editors/proto.vim +105 -0
  20. data/ext/protoc/protobuf/editors/protobuf-mode.el +220 -0
  21. data/ext/protoc/protobuf/examples/AddPerson.java +95 -0
  22. data/ext/protoc/protobuf/examples/ListPeople.java +50 -0
  23. data/ext/protoc/protobuf/examples/Makefile +58 -0
  24. data/ext/protoc/protobuf/examples/README.txt +29 -0
  25. data/ext/protoc/protobuf/examples/add_person.cc +95 -0
  26. data/ext/protoc/protobuf/examples/add_person.py +58 -0
  27. data/ext/protoc/protobuf/examples/addressbook.proto +30 -0
  28. data/ext/protoc/protobuf/examples/list_people.cc +68 -0
  29. data/ext/protoc/protobuf/examples/list_people.py +38 -0
  30. data/ext/protoc/protobuf/generate_descriptor_proto.sh +33 -0
  31. data/ext/protoc/protobuf/java/README.txt +96 -0
  32. data/ext/protoc/protobuf/java/pom.xml +217 -0
  33. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/AbstractMessage.java +466 -0
  34. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/AbstractMessageLite.java +355 -0
  35. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/AbstractParser.java +253 -0
  36. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/BlockingRpcChannel.java +51 -0
  37. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/BlockingService.java +64 -0
  38. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/BoundedByteString.java +163 -0
  39. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ByteString.java +1022 -0
  40. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/CodedInputStream.java +1311 -0
  41. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/CodedOutputStream.java +1297 -0
  42. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Descriptors.java +2238 -0
  43. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/DynamicMessage.java +622 -0
  44. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Extension.java +96 -0
  45. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ExtensionRegistry.java +392 -0
  46. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ExtensionRegistryLite.java +185 -0
  47. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/FieldSet.java +907 -0
  48. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/GeneratedMessage.java +2213 -0
  49. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/GeneratedMessageLite.java +949 -0
  50. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Internal.java +391 -0
  51. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/InvalidProtocolBufferException.java +122 -0
  52. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyField.java +154 -0
  53. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyFieldLite.java +176 -0
  54. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyStringArrayList.java +367 -0
  55. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LazyStringList.java +163 -0
  56. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/LiteralByteString.java +362 -0
  57. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Message.java +244 -0
  58. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageLite.java +320 -0
  59. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageLiteOrBuilder.java +60 -0
  60. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageOrBuilder.java +143 -0
  61. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/MessageReflection.java +931 -0
  62. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Parser.java +261 -0
  63. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ProtocolMessageEnum.java +58 -0
  64. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ProtocolStringList.java +48 -0
  65. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RepeatedFieldBuilder.java +696 -0
  66. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RopeByteString.java +957 -0
  67. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcCallback.java +47 -0
  68. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcChannel.java +71 -0
  69. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcController.java +118 -0
  70. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/RpcUtil.java +134 -0
  71. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Service.java +117 -0
  72. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/ServiceException.java +52 -0
  73. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/SingleFieldBuilder.java +241 -0
  74. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/SmallSortedMap.java +618 -0
  75. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/TextFormat.java +1984 -0
  76. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/UninitializedMessageException.java +99 -0
  77. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/UnknownFieldSet.java +995 -0
  78. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/UnmodifiableLazyStringList.java +205 -0
  79. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/Utf8.java +349 -0
  80. data/ext/protoc/protobuf/java/src/main/java/com/google/protobuf/WireFormat.java +163 -0
  81. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/AbstractMessageTest.java +527 -0
  82. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/BoundedByteStringTest.java +68 -0
  83. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ByteStringTest.java +759 -0
  84. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/CheckUtf8Test.java +141 -0
  85. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/CodedInputStreamTest.java +769 -0
  86. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/CodedOutputStreamTest.java +401 -0
  87. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/DeprecatedFieldTest.java +80 -0
  88. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/DescriptorsTest.java +735 -0
  89. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/DynamicMessageTest.java +326 -0
  90. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ForceFieldBuildersPreRun.java +48 -0
  91. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/GeneratedMessageTest.java +1515 -0
  92. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/IsValidUtf8Test.java +180 -0
  93. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/IsValidUtf8TestUtil.java +421 -0
  94. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyFieldLiteTest.java +134 -0
  95. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyFieldTest.java +121 -0
  96. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyMessageLiteTest.java +319 -0
  97. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyStringArrayListTest.java +174 -0
  98. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LazyStringEndToEndTest.java +143 -0
  99. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LiteEqualsAndHashTest.java +85 -0
  100. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LiteTest.java +148 -0
  101. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/LiteralByteStringTest.java +396 -0
  102. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/MessageTest.java +353 -0
  103. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/NestedBuildersTest.java +185 -0
  104. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ParserTest.java +381 -0
  105. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/RepeatedFieldBuilderTest.java +190 -0
  106. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/RopeByteStringSubstringTest.java +97 -0
  107. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/RopeByteStringTest.java +115 -0
  108. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/ServiceTest.java +320 -0
  109. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/SingleFieldBuilderTest.java +155 -0
  110. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/SmallSortedMapTest.java +420 -0
  111. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/TestBadIdentifiers.java +96 -0
  112. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/TestUtil.java +4124 -0
  113. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/TextFormatTest.java +994 -0
  114. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/UnknownFieldSetTest.java +653 -0
  115. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/UnmodifiableLazyStringListTest.java +227 -0
  116. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/WireFormatTest.java +606 -0
  117. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/lazy_fields_lite.proto +61 -0
  118. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/lite_equals_and_hash.proto +55 -0
  119. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/multiple_files_test.proto +77 -0
  120. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/nested_builders_test.proto +53 -0
  121. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/nested_extension.proto +46 -0
  122. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/nested_extension_lite.proto +48 -0
  123. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/non_nested_extension.proto +49 -0
  124. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/non_nested_extension_lite.proto +50 -0
  125. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/outer_class_name_test.proto +38 -0
  126. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/outer_class_name_test2.proto +42 -0
  127. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/outer_class_name_test3.proto +43 -0
  128. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_bad_identifiers.proto +157 -0
  129. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_check_utf8.proto +50 -0
  130. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_check_utf8_size.proto +51 -0
  131. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_custom_options.proto +43 -0
  132. data/ext/protoc/protobuf/java/src/test/java/com/google/protobuf/test_extra_interfaces.proto +60 -0
  133. data/ext/protoc/protobuf/m4/ac_system_extensions.m4 +37 -0
  134. data/ext/protoc/protobuf/m4/acx_check_suncc.m4 +75 -0
  135. data/ext/protoc/protobuf/m4/acx_pthread.m4 +397 -0
  136. data/ext/protoc/protobuf/m4/stl_hash.m4 +72 -0
  137. data/ext/protoc/protobuf/more_tests/Makefile +41 -0
  138. data/ext/protoc/protobuf/post_process_dist.sh +60 -0
  139. data/ext/protoc/protobuf/protobuf-lite.pc.in +13 -0
  140. data/ext/protoc/protobuf/protobuf.pc.in +14 -0
  141. data/ext/protoc/protobuf/python/README.txt +105 -0
  142. data/ext/protoc/protobuf/python/ez_setup.py +284 -0
  143. data/ext/protoc/protobuf/python/google/__init__.py +1 -0
  144. data/ext/protoc/protobuf/python/google/protobuf/__init__.py +0 -0
  145. data/ext/protoc/protobuf/python/google/protobuf/descriptor.py +849 -0
  146. data/ext/protoc/protobuf/python/google/protobuf/descriptor_database.py +137 -0
  147. data/ext/protoc/protobuf/python/google/protobuf/descriptor_pool.py +643 -0
  148. data/ext/protoc/protobuf/python/google/protobuf/internal/__init__.py +0 -0
  149. data/ext/protoc/protobuf/python/google/protobuf/internal/api_implementation.cc +139 -0
  150. data/ext/protoc/protobuf/python/google/protobuf/internal/api_implementation.py +89 -0
  151. data/ext/protoc/protobuf/python/google/protobuf/internal/api_implementation_default_test.py +63 -0
  152. data/ext/protoc/protobuf/python/google/protobuf/internal/containers.py +269 -0
  153. data/ext/protoc/protobuf/python/google/protobuf/internal/cpp_message.py +663 -0
  154. data/ext/protoc/protobuf/python/google/protobuf/internal/decoder.py +831 -0
  155. data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_database_test.py +63 -0
  156. data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_pool_test.py +564 -0
  157. data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_pool_test1.proto +94 -0
  158. data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_pool_test2.proto +70 -0
  159. data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_python_test.py +54 -0
  160. data/ext/protoc/protobuf/python/google/protobuf/internal/descriptor_test.py +669 -0
  161. data/ext/protoc/protobuf/python/google/protobuf/internal/encoder.py +788 -0
  162. data/ext/protoc/protobuf/python/google/protobuf/internal/enum_type_wrapper.py +89 -0
  163. data/ext/protoc/protobuf/python/google/protobuf/internal/factory_test1.proto +57 -0
  164. data/ext/protoc/protobuf/python/google/protobuf/internal/factory_test2.proto +92 -0
  165. data/ext/protoc/protobuf/python/google/protobuf/internal/generator_test.py +343 -0
  166. data/ext/protoc/protobuf/python/google/protobuf/internal/message_factory_python_test.py +54 -0
  167. data/ext/protoc/protobuf/python/google/protobuf/internal/message_factory_test.py +131 -0
  168. data/ext/protoc/protobuf/python/google/protobuf/internal/message_listener.py +78 -0
  169. data/ext/protoc/protobuf/python/google/protobuf/internal/message_python_test.py +54 -0
  170. data/ext/protoc/protobuf/python/google/protobuf/internal/message_test.py +681 -0
  171. data/ext/protoc/protobuf/python/google/protobuf/internal/missing_enum_values.proto +50 -0
  172. data/ext/protoc/protobuf/python/google/protobuf/internal/more_extensions.proto +58 -0
  173. data/ext/protoc/protobuf/python/google/protobuf/internal/more_extensions_dynamic.proto +49 -0
  174. data/ext/protoc/protobuf/python/google/protobuf/internal/more_messages.proto +51 -0
  175. data/ext/protoc/protobuf/python/google/protobuf/internal/python_message.py +1251 -0
  176. data/ext/protoc/protobuf/python/google/protobuf/internal/reflection_test.py +2934 -0
  177. data/ext/protoc/protobuf/python/google/protobuf/internal/service_reflection_test.py +136 -0
  178. data/ext/protoc/protobuf/python/google/protobuf/internal/symbol_database_test.py +120 -0
  179. data/ext/protoc/protobuf/python/google/protobuf/internal/test_bad_identifiers.proto +52 -0
  180. data/ext/protoc/protobuf/python/google/protobuf/internal/test_util.py +662 -0
  181. data/ext/protoc/protobuf/python/google/protobuf/internal/text_encoding_test.py +68 -0
  182. data/ext/protoc/protobuf/python/google/protobuf/internal/text_format_test.py +743 -0
  183. data/ext/protoc/protobuf/python/google/protobuf/internal/type_checkers.py +328 -0
  184. data/ext/protoc/protobuf/python/google/protobuf/internal/unknown_fields_test.py +231 -0
  185. data/ext/protoc/protobuf/python/google/protobuf/internal/wire_format.py +268 -0
  186. data/ext/protoc/protobuf/python/google/protobuf/internal/wire_format_test.py +253 -0
  187. data/ext/protoc/protobuf/python/google/protobuf/message.py +284 -0
  188. data/ext/protoc/protobuf/python/google/protobuf/message_factory.py +155 -0
  189. data/ext/protoc/protobuf/python/google/protobuf/pyext/README +6 -0
  190. data/ext/protoc/protobuf/python/google/protobuf/pyext/__init__.py +0 -0
  191. data/ext/protoc/protobuf/python/google/protobuf/pyext/cpp_message.py +61 -0
  192. data/ext/protoc/protobuf/python/google/protobuf/pyext/descriptor.cc +357 -0
  193. data/ext/protoc/protobuf/python/google/protobuf/pyext/descriptor.h +96 -0
  194. data/ext/protoc/protobuf/python/google/protobuf/pyext/descriptor_cpp2_test.py +58 -0
  195. data/ext/protoc/protobuf/python/google/protobuf/pyext/extension_dict.cc +338 -0
  196. data/ext/protoc/protobuf/python/google/protobuf/pyext/extension_dict.h +123 -0
  197. data/ext/protoc/protobuf/python/google/protobuf/pyext/message.cc +2561 -0
  198. data/ext/protoc/protobuf/python/google/protobuf/pyext/message.h +305 -0
  199. data/ext/protoc/protobuf/python/google/protobuf/pyext/message_factory_cpp2_test.py +56 -0
  200. data/ext/protoc/protobuf/python/google/protobuf/pyext/proto2_api_test.proto +38 -0
  201. data/ext/protoc/protobuf/python/google/protobuf/pyext/python.proto +66 -0
  202. data/ext/protoc/protobuf/python/google/protobuf/pyext/python_protobuf.h +57 -0
  203. data/ext/protoc/protobuf/python/google/protobuf/pyext/reflection_cpp2_generated_test.py +94 -0
  204. data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_composite_container.cc +763 -0
  205. data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_composite_container.h +172 -0
  206. data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_scalar_container.cc +825 -0
  207. data/ext/protoc/protobuf/python/google/protobuf/pyext/repeated_scalar_container.h +112 -0
  208. data/ext/protoc/protobuf/python/google/protobuf/pyext/scoped_pyobject_ptr.h +95 -0
  209. data/ext/protoc/protobuf/python/google/protobuf/reflection.py +205 -0
  210. data/ext/protoc/protobuf/python/google/protobuf/service.py +226 -0
  211. data/ext/protoc/protobuf/python/google/protobuf/service_reflection.py +284 -0
  212. data/ext/protoc/protobuf/python/google/protobuf/symbol_database.py +185 -0
  213. data/ext/protoc/protobuf/python/google/protobuf/text_encoding.py +110 -0
  214. data/ext/protoc/protobuf/python/google/protobuf/text_format.py +873 -0
  215. data/ext/protoc/protobuf/python/mox.py +1401 -0
  216. data/ext/protoc/protobuf/python/setup.py +201 -0
  217. data/ext/protoc/protobuf/python/stubout.py +140 -0
  218. data/ext/protoc/protobuf/src/Makefile.am +418 -0
  219. data/ext/protoc/protobuf/src/google/protobuf/SEBS +240 -0
  220. data/ext/protoc/protobuf/src/google/protobuf/compiler/code_generator.cc +84 -0
  221. data/ext/protoc/protobuf/src/google/protobuf/compiler/code_generator.h +145 -0
  222. data/ext/protoc/protobuf/src/google/protobuf/compiler/command_line_interface.cc +1603 -0
  223. data/ext/protoc/protobuf/src/google/protobuf/compiler/command_line_interface.h +378 -0
  224. data/ext/protoc/protobuf/src/google/protobuf/compiler/command_line_interface_unittest.cc +1654 -0
  225. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc +158 -0
  226. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum.cc +288 -0
  227. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum.h +103 -0
  228. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.cc +431 -0
  229. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_enum_field.h +122 -0
  230. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.cc +210 -0
  231. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_extension.h +86 -0
  232. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_field.cc +166 -0
  233. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_field.h +185 -0
  234. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_file.cc +665 -0
  235. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_file.h +99 -0
  236. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.cc +125 -0
  237. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_generator.h +72 -0
  238. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.cc +494 -0
  239. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_helpers.h +206 -0
  240. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message.cc +2645 -0
  241. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message.h +175 -0
  242. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message_field.cc +375 -0
  243. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_message_field.h +121 -0
  244. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_options.h +58 -0
  245. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_plugin_unittest.cc +123 -0
  246. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc +451 -0
  247. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_primitive_field.h +123 -0
  248. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_service.cc +334 -0
  249. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_service.h +118 -0
  250. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_string_field.cc +642 -0
  251. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_string_field.h +127 -0
  252. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_test_bad_identifiers.proto +132 -0
  253. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_unittest.cc +2074 -0
  254. data/ext/protoc/protobuf/src/google/protobuf/compiler/cpp/cpp_unittest.h +51 -0
  255. data/ext/protoc/protobuf/src/google/protobuf/compiler/importer.cc +480 -0
  256. data/ext/protoc/protobuf/src/google/protobuf/compiler/importer.h +317 -0
  257. data/ext/protoc/protobuf/src/google/protobuf/compiler/importer_unittest.cc +617 -0
  258. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_context.cc +195 -0
  259. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_context.h +95 -0
  260. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_doc_comment.cc +233 -0
  261. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_doc_comment.h +69 -0
  262. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_doc_comment_unittest.cc +67 -0
  263. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum.cc +333 -0
  264. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum.h +99 -0
  265. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum_field.cc +778 -0
  266. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_enum_field.h +158 -0
  267. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_extension.cc +207 -0
  268. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_extension.h +109 -0
  269. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_field.cc +213 -0
  270. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_field.h +162 -0
  271. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_file.cc +534 -0
  272. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_file.h +115 -0
  273. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator.cc +158 -0
  274. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator.h +72 -0
  275. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator_factory.cc +77 -0
  276. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_generator_factory.h +101 -0
  277. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_helpers.cc +737 -0
  278. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_helpers.h +322 -0
  279. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field.cc +826 -0
  280. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_lazy_message_field.h +121 -0
  281. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message.cc +1666 -0
  282. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message.h +140 -0
  283. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message_field.cc +1343 -0
  284. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_message_field.h +173 -0
  285. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_name_resolver.cc +266 -0
  286. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_name_resolver.h +124 -0
  287. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_plugin_unittest.cc +124 -0
  288. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_primitive_field.cc +877 -0
  289. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_primitive_field.h +160 -0
  290. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_service.cc +473 -0
  291. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_service.h +135 -0
  292. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_shared_code_generator.cc +201 -0
  293. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_shared_code_generator.h +90 -0
  294. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_string_field.cc +1056 -0
  295. data/ext/protoc/protobuf/src/google/protobuf/compiler/java/java_string_field.h +160 -0
  296. data/ext/protoc/protobuf/src/google/protobuf/compiler/main.cc +61 -0
  297. data/ext/protoc/protobuf/src/google/protobuf/compiler/mock_code_generator.cc +240 -0
  298. data/ext/protoc/protobuf/src/google/protobuf/compiler/mock_code_generator.h +117 -0
  299. data/ext/protoc/protobuf/src/google/protobuf/compiler/package_info.h +64 -0
  300. data/ext/protoc/protobuf/src/google/protobuf/compiler/parser.cc +1750 -0
  301. data/ext/protoc/protobuf/src/google/protobuf/compiler/parser.h +522 -0
  302. data/ext/protoc/protobuf/src/google/protobuf/compiler/parser_unittest.cc +2612 -0
  303. data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.cc +163 -0
  304. data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.h +72 -0
  305. data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.pb.cc +1148 -0
  306. data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.pb.h +897 -0
  307. data/ext/protoc/protobuf/src/google/protobuf/compiler/plugin.proto +147 -0
  308. data/ext/protoc/protobuf/src/google/protobuf/compiler/python/python_generator.cc +1262 -0
  309. data/ext/protoc/protobuf/src/google/protobuf/compiler/python/python_generator.h +166 -0
  310. data/ext/protoc/protobuf/src/google/protobuf/compiler/python/python_plugin_unittest.cc +118 -0
  311. data/ext/protoc/protobuf/src/google/protobuf/compiler/subprocess.cc +463 -0
  312. data/ext/protoc/protobuf/src/google/protobuf/compiler/subprocess.h +108 -0
  313. data/ext/protoc/protobuf/src/google/protobuf/compiler/test_plugin.cc +51 -0
  314. data/ext/protoc/protobuf/src/google/protobuf/compiler/zip_output_unittest.sh +91 -0
  315. data/ext/protoc/protobuf/src/google/protobuf/compiler/zip_writer.cc +218 -0
  316. data/ext/protoc/protobuf/src/google/protobuf/compiler/zip_writer.h +93 -0
  317. data/ext/protoc/protobuf/src/google/protobuf/descriptor.cc +5420 -0
  318. data/ext/protoc/protobuf/src/google/protobuf/descriptor.h +1691 -0
  319. data/ext/protoc/protobuf/src/google/protobuf/descriptor.pb.cc +9135 -0
  320. data/ext/protoc/protobuf/src/google/protobuf/descriptor.pb.h +6761 -0
  321. data/ext/protoc/protobuf/src/google/protobuf/descriptor.proto +687 -0
  322. data/ext/protoc/protobuf/src/google/protobuf/descriptor_database.cc +543 -0
  323. data/ext/protoc/protobuf/src/google/protobuf/descriptor_database.h +369 -0
  324. data/ext/protoc/protobuf/src/google/protobuf/descriptor_database_unittest.cc +748 -0
  325. data/ext/protoc/protobuf/src/google/protobuf/descriptor_pb2_test.py +54 -0
  326. data/ext/protoc/protobuf/src/google/protobuf/descriptor_unittest.cc +5501 -0
  327. data/ext/protoc/protobuf/src/google/protobuf/dynamic_message.cc +764 -0
  328. data/ext/protoc/protobuf/src/google/protobuf/dynamic_message.h +148 -0
  329. data/ext/protoc/protobuf/src/google/protobuf/dynamic_message_unittest.cc +230 -0
  330. data/ext/protoc/protobuf/src/google/protobuf/extension_set.cc +1663 -0
  331. data/ext/protoc/protobuf/src/google/protobuf/extension_set.h +1234 -0
  332. data/ext/protoc/protobuf/src/google/protobuf/extension_set_heavy.cc +734 -0
  333. data/ext/protoc/protobuf/src/google/protobuf/extension_set_unittest.cc +1095 -0
  334. data/ext/protoc/protobuf/src/google/protobuf/generated_enum_reflection.h +91 -0
  335. data/ext/protoc/protobuf/src/google/protobuf/generated_message_reflection.cc +1683 -0
  336. data/ext/protoc/protobuf/src/google/protobuf/generated_message_reflection.h +504 -0
  337. data/ext/protoc/protobuf/src/google/protobuf/generated_message_reflection_unittest.cc +795 -0
  338. data/ext/protoc/protobuf/src/google/protobuf/generated_message_util.cc +65 -0
  339. data/ext/protoc/protobuf/src/google/protobuf/generated_message_util.h +113 -0
  340. data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream.cc +914 -0
  341. data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream.h +1220 -0
  342. data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream_inl.h +69 -0
  343. data/ext/protoc/protobuf/src/google/protobuf/io/coded_stream_unittest.cc +1378 -0
  344. data/ext/protoc/protobuf/src/google/protobuf/io/gzip_stream.cc +326 -0
  345. data/ext/protoc/protobuf/src/google/protobuf/io/gzip_stream.h +209 -0
  346. data/ext/protoc/protobuf/src/google/protobuf/io/gzip_stream_unittest.sh +44 -0
  347. data/ext/protoc/protobuf/src/google/protobuf/io/package_info.h +54 -0
  348. data/ext/protoc/protobuf/src/google/protobuf/io/printer.cc +198 -0
  349. data/ext/protoc/protobuf/src/google/protobuf/io/printer.h +136 -0
  350. data/ext/protoc/protobuf/src/google/protobuf/io/printer_unittest.cc +285 -0
  351. data/ext/protoc/protobuf/src/google/protobuf/io/strtod.cc +113 -0
  352. data/ext/protoc/protobuf/src/google/protobuf/io/strtod.h +50 -0
  353. data/ext/protoc/protobuf/src/google/protobuf/io/tokenizer.cc +1127 -0
  354. data/ext/protoc/protobuf/src/google/protobuf/io/tokenizer.h +402 -0
  355. data/ext/protoc/protobuf/src/google/protobuf/io/tokenizer_unittest.cc +999 -0
  356. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream.cc +57 -0
  357. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream.h +248 -0
  358. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl.cc +473 -0
  359. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl.h +358 -0
  360. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.cc +405 -0
  361. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_impl_lite.h +354 -0
  362. data/ext/protoc/protobuf/src/google/protobuf/io/zero_copy_stream_unittest.cc +965 -0
  363. data/ext/protoc/protobuf/src/google/protobuf/lite_unittest.cc +350 -0
  364. data/ext/protoc/protobuf/src/google/protobuf/message.cc +358 -0
  365. data/ext/protoc/protobuf/src/google/protobuf/message.h +866 -0
  366. data/ext/protoc/protobuf/src/google/protobuf/message_lite.cc +335 -0
  367. data/ext/protoc/protobuf/src/google/protobuf/message_lite.h +247 -0
  368. data/ext/protoc/protobuf/src/google/protobuf/message_unittest.cc +427 -0
  369. data/ext/protoc/protobuf/src/google/protobuf/package_info.h +64 -0
  370. data/ext/protoc/protobuf/src/google/protobuf/reflection_ops.cc +269 -0
  371. data/ext/protoc/protobuf/src/google/protobuf/reflection_ops.h +81 -0
  372. data/ext/protoc/protobuf/src/google/protobuf/reflection_ops_unittest.cc +475 -0
  373. data/ext/protoc/protobuf/src/google/protobuf/repeated_field.cc +87 -0
  374. data/ext/protoc/protobuf/src/google/protobuf/repeated_field.h +1603 -0
  375. data/ext/protoc/protobuf/src/google/protobuf/repeated_field_reflection_unittest.cc +195 -0
  376. data/ext/protoc/protobuf/src/google/protobuf/repeated_field_unittest.cc +1442 -0
  377. data/ext/protoc/protobuf/src/google/protobuf/service.cc +46 -0
  378. data/ext/protoc/protobuf/src/google/protobuf/service.h +291 -0
  379. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops.h +227 -0
  380. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_arm64_gcc.h +325 -0
  381. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_arm_gcc.h +151 -0
  382. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_arm_qnx.h +146 -0
  383. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h +122 -0
  384. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_generic_gcc.h +137 -0
  385. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_macosx.h +225 -0
  386. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_mips_gcc.h +313 -0
  387. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_pnacl.h +73 -0
  388. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_solaris.h +188 -0
  389. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_tsan.h +219 -0
  390. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc +137 -0
  391. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_gcc.h +293 -0
  392. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc +112 -0
  393. data/ext/protoc/protobuf/src/google/protobuf/stubs/atomicops_internals_x86_msvc.h +150 -0
  394. data/ext/protoc/protobuf/src/google/protobuf/stubs/common.cc +395 -0
  395. data/ext/protoc/protobuf/src/google/protobuf/stubs/common.h +1226 -0
  396. data/ext/protoc/protobuf/src/google/protobuf/stubs/common_unittest.cc +357 -0
  397. data/ext/protoc/protobuf/src/google/protobuf/stubs/hash.h +232 -0
  398. data/ext/protoc/protobuf/src/google/protobuf/stubs/map_util.h +771 -0
  399. data/ext/protoc/protobuf/src/google/protobuf/stubs/once.cc +99 -0
  400. data/ext/protoc/protobuf/src/google/protobuf/stubs/once.h +166 -0
  401. data/ext/protoc/protobuf/src/google/protobuf/stubs/once_unittest.cc +253 -0
  402. data/ext/protoc/protobuf/src/google/protobuf/stubs/platform_macros.h +103 -0
  403. data/ext/protoc/protobuf/src/google/protobuf/stubs/shared_ptr.h +470 -0
  404. data/ext/protoc/protobuf/src/google/protobuf/stubs/stl_util.h +121 -0
  405. data/ext/protoc/protobuf/src/google/protobuf/stubs/stringprintf.cc +175 -0
  406. data/ext/protoc/protobuf/src/google/protobuf/stubs/stringprintf.h +76 -0
  407. data/ext/protoc/protobuf/src/google/protobuf/stubs/stringprintf_unittest.cc +152 -0
  408. data/ext/protoc/protobuf/src/google/protobuf/stubs/structurally_valid.cc +536 -0
  409. data/ext/protoc/protobuf/src/google/protobuf/stubs/structurally_valid_unittest.cc +40 -0
  410. data/ext/protoc/protobuf/src/google/protobuf/stubs/strutil.cc +1279 -0
  411. data/ext/protoc/protobuf/src/google/protobuf/stubs/strutil.h +562 -0
  412. data/ext/protoc/protobuf/src/google/protobuf/stubs/strutil_unittest.cc +73 -0
  413. data/ext/protoc/protobuf/src/google/protobuf/stubs/substitute.cc +134 -0
  414. data/ext/protoc/protobuf/src/google/protobuf/stubs/substitute.h +170 -0
  415. data/ext/protoc/protobuf/src/google/protobuf/stubs/template_util.h +138 -0
  416. data/ext/protoc/protobuf/src/google/protobuf/stubs/template_util_unittest.cc +130 -0
  417. data/ext/protoc/protobuf/src/google/protobuf/stubs/type_traits.h +336 -0
  418. data/ext/protoc/protobuf/src/google/protobuf/stubs/type_traits_unittest.cc +628 -0
  419. data/ext/protoc/protobuf/src/google/protobuf/test_util.cc +3345 -0
  420. data/ext/protoc/protobuf/src/google/protobuf/test_util.h +215 -0
  421. data/ext/protoc/protobuf/src/google/protobuf/test_util_lite.cc +1585 -0
  422. data/ext/protoc/protobuf/src/google/protobuf/test_util_lite.h +101 -0
  423. data/ext/protoc/protobuf/src/google/protobuf/testdata/bad_utf8_string +1 -0
  424. data/ext/protoc/protobuf/src/google/protobuf/testdata/golden_message +0 -0
  425. data/ext/protoc/protobuf/src/google/protobuf/testdata/golden_message_oneof_implemented +0 -0
  426. data/ext/protoc/protobuf/src/google/protobuf/testdata/golden_packed_fields_message +0 -0
  427. data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data.txt +134 -0
  428. data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data_oneof_implemented.txt +129 -0
  429. data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data_pointy.txt +134 -0
  430. data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_data_pointy_oneof.txt +129 -0
  431. data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_extensions_data.txt +134 -0
  432. data/ext/protoc/protobuf/src/google/protobuf/testdata/text_format_unittest_extensions_data_pointy.txt +134 -0
  433. data/ext/protoc/protobuf/src/google/protobuf/testing/file.cc +194 -0
  434. data/ext/protoc/protobuf/src/google/protobuf/testing/file.h +97 -0
  435. data/ext/protoc/protobuf/src/google/protobuf/testing/googletest.cc +255 -0
  436. data/ext/protoc/protobuf/src/google/protobuf/testing/googletest.h +102 -0
  437. data/ext/protoc/protobuf/src/google/protobuf/testing/zcgunzip.cc +73 -0
  438. data/ext/protoc/protobuf/src/google/protobuf/testing/zcgzip.cc +79 -0
  439. data/ext/protoc/protobuf/src/google/protobuf/text_format.cc +1746 -0
  440. data/ext/protoc/protobuf/src/google/protobuf/text_format.h +473 -0
  441. data/ext/protoc/protobuf/src/google/protobuf/text_format_unittest.cc +1479 -0
  442. data/ext/protoc/protobuf/src/google/protobuf/unittest.proto +861 -0
  443. data/ext/protoc/protobuf/src/google/protobuf/unittest_custom_options.proto +393 -0
  444. data/ext/protoc/protobuf/src/google/protobuf/unittest_embed_optimize_for.proto +50 -0
  445. data/ext/protoc/protobuf/src/google/protobuf/unittest_empty.proto +37 -0
  446. data/ext/protoc/protobuf/src/google/protobuf/unittest_enormous_descriptor.proto +1046 -0
  447. data/ext/protoc/protobuf/src/google/protobuf/unittest_import.proto +64 -0
  448. data/ext/protoc/protobuf/src/google/protobuf/unittest_import_lite.proto +51 -0
  449. data/ext/protoc/protobuf/src/google/protobuf/unittest_import_public.proto +40 -0
  450. data/ext/protoc/protobuf/src/google/protobuf/unittest_import_public_lite.proto +42 -0
  451. data/ext/protoc/protobuf/src/google/protobuf/unittest_lite.proto +384 -0
  452. data/ext/protoc/protobuf/src/google/protobuf/unittest_lite_imports_nonlite.proto +43 -0
  453. data/ext/protoc/protobuf/src/google/protobuf/unittest_mset.proto +83 -0
  454. data/ext/protoc/protobuf/src/google/protobuf/unittest_no_generic_services.proto +53 -0
  455. data/ext/protoc/protobuf/src/google/protobuf/unittest_optimize_for.proto +66 -0
  456. data/ext/protoc/protobuf/src/google/protobuf/unknown_field_set.cc +265 -0
  457. data/ext/protoc/protobuf/src/google/protobuf/unknown_field_set.h +318 -0
  458. data/ext/protoc/protobuf/src/google/protobuf/unknown_field_set_unittest.cc +599 -0
  459. data/ext/protoc/protobuf/src/google/protobuf/wire_format.cc +1101 -0
  460. data/ext/protoc/protobuf/src/google/protobuf/wire_format.h +336 -0
  461. data/ext/protoc/protobuf/src/google/protobuf/wire_format_lite.cc +471 -0
  462. data/ext/protoc/protobuf/src/google/protobuf/wire_format_lite.h +661 -0
  463. data/ext/protoc/protobuf/src/google/protobuf/wire_format_lite_inl.h +860 -0
  464. data/ext/protoc/protobuf/src/google/protobuf/wire_format_unittest.cc +1120 -0
  465. data/ext/protoc/protobuf/src/solaris/libstdc++.la +51 -0
  466. data/ext/protoc/protobuf/vsprojects/config.h +29 -0
  467. data/ext/protoc/protobuf/vsprojects/convert2008to2005.sh +20 -0
  468. data/ext/protoc/protobuf/vsprojects/extract_includes.bat +50 -0
  469. data/ext/protoc/protobuf/vsprojects/libprotobuf-lite.vcproj +302 -0
  470. data/ext/protoc/protobuf/vsprojects/libprotobuf.vcproj +470 -0
  471. data/ext/protoc/protobuf/vsprojects/libprotoc.vcproj +466 -0
  472. data/ext/protoc/protobuf/vsprojects/lite-test.vcproj +305 -0
  473. data/ext/protoc/protobuf/vsprojects/protobuf.sln +92 -0
  474. data/ext/protoc/protobuf/vsprojects/protoc.vcproj +192 -0
  475. data/ext/protoc/protobuf/vsprojects/readme.txt +114 -0
  476. data/ext/protoc/protobuf/vsprojects/test_plugin.vcproj +209 -0
  477. data/ext/protoc/protobuf/vsprojects/tests.vcproj +681 -0
  478. data/lib/protoc/version.rb +1 -1
  479. metadata +480 -3
@@ -0,0 +1,51 @@
1
+ // Protocol Buffers - Google's data interchange format
2
+ // Copyright 2008 Google Inc. All rights reserved.
3
+ // https://developers.google.com/protocol-buffers/
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
+ package com.google.protobuf;
32
+
33
+ /**
34
+ * <p>Abstract interface for a blocking RPC channel. {@code BlockingRpcChannel}
35
+ * is the blocking equivalent to {@link RpcChannel}.
36
+ *
37
+ * @author kenton@google.com Kenton Varda
38
+ * @author cpovirk@google.com Chris Povirk
39
+ */
40
+ public interface BlockingRpcChannel {
41
+ /**
42
+ * Call the given method of the remote service and blocks until it returns.
43
+ * {@code callBlockingMethod()} is the blocking equivalent to
44
+ * {@link RpcChannel#callMethod}.
45
+ */
46
+ Message callBlockingMethod(
47
+ Descriptors.MethodDescriptor method,
48
+ RpcController controller,
49
+ Message request,
50
+ Message responsePrototype) throws ServiceException;
51
+ }
@@ -0,0 +1,64 @@
1
+ // Protocol Buffers - Google's data interchange format
2
+ // Copyright 2008 Google Inc. All rights reserved.
3
+ // https://developers.google.com/protocol-buffers/
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
+ package com.google.protobuf;
32
+
33
+ /**
34
+ * Blocking equivalent to {@link Service}.
35
+ *
36
+ * @author kenton@google.com Kenton Varda
37
+ * @author cpovirk@google.com Chris Povirk
38
+ */
39
+ public interface BlockingService {
40
+ /**
41
+ * Equivalent to {@link Service#getDescriptorForType}.
42
+ */
43
+ Descriptors.ServiceDescriptor getDescriptorForType();
44
+
45
+ /**
46
+ * Equivalent to {@link Service#callMethod}, except that
47
+ * {@code callBlockingMethod()} returns the result of the RPC or throws a
48
+ * {@link ServiceException} if there is a failure, rather than passing the
49
+ * information to a callback.
50
+ */
51
+ Message callBlockingMethod(Descriptors.MethodDescriptor method,
52
+ RpcController controller,
53
+ Message request) throws ServiceException;
54
+
55
+ /**
56
+ * Equivalent to {@link Service#getRequestPrototype}.
57
+ */
58
+ Message getRequestPrototype(Descriptors.MethodDescriptor method);
59
+
60
+ /**
61
+ * Equivalent to {@link Service#getResponsePrototype}.
62
+ */
63
+ Message getResponsePrototype(Descriptors.MethodDescriptor method);
64
+ }
@@ -0,0 +1,163 @@
1
+ // Protocol Buffers - Google's data interchange format
2
+ // Copyright 2008 Google Inc. All rights reserved.
3
+ // https://developers.google.com/protocol-buffers/
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
+ package com.google.protobuf;
32
+
33
+ import java.util.NoSuchElementException;
34
+
35
+ /**
36
+ * This class is used to represent the substring of a {@link ByteString} over a
37
+ * single byte array. In terms of the public API of {@link ByteString}, you end
38
+ * up here by calling {@link ByteString#copyFrom(byte[])} followed by {@link
39
+ * ByteString#substring(int, int)}.
40
+ *
41
+ * <p>This class contains most of the overhead involved in creating a substring
42
+ * from a {@link LiteralByteString}. The overhead involves some range-checking
43
+ * and two extra fields.
44
+ *
45
+ * @author carlanton@google.com (Carl Haverl)
46
+ */
47
+ class BoundedByteString extends LiteralByteString {
48
+
49
+ private final int bytesOffset;
50
+ private final int bytesLength;
51
+
52
+ /**
53
+ * Creates a {@code BoundedByteString} backed by the sub-range of given array,
54
+ * without copying.
55
+ *
56
+ * @param bytes array to wrap
57
+ * @param offset index to first byte to use in bytes
58
+ * @param length number of bytes to use from bytes
59
+ * @throws IllegalArgumentException if {@code offset < 0}, {@code length < 0},
60
+ * or if {@code offset + length >
61
+ * bytes.length}.
62
+ */
63
+ BoundedByteString(byte[] bytes, int offset, int length) {
64
+ super(bytes);
65
+ if (offset < 0) {
66
+ throw new IllegalArgumentException("Offset too small: " + offset);
67
+ }
68
+ if (length < 0) {
69
+ throw new IllegalArgumentException("Length too small: " + offset);
70
+ }
71
+ if ((long) offset + length > bytes.length) {
72
+ throw new IllegalArgumentException(
73
+ "Offset+Length too large: " + offset + "+" + length);
74
+ }
75
+
76
+ this.bytesOffset = offset;
77
+ this.bytesLength = length;
78
+ }
79
+
80
+ /**
81
+ * Gets the byte at the given index.
82
+ * Throws {@link ArrayIndexOutOfBoundsException}
83
+ * for backwards-compatibility reasons although it would more properly be
84
+ * {@link IndexOutOfBoundsException}.
85
+ *
86
+ * @param index index of byte
87
+ * @return the value
88
+ * @throws ArrayIndexOutOfBoundsException {@code index} is < 0 or >= size
89
+ */
90
+ @Override
91
+ public byte byteAt(int index) {
92
+ // We must check the index ourselves as we cannot rely on Java array index
93
+ // checking for substrings.
94
+ if (index < 0) {
95
+ throw new ArrayIndexOutOfBoundsException("Index too small: " + index);
96
+ }
97
+ if (index >= size()) {
98
+ throw new ArrayIndexOutOfBoundsException(
99
+ "Index too large: " + index + ", " + size());
100
+ }
101
+
102
+ return bytes[bytesOffset + index];
103
+ }
104
+
105
+ @Override
106
+ public int size() {
107
+ return bytesLength;
108
+ }
109
+
110
+ @Override
111
+ protected int getOffsetIntoBytes() {
112
+ return bytesOffset;
113
+ }
114
+
115
+ // =================================================================
116
+ // ByteString -> byte[]
117
+
118
+ @Override
119
+ protected void copyToInternal(byte[] target, int sourceOffset,
120
+ int targetOffset, int numberToCopy) {
121
+ System.arraycopy(bytes, getOffsetIntoBytes() + sourceOffset, target,
122
+ targetOffset, numberToCopy);
123
+ }
124
+
125
+ // =================================================================
126
+ // ByteIterator
127
+
128
+ @Override
129
+ public ByteIterator iterator() {
130
+ return new BoundedByteIterator();
131
+ }
132
+
133
+ private class BoundedByteIterator implements ByteIterator {
134
+
135
+ private int position;
136
+ private final int limit;
137
+
138
+ private BoundedByteIterator() {
139
+ position = getOffsetIntoBytes();
140
+ limit = position + size();
141
+ }
142
+
143
+ public boolean hasNext() {
144
+ return (position < limit);
145
+ }
146
+
147
+ public Byte next() {
148
+ // Boxing calls Byte.valueOf(byte), which does not instantiate.
149
+ return nextByte();
150
+ }
151
+
152
+ public byte nextByte() {
153
+ if (position >= limit) {
154
+ throw new NoSuchElementException();
155
+ }
156
+ return bytes[position++];
157
+ }
158
+
159
+ public void remove() {
160
+ throw new UnsupportedOperationException();
161
+ }
162
+ }
163
+ }
@@ -0,0 +1,1022 @@
1
+ // Protocol Buffers - Google's data interchange format
2
+ // Copyright 2008 Google Inc. All rights reserved.
3
+ // https://developers.google.com/protocol-buffers/
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
+ package com.google.protobuf;
32
+
33
+ import java.io.ByteArrayOutputStream;
34
+ import java.io.IOException;
35
+ import java.io.InputStream;
36
+ import java.io.OutputStream;
37
+ import java.io.UnsupportedEncodingException;
38
+ import java.nio.ByteBuffer;
39
+ import java.util.ArrayList;
40
+ import java.util.Collection;
41
+ import java.util.Iterator;
42
+ import java.util.List;
43
+ import java.util.NoSuchElementException;
44
+
45
+ /**
46
+ * Immutable sequence of bytes. Substring is supported by sharing the reference
47
+ * to the immutable underlying bytes, as with {@link String}. Concatenation is
48
+ * likewise supported without copying (long strings) by building a tree of
49
+ * pieces in {@link RopeByteString}.
50
+ * <p>
51
+ * Like {@link String}, the contents of a {@link ByteString} can never be
52
+ * observed to change, not even in the presence of a data race or incorrect
53
+ * API usage in the client code.
54
+ *
55
+ * @author crazybob@google.com Bob Lee
56
+ * @author kenton@google.com Kenton Varda
57
+ * @author carlanton@google.com Carl Haverl
58
+ * @author martinrb@google.com Martin Buchholz
59
+ */
60
+ public abstract class ByteString implements Iterable<Byte> {
61
+
62
+ /**
63
+ * When two strings to be concatenated have a combined length shorter than
64
+ * this, we just copy their bytes on {@link #concat(ByteString)}.
65
+ * The trade-off is copy size versus the overhead of creating tree nodes
66
+ * in {@link RopeByteString}.
67
+ */
68
+ static final int CONCATENATE_BY_COPY_SIZE = 128;
69
+
70
+ /**
71
+ * When copying an InputStream into a ByteString with .readFrom(),
72
+ * the chunks in the underlying rope start at 256 bytes, but double
73
+ * each iteration up to 8192 bytes.
74
+ */
75
+ static final int MIN_READ_FROM_CHUNK_SIZE = 0x100; // 256b
76
+ static final int MAX_READ_FROM_CHUNK_SIZE = 0x2000; // 8k
77
+
78
+ /**
79
+ * Empty {@code ByteString}.
80
+ */
81
+ public static final ByteString EMPTY = new LiteralByteString(new byte[0]);
82
+
83
+ // This constructor is here to prevent subclassing outside of this package,
84
+ ByteString() {}
85
+
86
+ /**
87
+ * Gets the byte at the given index. This method should be used only for
88
+ * random access to individual bytes. To access bytes sequentially, use the
89
+ * {@link ByteIterator} returned by {@link #iterator()}, and call {@link
90
+ * #substring(int, int)} first if necessary.
91
+ *
92
+ * @param index index of byte
93
+ * @return the value
94
+ * @throws ArrayIndexOutOfBoundsException {@code index} is < 0 or >= size
95
+ */
96
+ public abstract byte byteAt(int index);
97
+
98
+ /**
99
+ * Return a {@link ByteString.ByteIterator} over the bytes in the ByteString.
100
+ * To avoid auto-boxing, you may get the iterator manually and call
101
+ * {@link ByteIterator#nextByte()}.
102
+ *
103
+ * @return the iterator
104
+ */
105
+ public abstract ByteIterator iterator();
106
+
107
+ /**
108
+ * This interface extends {@code Iterator<Byte>}, so that we can return an
109
+ * unboxed {@code byte}.
110
+ */
111
+ public interface ByteIterator extends Iterator<Byte> {
112
+ /**
113
+ * An alternative to {@link Iterator#next()} that returns an
114
+ * unboxed primitive {@code byte}.
115
+ *
116
+ * @return the next {@code byte} in the iteration
117
+ * @throws NoSuchElementException if the iteration has no more elements
118
+ */
119
+ byte nextByte();
120
+ }
121
+
122
+ /**
123
+ * Gets the number of bytes.
124
+ *
125
+ * @return size in bytes
126
+ */
127
+ public abstract int size();
128
+
129
+ /**
130
+ * Returns {@code true} if the size is {@code 0}, {@code false} otherwise.
131
+ *
132
+ * @return true if this is zero bytes long
133
+ */
134
+ public boolean isEmpty() {
135
+ return size() == 0;
136
+ }
137
+
138
+ // =================================================================
139
+ // ByteString -> substring
140
+
141
+ /**
142
+ * Return the substring from {@code beginIndex}, inclusive, to the end of the
143
+ * string.
144
+ *
145
+ * @param beginIndex start at this index
146
+ * @return substring sharing underlying data
147
+ * @throws IndexOutOfBoundsException if {@code beginIndex < 0} or
148
+ * {@code beginIndex > size()}.
149
+ */
150
+ public ByteString substring(int beginIndex) {
151
+ return substring(beginIndex, size());
152
+ }
153
+
154
+ /**
155
+ * Return the substring from {@code beginIndex}, inclusive, to {@code
156
+ * endIndex}, exclusive.
157
+ *
158
+ * @param beginIndex start at this index
159
+ * @param endIndex the last character is the one before this index
160
+ * @return substring sharing underlying data
161
+ * @throws IndexOutOfBoundsException if {@code beginIndex < 0},
162
+ * {@code endIndex > size()}, or {@code beginIndex > endIndex}.
163
+ */
164
+ public abstract ByteString substring(int beginIndex, int endIndex);
165
+
166
+ /**
167
+ * Tests if this bytestring starts with the specified prefix.
168
+ * Similar to {@link String#startsWith(String)}
169
+ *
170
+ * @param prefix the prefix.
171
+ * @return <code>true</code> if the byte sequence represented by the
172
+ * argument is a prefix of the byte sequence represented by
173
+ * this string; <code>false</code> otherwise.
174
+ */
175
+ public boolean startsWith(ByteString prefix) {
176
+ return size() >= prefix.size() &&
177
+ substring(0, prefix.size()).equals(prefix);
178
+ }
179
+
180
+ /**
181
+ * Tests if this bytestring ends with the specified suffix.
182
+ * Similar to {@link String#endsWith(String)}
183
+ *
184
+ * @param suffix the suffix.
185
+ * @return <code>true</code> if the byte sequence represented by the
186
+ * argument is a suffix of the byte sequence represented by
187
+ * this string; <code>false</code> otherwise.
188
+ */
189
+ public boolean endsWith(ByteString suffix) {
190
+ return size() >= suffix.size() &&
191
+ substring(size() - suffix.size()).equals(suffix);
192
+ }
193
+
194
+ // =================================================================
195
+ // byte[] -> ByteString
196
+
197
+ /**
198
+ * Copies the given bytes into a {@code ByteString}.
199
+ *
200
+ * @param bytes source array
201
+ * @param offset offset in source array
202
+ * @param size number of bytes to copy
203
+ * @return new {@code ByteString}
204
+ */
205
+ public static ByteString copyFrom(byte[] bytes, int offset, int size) {
206
+ byte[] copy = new byte[size];
207
+ System.arraycopy(bytes, offset, copy, 0, size);
208
+ return new LiteralByteString(copy);
209
+ }
210
+
211
+ /**
212
+ * Copies the given bytes into a {@code ByteString}.
213
+ *
214
+ * @param bytes to copy
215
+ * @return new {@code ByteString}
216
+ */
217
+ public static ByteString copyFrom(byte[] bytes) {
218
+ return copyFrom(bytes, 0, bytes.length);
219
+ }
220
+
221
+ /**
222
+ * Copies the next {@code size} bytes from a {@code java.nio.ByteBuffer} into
223
+ * a {@code ByteString}.
224
+ *
225
+ * @param bytes source buffer
226
+ * @param size number of bytes to copy
227
+ * @return new {@code ByteString}
228
+ */
229
+ public static ByteString copyFrom(ByteBuffer bytes, int size) {
230
+ byte[] copy = new byte[size];
231
+ bytes.get(copy);
232
+ return new LiteralByteString(copy);
233
+ }
234
+
235
+ /**
236
+ * Copies the remaining bytes from a {@code java.nio.ByteBuffer} into
237
+ * a {@code ByteString}.
238
+ *
239
+ * @param bytes sourceBuffer
240
+ * @return new {@code ByteString}
241
+ */
242
+ public static ByteString copyFrom(ByteBuffer bytes) {
243
+ return copyFrom(bytes, bytes.remaining());
244
+ }
245
+
246
+ /**
247
+ * Encodes {@code text} into a sequence of bytes using the named charset
248
+ * and returns the result as a {@code ByteString}.
249
+ *
250
+ * @param text source string
251
+ * @param charsetName encoding to use
252
+ * @return new {@code ByteString}
253
+ * @throws UnsupportedEncodingException if the encoding isn't found
254
+ */
255
+ public static ByteString copyFrom(String text, String charsetName)
256
+ throws UnsupportedEncodingException {
257
+ return new LiteralByteString(text.getBytes(charsetName));
258
+ }
259
+
260
+ /**
261
+ * Encodes {@code text} into a sequence of UTF-8 bytes and returns the
262
+ * result as a {@code ByteString}.
263
+ *
264
+ * @param text source string
265
+ * @return new {@code ByteString}
266
+ */
267
+ public static ByteString copyFromUtf8(String text) {
268
+ try {
269
+ return new LiteralByteString(text.getBytes("UTF-8"));
270
+ } catch (UnsupportedEncodingException e) {
271
+ throw new RuntimeException("UTF-8 not supported?", e);
272
+ }
273
+ }
274
+
275
+ // =================================================================
276
+ // InputStream -> ByteString
277
+
278
+ /**
279
+ * Completely reads the given stream's bytes into a
280
+ * {@code ByteString}, blocking if necessary until all bytes are
281
+ * read through to the end of the stream.
282
+ *
283
+ * <b>Performance notes:</b> The returned {@code ByteString} is an
284
+ * immutable tree of byte arrays ("chunks") of the stream data. The
285
+ * first chunk is small, with subsequent chunks each being double
286
+ * the size, up to 8K. If the caller knows the precise length of
287
+ * the stream and wishes to avoid all unnecessary copies and
288
+ * allocations, consider using the two-argument version of this
289
+ * method, below.
290
+ *
291
+ * @param streamToDrain The source stream, which is read completely
292
+ * but not closed.
293
+ * @return A new {@code ByteString} which is made up of chunks of
294
+ * various sizes, depending on the behavior of the underlying
295
+ * stream.
296
+ * @throws IOException IOException is thrown if there is a problem
297
+ * reading the underlying stream.
298
+ */
299
+ public static ByteString readFrom(InputStream streamToDrain)
300
+ throws IOException {
301
+ return readFrom(
302
+ streamToDrain, MIN_READ_FROM_CHUNK_SIZE, MAX_READ_FROM_CHUNK_SIZE);
303
+ }
304
+
305
+ /**
306
+ * Completely reads the given stream's bytes into a
307
+ * {@code ByteString}, blocking if necessary until all bytes are
308
+ * read through to the end of the stream.
309
+ *
310
+ * <b>Performance notes:</b> The returned {@code ByteString} is an
311
+ * immutable tree of byte arrays ("chunks") of the stream data. The
312
+ * chunkSize parameter sets the size of these byte arrays. In
313
+ * particular, if the chunkSize is precisely the same as the length
314
+ * of the stream, unnecessary allocations and copies will be
315
+ * avoided. Otherwise, the chunks will be of the given size, except
316
+ * for the last chunk, which will be resized (via a reallocation and
317
+ * copy) to contain the remainder of the stream.
318
+ *
319
+ * @param streamToDrain The source stream, which is read completely
320
+ * but not closed.
321
+ * @param chunkSize The size of the chunks in which to read the
322
+ * stream.
323
+ * @return A new {@code ByteString} which is made up of chunks of
324
+ * the given size.
325
+ * @throws IOException IOException is thrown if there is a problem
326
+ * reading the underlying stream.
327
+ */
328
+ public static ByteString readFrom(InputStream streamToDrain, int chunkSize)
329
+ throws IOException {
330
+ return readFrom(streamToDrain, chunkSize, chunkSize);
331
+ }
332
+
333
+ // Helper method that takes the chunk size range as a parameter.
334
+ public static ByteString readFrom(InputStream streamToDrain, int minChunkSize,
335
+ int maxChunkSize) throws IOException {
336
+ Collection<ByteString> results = new ArrayList<ByteString>();
337
+
338
+ // copy the inbound bytes into a list of chunks; the chunk size
339
+ // grows exponentially to support both short and long streams.
340
+ int chunkSize = minChunkSize;
341
+ while (true) {
342
+ ByteString chunk = readChunk(streamToDrain, chunkSize);
343
+ if (chunk == null) {
344
+ break;
345
+ }
346
+ results.add(chunk);
347
+ chunkSize = Math.min(chunkSize * 2, maxChunkSize);
348
+ }
349
+
350
+ return ByteString.copyFrom(results);
351
+ }
352
+
353
+ /**
354
+ * Blocks until a chunk of the given size can be made from the
355
+ * stream, or EOF is reached. Calls read() repeatedly in case the
356
+ * given stream implementation doesn't completely fill the given
357
+ * buffer in one read() call.
358
+ *
359
+ * @return A chunk of the desired size, or else a chunk as large as
360
+ * was available when end of stream was reached. Returns null if the
361
+ * given stream had no more data in it.
362
+ */
363
+ private static ByteString readChunk(InputStream in, final int chunkSize)
364
+ throws IOException {
365
+ final byte[] buf = new byte[chunkSize];
366
+ int bytesRead = 0;
367
+ while (bytesRead < chunkSize) {
368
+ final int count = in.read(buf, bytesRead, chunkSize - bytesRead);
369
+ if (count == -1) {
370
+ break;
371
+ }
372
+ bytesRead += count;
373
+ }
374
+
375
+ if (bytesRead == 0) {
376
+ return null;
377
+ } else {
378
+ return ByteString.copyFrom(buf, 0, bytesRead);
379
+ }
380
+ }
381
+
382
+ // =================================================================
383
+ // Multiple ByteStrings -> One ByteString
384
+
385
+ /**
386
+ * Concatenate the given {@code ByteString} to this one. Short concatenations,
387
+ * of total size smaller than {@link ByteString#CONCATENATE_BY_COPY_SIZE}, are
388
+ * produced by copying the underlying bytes (as per Rope.java, <a
389
+ * href="http://www.cs.ubc.ca/local/reading/proceedings/spe91-95/spe/vol25/issue12/spe986.pdf">
390
+ * BAP95 </a>. In general, the concatenate involves no copying.
391
+ *
392
+ * @param other string to concatenate
393
+ * @return a new {@code ByteString} instance
394
+ */
395
+ public ByteString concat(ByteString other) {
396
+ int thisSize = size();
397
+ int otherSize = other.size();
398
+ if ((long) thisSize + otherSize >= Integer.MAX_VALUE) {
399
+ throw new IllegalArgumentException("ByteString would be too long: " +
400
+ thisSize + "+" + otherSize);
401
+ }
402
+
403
+ return RopeByteString.concatenate(this, other);
404
+ }
405
+
406
+ /**
407
+ * Concatenates all byte strings in the iterable and returns the result.
408
+ * This is designed to run in O(list size), not O(total bytes).
409
+ *
410
+ * <p>The returned {@code ByteString} is not necessarily a unique object.
411
+ * If the list is empty, the returned object is the singleton empty
412
+ * {@code ByteString}. If the list has only one element, that
413
+ * {@code ByteString} will be returned without copying.
414
+ *
415
+ * @param byteStrings strings to be concatenated
416
+ * @return new {@code ByteString}
417
+ */
418
+ public static ByteString copyFrom(Iterable<ByteString> byteStrings) {
419
+ Collection<ByteString> collection;
420
+ if (!(byteStrings instanceof Collection)) {
421
+ collection = new ArrayList<ByteString>();
422
+ for (ByteString byteString : byteStrings) {
423
+ collection.add(byteString);
424
+ }
425
+ } else {
426
+ collection = (Collection<ByteString>) byteStrings;
427
+ }
428
+ ByteString result;
429
+ if (collection.isEmpty()) {
430
+ result = EMPTY;
431
+ } else {
432
+ result = balancedConcat(collection.iterator(), collection.size());
433
+ }
434
+ return result;
435
+ }
436
+
437
+ // Internal function used by copyFrom(Iterable<ByteString>).
438
+ // Create a balanced concatenation of the next "length" elements from the
439
+ // iterable.
440
+ private static ByteString balancedConcat(Iterator<ByteString> iterator,
441
+ int length) {
442
+ assert length >= 1;
443
+ ByteString result;
444
+ if (length == 1) {
445
+ result = iterator.next();
446
+ } else {
447
+ int halfLength = length >>> 1;
448
+ ByteString left = balancedConcat(iterator, halfLength);
449
+ ByteString right = balancedConcat(iterator, length - halfLength);
450
+ result = left.concat(right);
451
+ }
452
+ return result;
453
+ }
454
+
455
+ // =================================================================
456
+ // ByteString -> byte[]
457
+
458
+ /**
459
+ * Copies bytes into a buffer at the given offset.
460
+ *
461
+ * @param target buffer to copy into
462
+ * @param offset in the target buffer
463
+ * @throws IndexOutOfBoundsException if the offset is negative or too large
464
+ */
465
+ public void copyTo(byte[] target, int offset) {
466
+ copyTo(target, 0, offset, size());
467
+ }
468
+
469
+ /**
470
+ * Copies bytes into a buffer.
471
+ *
472
+ * @param target buffer to copy into
473
+ * @param sourceOffset offset within these bytes
474
+ * @param targetOffset offset within the target buffer
475
+ * @param numberToCopy number of bytes to copy
476
+ * @throws IndexOutOfBoundsException if an offset or size is negative or too
477
+ * large
478
+ */
479
+ public void copyTo(byte[] target, int sourceOffset, int targetOffset,
480
+ int numberToCopy) {
481
+ if (sourceOffset < 0) {
482
+ throw new IndexOutOfBoundsException("Source offset < 0: " + sourceOffset);
483
+ }
484
+ if (targetOffset < 0) {
485
+ throw new IndexOutOfBoundsException("Target offset < 0: " + targetOffset);
486
+ }
487
+ if (numberToCopy < 0) {
488
+ throw new IndexOutOfBoundsException("Length < 0: " + numberToCopy);
489
+ }
490
+ if (sourceOffset + numberToCopy > size()) {
491
+ throw new IndexOutOfBoundsException(
492
+ "Source end offset < 0: " + (sourceOffset + numberToCopy));
493
+ }
494
+ if (targetOffset + numberToCopy > target.length) {
495
+ throw new IndexOutOfBoundsException(
496
+ "Target end offset < 0: " + (targetOffset + numberToCopy));
497
+ }
498
+ if (numberToCopy > 0) {
499
+ copyToInternal(target, sourceOffset, targetOffset, numberToCopy);
500
+ }
501
+ }
502
+
503
+ /**
504
+ * Internal (package private) implementation of
505
+ * @link{#copyTo(byte[],int,int,int}.
506
+ * It assumes that all error checking has already been performed and that
507
+ * @code{numberToCopy > 0}.
508
+ */
509
+ protected abstract void copyToInternal(byte[] target, int sourceOffset,
510
+ int targetOffset, int numberToCopy);
511
+
512
+ /**
513
+ * Copies bytes into a ByteBuffer.
514
+ *
515
+ * @param target ByteBuffer to copy into.
516
+ * @throws java.nio.ReadOnlyBufferException if the {@code target} is read-only
517
+ * @throws java.nio.BufferOverflowException if the {@code target}'s
518
+ * remaining() space is not large enough to hold the data.
519
+ */
520
+ public abstract void copyTo(ByteBuffer target);
521
+
522
+ /**
523
+ * Copies bytes to a {@code byte[]}.
524
+ *
525
+ * @return copied bytes
526
+ */
527
+ public byte[] toByteArray() {
528
+ int size = size();
529
+ if (size == 0) {
530
+ return Internal.EMPTY_BYTE_ARRAY;
531
+ }
532
+ byte[] result = new byte[size];
533
+ copyToInternal(result, 0, 0, size);
534
+ return result;
535
+ }
536
+
537
+ /**
538
+ * Writes the complete contents of this byte string to
539
+ * the specified output stream argument.
540
+ *
541
+ * @param out the output stream to which to write the data.
542
+ * @throws IOException if an I/O error occurs.
543
+ */
544
+ public abstract void writeTo(OutputStream out) throws IOException;
545
+
546
+ /**
547
+ * Writes a specified part of this byte string to an output stream.
548
+ *
549
+ * @param out the output stream to which to write the data.
550
+ * @param sourceOffset offset within these bytes
551
+ * @param numberToWrite number of bytes to write
552
+ * @throws IOException if an I/O error occurs.
553
+ * @throws IndexOutOfBoundsException if an offset or size is negative or too
554
+ * large
555
+ */
556
+ void writeTo(OutputStream out, int sourceOffset, int numberToWrite)
557
+ throws IOException {
558
+ if (sourceOffset < 0) {
559
+ throw new IndexOutOfBoundsException("Source offset < 0: " + sourceOffset);
560
+ }
561
+ if (numberToWrite < 0) {
562
+ throw new IndexOutOfBoundsException("Length < 0: " + numberToWrite);
563
+ }
564
+ if (sourceOffset + numberToWrite > size()) {
565
+ throw new IndexOutOfBoundsException(
566
+ "Source end offset exceeded: " + (sourceOffset + numberToWrite));
567
+ }
568
+ if (numberToWrite > 0) {
569
+ writeToInternal(out, sourceOffset, numberToWrite);
570
+ }
571
+
572
+ }
573
+
574
+ /**
575
+ * Internal version of {@link #writeTo(OutputStream,int,int)} that assumes
576
+ * all error checking has already been done.
577
+ */
578
+ abstract void writeToInternal(OutputStream out, int sourceOffset,
579
+ int numberToWrite) throws IOException;
580
+
581
+ /**
582
+ * Constructs a read-only {@code java.nio.ByteBuffer} whose content
583
+ * is equal to the contents of this byte string.
584
+ * The result uses the same backing array as the byte string, if possible.
585
+ *
586
+ * @return wrapped bytes
587
+ */
588
+ public abstract ByteBuffer asReadOnlyByteBuffer();
589
+
590
+ /**
591
+ * Constructs a list of read-only {@code java.nio.ByteBuffer} objects
592
+ * such that the concatenation of their contents is equal to the contents
593
+ * of this byte string. The result uses the same backing arrays as the
594
+ * byte string.
595
+ * <p>
596
+ * By returning a list, implementations of this method may be able to avoid
597
+ * copying even when there are multiple backing arrays.
598
+ *
599
+ * @return a list of wrapped bytes
600
+ */
601
+ public abstract List<ByteBuffer> asReadOnlyByteBufferList();
602
+
603
+ /**
604
+ * Constructs a new {@code String} by decoding the bytes using the
605
+ * specified charset.
606
+ *
607
+ * @param charsetName encode using this charset
608
+ * @return new string
609
+ * @throws UnsupportedEncodingException if charset isn't recognized
610
+ */
611
+ public abstract String toString(String charsetName)
612
+ throws UnsupportedEncodingException;
613
+
614
+ // =================================================================
615
+ // UTF-8 decoding
616
+
617
+ /**
618
+ * Constructs a new {@code String} by decoding the bytes as UTF-8.
619
+ *
620
+ * @return new string using UTF-8 encoding
621
+ */
622
+ public String toStringUtf8() {
623
+ try {
624
+ return toString("UTF-8");
625
+ } catch (UnsupportedEncodingException e) {
626
+ throw new RuntimeException("UTF-8 not supported?", e);
627
+ }
628
+ }
629
+
630
+ /**
631
+ * Tells whether this {@code ByteString} represents a well-formed UTF-8
632
+ * byte sequence, such that the original bytes can be converted to a
633
+ * String object and then round tripped back to bytes without loss.
634
+ *
635
+ * <p>More precisely, returns {@code true} whenever: <pre> {@code
636
+ * Arrays.equals(byteString.toByteArray(),
637
+ * new String(byteString.toByteArray(), "UTF-8").getBytes("UTF-8"))
638
+ * }</pre>
639
+ *
640
+ * <p>This method returns {@code false} for "overlong" byte sequences,
641
+ * as well as for 3-byte sequences that would map to a surrogate
642
+ * character, in accordance with the restricted definition of UTF-8
643
+ * introduced in Unicode 3.1. Note that the UTF-8 decoder included in
644
+ * Oracle's JDK has been modified to also reject "overlong" byte
645
+ * sequences, but (as of 2011) still accepts 3-byte surrogate
646
+ * character byte sequences.
647
+ *
648
+ * <p>See the Unicode Standard,</br>
649
+ * Table 3-6. <em>UTF-8 Bit Distribution</em>,</br>
650
+ * Table 3-7. <em>Well Formed UTF-8 Byte Sequences</em>.
651
+ *
652
+ * @return whether the bytes in this {@code ByteString} are a
653
+ * well-formed UTF-8 byte sequence
654
+ */
655
+ public abstract boolean isValidUtf8();
656
+
657
+ /**
658
+ * Tells whether the given byte sequence is a well-formed, malformed, or
659
+ * incomplete UTF-8 byte sequence. This method accepts and returns a partial
660
+ * state result, allowing the bytes for a complete UTF-8 byte sequence to be
661
+ * composed from multiple {@code ByteString} segments.
662
+ *
663
+ * @param state either {@code 0} (if this is the initial decoding operation)
664
+ * or the value returned from a call to a partial decoding method for the
665
+ * previous bytes
666
+ * @param offset offset of the first byte to check
667
+ * @param length number of bytes to check
668
+ *
669
+ * @return {@code -1} if the partial byte sequence is definitely malformed,
670
+ * {@code 0} if it is well-formed (no additional input needed), or, if the
671
+ * byte sequence is "incomplete", i.e. apparently terminated in the middle of
672
+ * a character, an opaque integer "state" value containing enough information
673
+ * to decode the character when passed to a subsequent invocation of a
674
+ * partial decoding method.
675
+ */
676
+ protected abstract int partialIsValidUtf8(int state, int offset, int length);
677
+
678
+ // =================================================================
679
+ // equals() and hashCode()
680
+
681
+ @Override
682
+ public abstract boolean equals(Object o);
683
+
684
+ /**
685
+ * Return a non-zero hashCode depending only on the sequence of bytes
686
+ * in this ByteString.
687
+ *
688
+ * @return hashCode value for this object
689
+ */
690
+ @Override
691
+ public abstract int hashCode();
692
+
693
+ // =================================================================
694
+ // Input stream
695
+
696
+ /**
697
+ * Creates an {@code InputStream} which can be used to read the bytes.
698
+ * <p>
699
+ * The {@link InputStream} returned by this method is guaranteed to be
700
+ * completely non-blocking. The method {@link InputStream#available()}
701
+ * returns the number of bytes remaining in the stream. The methods
702
+ * {@link InputStream#read(byte[]), {@link InputStream#read(byte[],int,int)}
703
+ * and {@link InputStream#skip(long)} will read/skip as many bytes as are
704
+ * available.
705
+ * <p>
706
+ * The methods in the returned {@link InputStream} might <b>not</b> be
707
+ * thread safe.
708
+ *
709
+ * @return an input stream that returns the bytes of this byte string.
710
+ */
711
+ public abstract InputStream newInput();
712
+
713
+ /**
714
+ * Creates a {@link CodedInputStream} which can be used to read the bytes.
715
+ * Using this is often more efficient than creating a {@link CodedInputStream}
716
+ * that wraps the result of {@link #newInput()}.
717
+ *
718
+ * @return stream based on wrapped data
719
+ */
720
+ public abstract CodedInputStream newCodedInput();
721
+
722
+ // =================================================================
723
+ // Output stream
724
+
725
+ /**
726
+ * Creates a new {@link Output} with the given initial capacity. Call {@link
727
+ * Output#toByteString()} to create the {@code ByteString} instance.
728
+ * <p>
729
+ * A {@link ByteString.Output} offers the same functionality as a
730
+ * {@link ByteArrayOutputStream}, except that it returns a {@link ByteString}
731
+ * rather than a {@code byte} array.
732
+ *
733
+ * @param initialCapacity estimate of number of bytes to be written
734
+ * @return {@code OutputStream} for building a {@code ByteString}
735
+ */
736
+ public static Output newOutput(int initialCapacity) {
737
+ return new Output(initialCapacity);
738
+ }
739
+
740
+ /**
741
+ * Creates a new {@link Output}. Call {@link Output#toByteString()} to create
742
+ * the {@code ByteString} instance.
743
+ * <p>
744
+ * A {@link ByteString.Output} offers the same functionality as a
745
+ * {@link ByteArrayOutputStream}, except that it returns a {@link ByteString}
746
+ * rather than a {@code byte array}.
747
+ *
748
+ * @return {@code OutputStream} for building a {@code ByteString}
749
+ */
750
+ public static Output newOutput() {
751
+ return new Output(CONCATENATE_BY_COPY_SIZE);
752
+ }
753
+
754
+ /**
755
+ * Outputs to a {@code ByteString} instance. Call {@link #toByteString()} to
756
+ * create the {@code ByteString} instance.
757
+ */
758
+ public static final class Output extends OutputStream {
759
+ // Implementation note.
760
+ // The public methods of this class must be synchronized. ByteStrings
761
+ // are guaranteed to be immutable. Without some sort of locking, it could
762
+ // be possible for one thread to call toByteSring(), while another thread
763
+ // is still modifying the underlying byte array.
764
+
765
+ private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
766
+ // argument passed by user, indicating initial capacity.
767
+ private final int initialCapacity;
768
+ // ByteStrings to be concatenated to create the result
769
+ private final ArrayList<ByteString> flushedBuffers;
770
+ // Total number of bytes in the ByteStrings of flushedBuffers
771
+ private int flushedBuffersTotalBytes;
772
+ // Current buffer to which we are writing
773
+ private byte[] buffer;
774
+ // Location in buffer[] to which we write the next byte.
775
+ private int bufferPos;
776
+
777
+ /**
778
+ * Creates a new ByteString output stream with the specified
779
+ * initial capacity.
780
+ *
781
+ * @param initialCapacity the initial capacity of the output stream.
782
+ */
783
+ Output(int initialCapacity) {
784
+ if (initialCapacity < 0) {
785
+ throw new IllegalArgumentException("Buffer size < 0");
786
+ }
787
+ this.initialCapacity = initialCapacity;
788
+ this.flushedBuffers = new ArrayList<ByteString>();
789
+ this.buffer = new byte[initialCapacity];
790
+ }
791
+
792
+ @Override
793
+ public synchronized void write(int b) {
794
+ if (bufferPos == buffer.length) {
795
+ flushFullBuffer(1);
796
+ }
797
+ buffer[bufferPos++] = (byte)b;
798
+ }
799
+
800
+ @Override
801
+ public synchronized void write(byte[] b, int offset, int length) {
802
+ if (length <= buffer.length - bufferPos) {
803
+ // The bytes can fit into the current buffer.
804
+ System.arraycopy(b, offset, buffer, bufferPos, length);
805
+ bufferPos += length;
806
+ } else {
807
+ // Use up the current buffer
808
+ int copySize = buffer.length - bufferPos;
809
+ System.arraycopy(b, offset, buffer, bufferPos, copySize);
810
+ offset += copySize;
811
+ length -= copySize;
812
+ // Flush the buffer, and get a new buffer at least big enough to cover
813
+ // what we still need to output
814
+ flushFullBuffer(length);
815
+ System.arraycopy(b, offset, buffer, 0 /* count */, length);
816
+ bufferPos = length;
817
+ }
818
+ }
819
+
820
+ /**
821
+ * Creates a byte string. Its size is the current size of this output
822
+ * stream and its output has been copied to it.
823
+ *
824
+ * @return the current contents of this output stream, as a byte string.
825
+ */
826
+ public synchronized ByteString toByteString() {
827
+ flushLastBuffer();
828
+ return ByteString.copyFrom(flushedBuffers);
829
+ }
830
+
831
+ /**
832
+ * Implement java.util.Arrays.copyOf() for jdk 1.5.
833
+ */
834
+ private byte[] copyArray(byte[] buffer, int length) {
835
+ byte[] result = new byte[length];
836
+ System.arraycopy(buffer, 0, result, 0, Math.min(buffer.length, length));
837
+ return result;
838
+ }
839
+
840
+ /**
841
+ * Writes the complete contents of this byte array output stream to
842
+ * the specified output stream argument.
843
+ *
844
+ * @param out the output stream to which to write the data.
845
+ * @throws IOException if an I/O error occurs.
846
+ */
847
+ public void writeTo(OutputStream out) throws IOException {
848
+ ByteString[] cachedFlushBuffers;
849
+ byte[] cachedBuffer;
850
+ int cachedBufferPos;
851
+ synchronized (this) {
852
+ // Copy the information we need into local variables so as to hold
853
+ // the lock for as short a time as possible.
854
+ cachedFlushBuffers =
855
+ flushedBuffers.toArray(new ByteString[flushedBuffers.size()]);
856
+ cachedBuffer = buffer;
857
+ cachedBufferPos = bufferPos;
858
+ }
859
+ for (ByteString byteString : cachedFlushBuffers) {
860
+ byteString.writeTo(out);
861
+ }
862
+
863
+ out.write(copyArray(cachedBuffer, cachedBufferPos));
864
+ }
865
+
866
+ /**
867
+ * Returns the current size of the output stream.
868
+ *
869
+ * @return the current size of the output stream
870
+ */
871
+ public synchronized int size() {
872
+ return flushedBuffersTotalBytes + bufferPos;
873
+ }
874
+
875
+ /**
876
+ * Resets this stream, so that all currently accumulated output in the
877
+ * output stream is discarded. The output stream can be used again,
878
+ * reusing the already allocated buffer space.
879
+ */
880
+ public synchronized void reset() {
881
+ flushedBuffers.clear();
882
+ flushedBuffersTotalBytes = 0;
883
+ bufferPos = 0;
884
+ }
885
+
886
+ @Override
887
+ public String toString() {
888
+ return String.format("<ByteString.Output@%s size=%d>",
889
+ Integer.toHexString(System.identityHashCode(this)), size());
890
+ }
891
+
892
+ /**
893
+ * Internal function used by writers. The current buffer is full, and the
894
+ * writer needs a new buffer whose size is at least the specified minimum
895
+ * size.
896
+ */
897
+ private void flushFullBuffer(int minSize) {
898
+ flushedBuffers.add(new LiteralByteString(buffer));
899
+ flushedBuffersTotalBytes += buffer.length;
900
+ // We want to increase our total capacity by 50%, but as a minimum,
901
+ // the new buffer should also at least be >= minSize and
902
+ // >= initial Capacity.
903
+ int newSize = Math.max(initialCapacity,
904
+ Math.max(minSize, flushedBuffersTotalBytes >>> 1));
905
+ buffer = new byte[newSize];
906
+ bufferPos = 0;
907
+ }
908
+
909
+ /**
910
+ * Internal function used by {@link #toByteString()}. The current buffer may
911
+ * or may not be full, but it needs to be flushed.
912
+ */
913
+ private void flushLastBuffer() {
914
+ if (bufferPos < buffer.length) {
915
+ if (bufferPos > 0) {
916
+ byte[] bufferCopy = copyArray(buffer, bufferPos);
917
+ flushedBuffers.add(new LiteralByteString(bufferCopy));
918
+ }
919
+ // We reuse this buffer for further writes.
920
+ } else {
921
+ // Buffer is completely full. Huzzah.
922
+ flushedBuffers.add(new LiteralByteString(buffer));
923
+ // 99% of the time, we're not going to use this OutputStream again.
924
+ // We set buffer to an empty byte stream so that we're handling this
925
+ // case without wasting space. In the rare case that more writes
926
+ // *do* occur, this empty buffer will be flushed and an appropriately
927
+ // sized new buffer will be created.
928
+ buffer = EMPTY_BYTE_ARRAY;
929
+ }
930
+ flushedBuffersTotalBytes += bufferPos;
931
+ bufferPos = 0;
932
+ }
933
+ }
934
+
935
+ /**
936
+ * Constructs a new {@code ByteString} builder, which allows you to
937
+ * efficiently construct a {@code ByteString} by writing to a {@link
938
+ * CodedOutputStream}. Using this is much more efficient than calling {@code
939
+ * newOutput()} and wrapping that in a {@code CodedOutputStream}.
940
+ *
941
+ * <p>This is package-private because it's a somewhat confusing interface.
942
+ * Users can call {@link Message#toByteString()} instead of calling this
943
+ * directly.
944
+ *
945
+ * @param size The target byte size of the {@code ByteString}. You must write
946
+ * exactly this many bytes before building the result.
947
+ * @return the builder
948
+ */
949
+ static CodedBuilder newCodedBuilder(int size) {
950
+ return new CodedBuilder(size);
951
+ }
952
+
953
+ /** See {@link ByteString#newCodedBuilder(int)}. */
954
+ static final class CodedBuilder {
955
+ private final CodedOutputStream output;
956
+ private final byte[] buffer;
957
+
958
+ private CodedBuilder(int size) {
959
+ buffer = new byte[size];
960
+ output = CodedOutputStream.newInstance(buffer);
961
+ }
962
+
963
+ public ByteString build() {
964
+ output.checkNoSpaceLeft();
965
+
966
+ // We can be confident that the CodedOutputStream will not modify the
967
+ // underlying bytes anymore because it already wrote all of them. So,
968
+ // no need to make a copy.
969
+ return new LiteralByteString(buffer);
970
+ }
971
+
972
+ public CodedOutputStream getCodedOutput() {
973
+ return output;
974
+ }
975
+ }
976
+
977
+ // =================================================================
978
+ // Methods {@link RopeByteString} needs on instances, which aren't part of the
979
+ // public API.
980
+
981
+ /**
982
+ * Return the depth of the tree representing this {@code ByteString}, if any,
983
+ * whose root is this node. If this is a leaf node, return 0.
984
+ *
985
+ * @return tree depth or zero
986
+ */
987
+ protected abstract int getTreeDepth();
988
+
989
+ /**
990
+ * Return {@code true} if this ByteString is literal (a leaf node) or a
991
+ * flat-enough tree in the sense of {@link RopeByteString}.
992
+ *
993
+ * @return true if the tree is flat enough
994
+ */
995
+ protected abstract boolean isBalanced();
996
+
997
+ /**
998
+ * Return the cached hash code if available.
999
+ *
1000
+ * @return value of cached hash code or 0 if not computed yet
1001
+ */
1002
+ protected abstract int peekCachedHashCode();
1003
+
1004
+ /**
1005
+ * Compute the hash across the value bytes starting with the given hash, and
1006
+ * return the result. This is used to compute the hash across strings
1007
+ * represented as a set of pieces by allowing the hash computation to be
1008
+ * continued from piece to piece.
1009
+ *
1010
+ * @param h starting hash value
1011
+ * @param offset offset into this value to start looking at data values
1012
+ * @param length number of data values to include in the hash computation
1013
+ * @return ending hash value
1014
+ */
1015
+ protected abstract int partialHash(int h, int offset, int length);
1016
+
1017
+ @Override
1018
+ public String toString() {
1019
+ return String.format("<ByteString@%s size=%d>",
1020
+ Integer.toHexString(System.identityHashCode(this)), size());
1021
+ }
1022
+ }