@point3/node-rdkafka 3.6.0-1

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 (707) hide show
  1. package/LICENSE.txt +20 -0
  2. package/README.md +636 -0
  3. package/binding.gyp +154 -0
  4. package/deps/librdkafka/.clang-format +136 -0
  5. package/deps/librdkafka/.clang-format-cpp +103 -0
  6. package/deps/librdkafka/.dir-locals.el +10 -0
  7. package/deps/librdkafka/.formatignore +33 -0
  8. package/deps/librdkafka/.gdbmacros +19 -0
  9. package/deps/librdkafka/.github/CODEOWNERS +1 -0
  10. package/deps/librdkafka/.github/ISSUE_TEMPLATE +34 -0
  11. package/deps/librdkafka/.semaphore/run-all-tests.yml +77 -0
  12. package/deps/librdkafka/.semaphore/semaphore-integration.yml +250 -0
  13. package/deps/librdkafka/.semaphore/semaphore.yml +378 -0
  14. package/deps/librdkafka/.semaphore/verify-linux-packages.yml +41 -0
  15. package/deps/librdkafka/CHANGELOG.md +2208 -0
  16. package/deps/librdkafka/CMakeLists.txt +291 -0
  17. package/deps/librdkafka/CODE_OF_CONDUCT.md +46 -0
  18. package/deps/librdkafka/CONFIGURATION.md +209 -0
  19. package/deps/librdkafka/CONTRIBUTING.md +431 -0
  20. package/deps/librdkafka/Doxyfile +2375 -0
  21. package/deps/librdkafka/INTRODUCTION.md +2481 -0
  22. package/deps/librdkafka/LICENSE +26 -0
  23. package/deps/librdkafka/LICENSE.cjson +22 -0
  24. package/deps/librdkafka/LICENSE.crc32c +28 -0
  25. package/deps/librdkafka/LICENSE.fnv1a +18 -0
  26. package/deps/librdkafka/LICENSE.hdrhistogram +27 -0
  27. package/deps/librdkafka/LICENSE.lz4 +26 -0
  28. package/deps/librdkafka/LICENSE.murmur2 +25 -0
  29. package/deps/librdkafka/LICENSE.nanopb +22 -0
  30. package/deps/librdkafka/LICENSE.opentelemetry +203 -0
  31. package/deps/librdkafka/LICENSE.pycrc +23 -0
  32. package/deps/librdkafka/LICENSE.queue +31 -0
  33. package/deps/librdkafka/LICENSE.regexp +5 -0
  34. package/deps/librdkafka/LICENSE.snappy +36 -0
  35. package/deps/librdkafka/LICENSE.tinycthread +26 -0
  36. package/deps/librdkafka/LICENSE.wingetopt +49 -0
  37. package/deps/librdkafka/LICENSES.txt +625 -0
  38. package/deps/librdkafka/Makefile +125 -0
  39. package/deps/librdkafka/README.md +199 -0
  40. package/deps/librdkafka/README.win32 +26 -0
  41. package/deps/librdkafka/STATISTICS.md +624 -0
  42. package/deps/librdkafka/configure +214 -0
  43. package/deps/librdkafka/configure.self +331 -0
  44. package/deps/librdkafka/debian/changelog +111 -0
  45. package/deps/librdkafka/debian/compat +1 -0
  46. package/deps/librdkafka/debian/control +71 -0
  47. package/deps/librdkafka/debian/copyright +99 -0
  48. package/deps/librdkafka/debian/gbp.conf +9 -0
  49. package/deps/librdkafka/debian/librdkafka++1.install +1 -0
  50. package/deps/librdkafka/debian/librdkafka-dev.examples +2 -0
  51. package/deps/librdkafka/debian/librdkafka-dev.install +9 -0
  52. package/deps/librdkafka/debian/librdkafka1.docs +5 -0
  53. package/deps/librdkafka/debian/librdkafka1.install +1 -0
  54. package/deps/librdkafka/debian/librdkafka1.symbols +135 -0
  55. package/deps/librdkafka/debian/rules +19 -0
  56. package/deps/librdkafka/debian/source/format +1 -0
  57. package/deps/librdkafka/debian/watch +2 -0
  58. package/deps/librdkafka/dev-conf.sh +123 -0
  59. package/deps/librdkafka/examples/CMakeLists.txt +79 -0
  60. package/deps/librdkafka/examples/Makefile +167 -0
  61. package/deps/librdkafka/examples/README.md +42 -0
  62. package/deps/librdkafka/examples/alter_consumer_group_offsets.c +338 -0
  63. package/deps/librdkafka/examples/consumer.c +271 -0
  64. package/deps/librdkafka/examples/delete_records.c +233 -0
  65. package/deps/librdkafka/examples/describe_cluster.c +322 -0
  66. package/deps/librdkafka/examples/describe_consumer_groups.c +455 -0
  67. package/deps/librdkafka/examples/describe_topics.c +427 -0
  68. package/deps/librdkafka/examples/elect_leaders.c +317 -0
  69. package/deps/librdkafka/examples/globals.json +11 -0
  70. package/deps/librdkafka/examples/idempotent_producer.c +344 -0
  71. package/deps/librdkafka/examples/incremental_alter_configs.c +347 -0
  72. package/deps/librdkafka/examples/kafkatest_verifiable_client.cpp +945 -0
  73. package/deps/librdkafka/examples/list_consumer_group_offsets.c +359 -0
  74. package/deps/librdkafka/examples/list_consumer_groups.c +365 -0
  75. package/deps/librdkafka/examples/list_offsets.c +327 -0
  76. package/deps/librdkafka/examples/misc.c +287 -0
  77. package/deps/librdkafka/examples/openssl_engine_example.cpp +248 -0
  78. package/deps/librdkafka/examples/producer.c +251 -0
  79. package/deps/librdkafka/examples/producer.cpp +228 -0
  80. package/deps/librdkafka/examples/rdkafka_complex_consumer_example.c +617 -0
  81. package/deps/librdkafka/examples/rdkafka_complex_consumer_example.cpp +467 -0
  82. package/deps/librdkafka/examples/rdkafka_consume_batch.cpp +264 -0
  83. package/deps/librdkafka/examples/rdkafka_example.c +853 -0
  84. package/deps/librdkafka/examples/rdkafka_example.cpp +679 -0
  85. package/deps/librdkafka/examples/rdkafka_performance.c +1781 -0
  86. package/deps/librdkafka/examples/transactions-older-broker.c +668 -0
  87. package/deps/librdkafka/examples/transactions.c +665 -0
  88. package/deps/librdkafka/examples/user_scram.c +491 -0
  89. package/deps/librdkafka/examples/win_ssl_cert_store.cpp +396 -0
  90. package/deps/librdkafka/lds-gen.py +73 -0
  91. package/deps/librdkafka/mainpage.doxy +40 -0
  92. package/deps/librdkafka/mklove/Makefile.base +329 -0
  93. package/deps/librdkafka/mklove/modules/configure.atomics +144 -0
  94. package/deps/librdkafka/mklove/modules/configure.base +2484 -0
  95. package/deps/librdkafka/mklove/modules/configure.builtin +70 -0
  96. package/deps/librdkafka/mklove/modules/configure.cc +186 -0
  97. package/deps/librdkafka/mklove/modules/configure.cxx +8 -0
  98. package/deps/librdkafka/mklove/modules/configure.fileversion +65 -0
  99. package/deps/librdkafka/mklove/modules/configure.gitversion +29 -0
  100. package/deps/librdkafka/mklove/modules/configure.good_cflags +18 -0
  101. package/deps/librdkafka/mklove/modules/configure.host +132 -0
  102. package/deps/librdkafka/mklove/modules/configure.lib +49 -0
  103. package/deps/librdkafka/mklove/modules/configure.libcurl +99 -0
  104. package/deps/librdkafka/mklove/modules/configure.libsasl2 +36 -0
  105. package/deps/librdkafka/mklove/modules/configure.libssl +147 -0
  106. package/deps/librdkafka/mklove/modules/configure.libzstd +58 -0
  107. package/deps/librdkafka/mklove/modules/configure.parseversion +95 -0
  108. package/deps/librdkafka/mklove/modules/configure.pic +16 -0
  109. package/deps/librdkafka/mklove/modules/configure.socket +20 -0
  110. package/deps/librdkafka/mklove/modules/configure.zlib +61 -0
  111. package/deps/librdkafka/mklove/modules/patches/README.md +8 -0
  112. package/deps/librdkafka/mklove/modules/patches/libcurl.0000-no-runtime-linking-check.patch +11 -0
  113. package/deps/librdkafka/mklove/modules/patches/libssl.0000-osx-rand-include-fix-OpenSSL-PR16409.patch +56 -0
  114. package/deps/librdkafka/packaging/RELEASE.md +319 -0
  115. package/deps/librdkafka/packaging/alpine/build-alpine.sh +38 -0
  116. package/deps/librdkafka/packaging/archlinux/PKGBUILD +30 -0
  117. package/deps/librdkafka/packaging/cmake/Config.cmake.in +37 -0
  118. package/deps/librdkafka/packaging/cmake/Modules/FindLZ4.cmake +38 -0
  119. package/deps/librdkafka/packaging/cmake/Modules/FindZSTD.cmake +27 -0
  120. package/deps/librdkafka/packaging/cmake/Modules/LICENSE.FindZstd +178 -0
  121. package/deps/librdkafka/packaging/cmake/README.md +38 -0
  122. package/deps/librdkafka/packaging/cmake/config.h.in +52 -0
  123. package/deps/librdkafka/packaging/cmake/parseversion.cmake +60 -0
  124. package/deps/librdkafka/packaging/cmake/rdkafka.pc.in +12 -0
  125. package/deps/librdkafka/packaging/cmake/try_compile/atomic_32_test.c +8 -0
  126. package/deps/librdkafka/packaging/cmake/try_compile/atomic_64_test.c +8 -0
  127. package/deps/librdkafka/packaging/cmake/try_compile/c11threads_test.c +14 -0
  128. package/deps/librdkafka/packaging/cmake/try_compile/crc32c_hw_test.c +27 -0
  129. package/deps/librdkafka/packaging/cmake/try_compile/dlopen_test.c +11 -0
  130. package/deps/librdkafka/packaging/cmake/try_compile/libsasl2_test.c +7 -0
  131. package/deps/librdkafka/packaging/cmake/try_compile/pthread_setname_darwin_test.c +6 -0
  132. package/deps/librdkafka/packaging/cmake/try_compile/pthread_setname_freebsd_test.c +7 -0
  133. package/deps/librdkafka/packaging/cmake/try_compile/pthread_setname_gnu_test.c +5 -0
  134. package/deps/librdkafka/packaging/cmake/try_compile/rand_r_test.c +7 -0
  135. package/deps/librdkafka/packaging/cmake/try_compile/rdkafka_setup.cmake +122 -0
  136. package/deps/librdkafka/packaging/cmake/try_compile/regex_test.c +10 -0
  137. package/deps/librdkafka/packaging/cmake/try_compile/strndup_test.c +5 -0
  138. package/deps/librdkafka/packaging/cmake/try_compile/sync_32_test.c +8 -0
  139. package/deps/librdkafka/packaging/cmake/try_compile/sync_64_test.c +8 -0
  140. package/deps/librdkafka/packaging/cp/README.md +16 -0
  141. package/deps/librdkafka/packaging/cp/check_features.c +72 -0
  142. package/deps/librdkafka/packaging/cp/verify-deb.sh +33 -0
  143. package/deps/librdkafka/packaging/cp/verify-packages.sh +69 -0
  144. package/deps/librdkafka/packaging/cp/verify-rpm.sh +32 -0
  145. package/deps/librdkafka/packaging/debian/changelog +66 -0
  146. package/deps/librdkafka/packaging/debian/compat +1 -0
  147. package/deps/librdkafka/packaging/debian/control +49 -0
  148. package/deps/librdkafka/packaging/debian/copyright +84 -0
  149. package/deps/librdkafka/packaging/debian/docs +5 -0
  150. package/deps/librdkafka/packaging/debian/gbp.conf +9 -0
  151. package/deps/librdkafka/packaging/debian/librdkafka-dev.dirs +2 -0
  152. package/deps/librdkafka/packaging/debian/librdkafka-dev.examples +2 -0
  153. package/deps/librdkafka/packaging/debian/librdkafka-dev.install +6 -0
  154. package/deps/librdkafka/packaging/debian/librdkafka-dev.substvars +1 -0
  155. package/deps/librdkafka/packaging/debian/librdkafka.dsc +16 -0
  156. package/deps/librdkafka/packaging/debian/librdkafka1-dbg.substvars +1 -0
  157. package/deps/librdkafka/packaging/debian/librdkafka1.dirs +1 -0
  158. package/deps/librdkafka/packaging/debian/librdkafka1.install +2 -0
  159. package/deps/librdkafka/packaging/debian/librdkafka1.postinst.debhelper +5 -0
  160. package/deps/librdkafka/packaging/debian/librdkafka1.postrm.debhelper +5 -0
  161. package/deps/librdkafka/packaging/debian/librdkafka1.symbols +64 -0
  162. package/deps/librdkafka/packaging/debian/rules +19 -0
  163. package/deps/librdkafka/packaging/debian/source/format +1 -0
  164. package/deps/librdkafka/packaging/debian/watch +2 -0
  165. package/deps/librdkafka/packaging/get_version.py +21 -0
  166. package/deps/librdkafka/packaging/homebrew/README.md +15 -0
  167. package/deps/librdkafka/packaging/homebrew/brew-update-pr.sh +31 -0
  168. package/deps/librdkafka/packaging/mingw-w64/configure-build-msys2-mingw-static.sh +52 -0
  169. package/deps/librdkafka/packaging/mingw-w64/configure-build-msys2-mingw.sh +21 -0
  170. package/deps/librdkafka/packaging/mingw-w64/export-variables.sh +13 -0
  171. package/deps/librdkafka/packaging/mingw-w64/run-tests.sh +6 -0
  172. package/deps/librdkafka/packaging/mingw-w64/semaphoreci-build.sh +38 -0
  173. package/deps/librdkafka/packaging/nuget/README.md +84 -0
  174. package/deps/librdkafka/packaging/nuget/artifact.py +177 -0
  175. package/deps/librdkafka/packaging/nuget/cleanup-s3.py +143 -0
  176. package/deps/librdkafka/packaging/nuget/common/p-common__plat-windows__arch-win32__bldtype-Release/msvcr120.zip +0 -0
  177. package/deps/librdkafka/packaging/nuget/common/p-common__plat-windows__arch-win32__bldtype-Release/msvcr140.zip +0 -0
  178. package/deps/librdkafka/packaging/nuget/common/p-common__plat-windows__arch-x64__bldtype-Release/msvcr120.zip +0 -0
  179. package/deps/librdkafka/packaging/nuget/common/p-common__plat-windows__arch-x64__bldtype-Release/msvcr140.zip +0 -0
  180. package/deps/librdkafka/packaging/nuget/nuget.sh +21 -0
  181. package/deps/librdkafka/packaging/nuget/nugetpackage.py +278 -0
  182. package/deps/librdkafka/packaging/nuget/packaging.py +448 -0
  183. package/deps/librdkafka/packaging/nuget/push-to-nuget.sh +21 -0
  184. package/deps/librdkafka/packaging/nuget/release.py +167 -0
  185. package/deps/librdkafka/packaging/nuget/requirements.txt +3 -0
  186. package/deps/librdkafka/packaging/nuget/staticpackage.py +178 -0
  187. package/deps/librdkafka/packaging/nuget/templates/librdkafka.redist.nuspec +21 -0
  188. package/deps/librdkafka/packaging/nuget/templates/librdkafka.redist.props +18 -0
  189. package/deps/librdkafka/packaging/nuget/templates/librdkafka.redist.targets +19 -0
  190. package/deps/librdkafka/packaging/nuget/zfile/__init__.py +0 -0
  191. package/deps/librdkafka/packaging/nuget/zfile/zfile.py +98 -0
  192. package/deps/librdkafka/packaging/rpm/Makefile +92 -0
  193. package/deps/librdkafka/packaging/rpm/README.md +23 -0
  194. package/deps/librdkafka/packaging/rpm/el7-x86_64.cfg +40 -0
  195. package/deps/librdkafka/packaging/rpm/librdkafka.spec +118 -0
  196. package/deps/librdkafka/packaging/rpm/mock-on-docker.sh +96 -0
  197. package/deps/librdkafka/packaging/rpm/tests/Makefile +25 -0
  198. package/deps/librdkafka/packaging/rpm/tests/README.md +8 -0
  199. package/deps/librdkafka/packaging/rpm/tests/run-test.sh +42 -0
  200. package/deps/librdkafka/packaging/rpm/tests/test-on-docker.sh +56 -0
  201. package/deps/librdkafka/packaging/rpm/tests/test.c +77 -0
  202. package/deps/librdkafka/packaging/rpm/tests/test.cpp +34 -0
  203. package/deps/librdkafka/packaging/tools/Dockerfile +31 -0
  204. package/deps/librdkafka/packaging/tools/build-configurations-checks.sh +12 -0
  205. package/deps/librdkafka/packaging/tools/build-deb-package.sh +64 -0
  206. package/deps/librdkafka/packaging/tools/build-debian.sh +65 -0
  207. package/deps/librdkafka/packaging/tools/build-manylinux.sh +68 -0
  208. package/deps/librdkafka/packaging/tools/build-release-artifacts.sh +139 -0
  209. package/deps/librdkafka/packaging/tools/distro-build.sh +38 -0
  210. package/deps/librdkafka/packaging/tools/gh-release-checksums.py +39 -0
  211. package/deps/librdkafka/packaging/tools/rdutcoverage.sh +25 -0
  212. package/deps/librdkafka/packaging/tools/requirements.txt +2 -0
  213. package/deps/librdkafka/packaging/tools/run-in-docker.sh +28 -0
  214. package/deps/librdkafka/packaging/tools/run-integration-tests.sh +31 -0
  215. package/deps/librdkafka/packaging/tools/run-style-check.sh +4 -0
  216. package/deps/librdkafka/packaging/tools/style-format.sh +149 -0
  217. package/deps/librdkafka/packaging/tools/update_rpcs_max_versions.py +100 -0
  218. package/deps/librdkafka/service.yml +172 -0
  219. package/deps/librdkafka/src/CMakeLists.txt +374 -0
  220. package/deps/librdkafka/src/Makefile +103 -0
  221. package/deps/librdkafka/src/README.lz4.md +30 -0
  222. package/deps/librdkafka/src/cJSON.c +2834 -0
  223. package/deps/librdkafka/src/cJSON.h +398 -0
  224. package/deps/librdkafka/src/crc32c.c +430 -0
  225. package/deps/librdkafka/src/crc32c.h +38 -0
  226. package/deps/librdkafka/src/generate_proto.sh +66 -0
  227. package/deps/librdkafka/src/librdkafka_cgrp_synch.png +0 -0
  228. package/deps/librdkafka/src/lz4.c +2727 -0
  229. package/deps/librdkafka/src/lz4.h +842 -0
  230. package/deps/librdkafka/src/lz4frame.c +2078 -0
  231. package/deps/librdkafka/src/lz4frame.h +692 -0
  232. package/deps/librdkafka/src/lz4frame_static.h +47 -0
  233. package/deps/librdkafka/src/lz4hc.c +1631 -0
  234. package/deps/librdkafka/src/lz4hc.h +413 -0
  235. package/deps/librdkafka/src/nanopb/pb.h +917 -0
  236. package/deps/librdkafka/src/nanopb/pb_common.c +388 -0
  237. package/deps/librdkafka/src/nanopb/pb_common.h +49 -0
  238. package/deps/librdkafka/src/nanopb/pb_decode.c +1727 -0
  239. package/deps/librdkafka/src/nanopb/pb_decode.h +193 -0
  240. package/deps/librdkafka/src/nanopb/pb_encode.c +1000 -0
  241. package/deps/librdkafka/src/nanopb/pb_encode.h +185 -0
  242. package/deps/librdkafka/src/opentelemetry/common.pb.c +32 -0
  243. package/deps/librdkafka/src/opentelemetry/common.pb.h +170 -0
  244. package/deps/librdkafka/src/opentelemetry/metrics.options +2 -0
  245. package/deps/librdkafka/src/opentelemetry/metrics.pb.c +67 -0
  246. package/deps/librdkafka/src/opentelemetry/metrics.pb.h +966 -0
  247. package/deps/librdkafka/src/opentelemetry/resource.pb.c +12 -0
  248. package/deps/librdkafka/src/opentelemetry/resource.pb.h +58 -0
  249. package/deps/librdkafka/src/queue.h +850 -0
  250. package/deps/librdkafka/src/rd.h +584 -0
  251. package/deps/librdkafka/src/rdaddr.c +255 -0
  252. package/deps/librdkafka/src/rdaddr.h +202 -0
  253. package/deps/librdkafka/src/rdatomic.h +230 -0
  254. package/deps/librdkafka/src/rdavg.h +260 -0
  255. package/deps/librdkafka/src/rdavl.c +210 -0
  256. package/deps/librdkafka/src/rdavl.h +250 -0
  257. package/deps/librdkafka/src/rdbase64.c +200 -0
  258. package/deps/librdkafka/src/rdbase64.h +43 -0
  259. package/deps/librdkafka/src/rdbuf.c +1884 -0
  260. package/deps/librdkafka/src/rdbuf.h +375 -0
  261. package/deps/librdkafka/src/rdcrc32.c +114 -0
  262. package/deps/librdkafka/src/rdcrc32.h +170 -0
  263. package/deps/librdkafka/src/rddl.c +179 -0
  264. package/deps/librdkafka/src/rddl.h +43 -0
  265. package/deps/librdkafka/src/rdendian.h +175 -0
  266. package/deps/librdkafka/src/rdfloat.h +67 -0
  267. package/deps/librdkafka/src/rdfnv1a.c +113 -0
  268. package/deps/librdkafka/src/rdfnv1a.h +35 -0
  269. package/deps/librdkafka/src/rdgz.c +120 -0
  270. package/deps/librdkafka/src/rdgz.h +46 -0
  271. package/deps/librdkafka/src/rdhdrhistogram.c +721 -0
  272. package/deps/librdkafka/src/rdhdrhistogram.h +87 -0
  273. package/deps/librdkafka/src/rdhttp.c +830 -0
  274. package/deps/librdkafka/src/rdhttp.h +101 -0
  275. package/deps/librdkafka/src/rdinterval.h +177 -0
  276. package/deps/librdkafka/src/rdkafka.c +5505 -0
  277. package/deps/librdkafka/src/rdkafka.h +10686 -0
  278. package/deps/librdkafka/src/rdkafka_admin.c +9794 -0
  279. package/deps/librdkafka/src/rdkafka_admin.h +661 -0
  280. package/deps/librdkafka/src/rdkafka_assignment.c +1010 -0
  281. package/deps/librdkafka/src/rdkafka_assignment.h +73 -0
  282. package/deps/librdkafka/src/rdkafka_assignor.c +1786 -0
  283. package/deps/librdkafka/src/rdkafka_assignor.h +402 -0
  284. package/deps/librdkafka/src/rdkafka_aux.c +409 -0
  285. package/deps/librdkafka/src/rdkafka_aux.h +174 -0
  286. package/deps/librdkafka/src/rdkafka_background.c +221 -0
  287. package/deps/librdkafka/src/rdkafka_broker.c +6337 -0
  288. package/deps/librdkafka/src/rdkafka_broker.h +744 -0
  289. package/deps/librdkafka/src/rdkafka_buf.c +543 -0
  290. package/deps/librdkafka/src/rdkafka_buf.h +1525 -0
  291. package/deps/librdkafka/src/rdkafka_cert.c +576 -0
  292. package/deps/librdkafka/src/rdkafka_cert.h +62 -0
  293. package/deps/librdkafka/src/rdkafka_cgrp.c +7587 -0
  294. package/deps/librdkafka/src/rdkafka_cgrp.h +477 -0
  295. package/deps/librdkafka/src/rdkafka_conf.c +4880 -0
  296. package/deps/librdkafka/src/rdkafka_conf.h +732 -0
  297. package/deps/librdkafka/src/rdkafka_confval.h +97 -0
  298. package/deps/librdkafka/src/rdkafka_coord.c +623 -0
  299. package/deps/librdkafka/src/rdkafka_coord.h +132 -0
  300. package/deps/librdkafka/src/rdkafka_error.c +228 -0
  301. package/deps/librdkafka/src/rdkafka_error.h +80 -0
  302. package/deps/librdkafka/src/rdkafka_event.c +502 -0
  303. package/deps/librdkafka/src/rdkafka_event.h +126 -0
  304. package/deps/librdkafka/src/rdkafka_feature.c +898 -0
  305. package/deps/librdkafka/src/rdkafka_feature.h +104 -0
  306. package/deps/librdkafka/src/rdkafka_fetcher.c +1422 -0
  307. package/deps/librdkafka/src/rdkafka_fetcher.h +44 -0
  308. package/deps/librdkafka/src/rdkafka_header.c +220 -0
  309. package/deps/librdkafka/src/rdkafka_header.h +76 -0
  310. package/deps/librdkafka/src/rdkafka_idempotence.c +807 -0
  311. package/deps/librdkafka/src/rdkafka_idempotence.h +144 -0
  312. package/deps/librdkafka/src/rdkafka_int.h +1260 -0
  313. package/deps/librdkafka/src/rdkafka_interceptor.c +819 -0
  314. package/deps/librdkafka/src/rdkafka_interceptor.h +104 -0
  315. package/deps/librdkafka/src/rdkafka_lz4.c +450 -0
  316. package/deps/librdkafka/src/rdkafka_lz4.h +49 -0
  317. package/deps/librdkafka/src/rdkafka_metadata.c +2209 -0
  318. package/deps/librdkafka/src/rdkafka_metadata.h +345 -0
  319. package/deps/librdkafka/src/rdkafka_metadata_cache.c +1183 -0
  320. package/deps/librdkafka/src/rdkafka_mock.c +3661 -0
  321. package/deps/librdkafka/src/rdkafka_mock.h +610 -0
  322. package/deps/librdkafka/src/rdkafka_mock_cgrp.c +1876 -0
  323. package/deps/librdkafka/src/rdkafka_mock_handlers.c +3113 -0
  324. package/deps/librdkafka/src/rdkafka_mock_int.h +710 -0
  325. package/deps/librdkafka/src/rdkafka_msg.c +2589 -0
  326. package/deps/librdkafka/src/rdkafka_msg.h +614 -0
  327. package/deps/librdkafka/src/rdkafka_msgbatch.h +62 -0
  328. package/deps/librdkafka/src/rdkafka_msgset.h +98 -0
  329. package/deps/librdkafka/src/rdkafka_msgset_reader.c +1806 -0
  330. package/deps/librdkafka/src/rdkafka_msgset_writer.c +1474 -0
  331. package/deps/librdkafka/src/rdkafka_offset.c +1565 -0
  332. package/deps/librdkafka/src/rdkafka_offset.h +150 -0
  333. package/deps/librdkafka/src/rdkafka_op.c +997 -0
  334. package/deps/librdkafka/src/rdkafka_op.h +858 -0
  335. package/deps/librdkafka/src/rdkafka_partition.c +4896 -0
  336. package/deps/librdkafka/src/rdkafka_partition.h +1182 -0
  337. package/deps/librdkafka/src/rdkafka_pattern.c +228 -0
  338. package/deps/librdkafka/src/rdkafka_pattern.h +70 -0
  339. package/deps/librdkafka/src/rdkafka_plugin.c +213 -0
  340. package/deps/librdkafka/src/rdkafka_plugin.h +41 -0
  341. package/deps/librdkafka/src/rdkafka_proto.h +736 -0
  342. package/deps/librdkafka/src/rdkafka_protocol.h +128 -0
  343. package/deps/librdkafka/src/rdkafka_queue.c +1230 -0
  344. package/deps/librdkafka/src/rdkafka_queue.h +1220 -0
  345. package/deps/librdkafka/src/rdkafka_range_assignor.c +1748 -0
  346. package/deps/librdkafka/src/rdkafka_request.c +7089 -0
  347. package/deps/librdkafka/src/rdkafka_request.h +732 -0
  348. package/deps/librdkafka/src/rdkafka_roundrobin_assignor.c +123 -0
  349. package/deps/librdkafka/src/rdkafka_sasl.c +530 -0
  350. package/deps/librdkafka/src/rdkafka_sasl.h +63 -0
  351. package/deps/librdkafka/src/rdkafka_sasl_cyrus.c +722 -0
  352. package/deps/librdkafka/src/rdkafka_sasl_int.h +89 -0
  353. package/deps/librdkafka/src/rdkafka_sasl_oauthbearer.c +1833 -0
  354. package/deps/librdkafka/src/rdkafka_sasl_oauthbearer.h +52 -0
  355. package/deps/librdkafka/src/rdkafka_sasl_oauthbearer_oidc.c +1666 -0
  356. package/deps/librdkafka/src/rdkafka_sasl_oauthbearer_oidc.h +47 -0
  357. package/deps/librdkafka/src/rdkafka_sasl_plain.c +142 -0
  358. package/deps/librdkafka/src/rdkafka_sasl_scram.c +858 -0
  359. package/deps/librdkafka/src/rdkafka_sasl_win32.c +550 -0
  360. package/deps/librdkafka/src/rdkafka_ssl.c +2129 -0
  361. package/deps/librdkafka/src/rdkafka_ssl.h +86 -0
  362. package/deps/librdkafka/src/rdkafka_sticky_assignor.c +4785 -0
  363. package/deps/librdkafka/src/rdkafka_subscription.c +278 -0
  364. package/deps/librdkafka/src/rdkafka_telemetry.c +760 -0
  365. package/deps/librdkafka/src/rdkafka_telemetry.h +52 -0
  366. package/deps/librdkafka/src/rdkafka_telemetry_decode.c +1053 -0
  367. package/deps/librdkafka/src/rdkafka_telemetry_decode.h +59 -0
  368. package/deps/librdkafka/src/rdkafka_telemetry_encode.c +997 -0
  369. package/deps/librdkafka/src/rdkafka_telemetry_encode.h +301 -0
  370. package/deps/librdkafka/src/rdkafka_timer.c +402 -0
  371. package/deps/librdkafka/src/rdkafka_timer.h +117 -0
  372. package/deps/librdkafka/src/rdkafka_topic.c +2161 -0
  373. package/deps/librdkafka/src/rdkafka_topic.h +334 -0
  374. package/deps/librdkafka/src/rdkafka_transport.c +1309 -0
  375. package/deps/librdkafka/src/rdkafka_transport.h +99 -0
  376. package/deps/librdkafka/src/rdkafka_transport_int.h +100 -0
  377. package/deps/librdkafka/src/rdkafka_txnmgr.c +3256 -0
  378. package/deps/librdkafka/src/rdkafka_txnmgr.h +171 -0
  379. package/deps/librdkafka/src/rdkafka_zstd.c +226 -0
  380. package/deps/librdkafka/src/rdkafka_zstd.h +57 -0
  381. package/deps/librdkafka/src/rdlist.c +576 -0
  382. package/deps/librdkafka/src/rdlist.h +434 -0
  383. package/deps/librdkafka/src/rdlog.c +89 -0
  384. package/deps/librdkafka/src/rdlog.h +41 -0
  385. package/deps/librdkafka/src/rdmap.c +508 -0
  386. package/deps/librdkafka/src/rdmap.h +492 -0
  387. package/deps/librdkafka/src/rdmurmur2.c +167 -0
  388. package/deps/librdkafka/src/rdmurmur2.h +35 -0
  389. package/deps/librdkafka/src/rdports.c +61 -0
  390. package/deps/librdkafka/src/rdports.h +38 -0
  391. package/deps/librdkafka/src/rdposix.h +250 -0
  392. package/deps/librdkafka/src/rdrand.c +80 -0
  393. package/deps/librdkafka/src/rdrand.h +43 -0
  394. package/deps/librdkafka/src/rdregex.c +156 -0
  395. package/deps/librdkafka/src/rdregex.h +43 -0
  396. package/deps/librdkafka/src/rdsignal.h +57 -0
  397. package/deps/librdkafka/src/rdstring.c +645 -0
  398. package/deps/librdkafka/src/rdstring.h +98 -0
  399. package/deps/librdkafka/src/rdsysqueue.h +404 -0
  400. package/deps/librdkafka/src/rdtime.h +356 -0
  401. package/deps/librdkafka/src/rdtypes.h +86 -0
  402. package/deps/librdkafka/src/rdunittest.c +549 -0
  403. package/deps/librdkafka/src/rdunittest.h +232 -0
  404. package/deps/librdkafka/src/rdvarint.c +134 -0
  405. package/deps/librdkafka/src/rdvarint.h +165 -0
  406. package/deps/librdkafka/src/rdwin32.h +382 -0
  407. package/deps/librdkafka/src/rdxxhash.c +1030 -0
  408. package/deps/librdkafka/src/rdxxhash.h +328 -0
  409. package/deps/librdkafka/src/regexp.c +1352 -0
  410. package/deps/librdkafka/src/regexp.h +41 -0
  411. package/deps/librdkafka/src/snappy.c +1866 -0
  412. package/deps/librdkafka/src/snappy.h +62 -0
  413. package/deps/librdkafka/src/snappy_compat.h +138 -0
  414. package/deps/librdkafka/src/statistics_schema.json +444 -0
  415. package/deps/librdkafka/src/tinycthread.c +932 -0
  416. package/deps/librdkafka/src/tinycthread.h +503 -0
  417. package/deps/librdkafka/src/tinycthread_extra.c +199 -0
  418. package/deps/librdkafka/src/tinycthread_extra.h +212 -0
  419. package/deps/librdkafka/src/win32_config.h +58 -0
  420. package/deps/librdkafka/src-cpp/CMakeLists.txt +90 -0
  421. package/deps/librdkafka/src-cpp/ConfImpl.cpp +84 -0
  422. package/deps/librdkafka/src-cpp/ConsumerImpl.cpp +244 -0
  423. package/deps/librdkafka/src-cpp/HandleImpl.cpp +436 -0
  424. package/deps/librdkafka/src-cpp/HeadersImpl.cpp +48 -0
  425. package/deps/librdkafka/src-cpp/KafkaConsumerImpl.cpp +296 -0
  426. package/deps/librdkafka/src-cpp/Makefile +55 -0
  427. package/deps/librdkafka/src-cpp/MessageImpl.cpp +38 -0
  428. package/deps/librdkafka/src-cpp/MetadataImpl.cpp +170 -0
  429. package/deps/librdkafka/src-cpp/ProducerImpl.cpp +197 -0
  430. package/deps/librdkafka/src-cpp/QueueImpl.cpp +70 -0
  431. package/deps/librdkafka/src-cpp/README.md +16 -0
  432. package/deps/librdkafka/src-cpp/RdKafka.cpp +59 -0
  433. package/deps/librdkafka/src-cpp/TopicImpl.cpp +124 -0
  434. package/deps/librdkafka/src-cpp/TopicPartitionImpl.cpp +57 -0
  435. package/deps/librdkafka/src-cpp/rdkafkacpp.h +3797 -0
  436. package/deps/librdkafka/src-cpp/rdkafkacpp_int.h +1641 -0
  437. package/deps/librdkafka/tests/0000-unittests.c +72 -0
  438. package/deps/librdkafka/tests/0001-multiobj.c +102 -0
  439. package/deps/librdkafka/tests/0002-unkpart.c +244 -0
  440. package/deps/librdkafka/tests/0003-msgmaxsize.c +173 -0
  441. package/deps/librdkafka/tests/0004-conf.c +934 -0
  442. package/deps/librdkafka/tests/0005-order.c +133 -0
  443. package/deps/librdkafka/tests/0006-symbols.c +163 -0
  444. package/deps/librdkafka/tests/0007-autotopic.c +136 -0
  445. package/deps/librdkafka/tests/0008-reqacks.c +179 -0
  446. package/deps/librdkafka/tests/0009-mock_cluster.c +97 -0
  447. package/deps/librdkafka/tests/0011-produce_batch.c +753 -0
  448. package/deps/librdkafka/tests/0012-produce_consume.c +537 -0
  449. package/deps/librdkafka/tests/0013-null-msgs.c +473 -0
  450. package/deps/librdkafka/tests/0014-reconsume-191.c +512 -0
  451. package/deps/librdkafka/tests/0015-offset_seeks.c +172 -0
  452. package/deps/librdkafka/tests/0016-client_swname.c +181 -0
  453. package/deps/librdkafka/tests/0017-compression.c +140 -0
  454. package/deps/librdkafka/tests/0018-cgrp_term.c +338 -0
  455. package/deps/librdkafka/tests/0019-list_groups.c +289 -0
  456. package/deps/librdkafka/tests/0020-destroy_hang.c +162 -0
  457. package/deps/librdkafka/tests/0021-rkt_destroy.c +72 -0
  458. package/deps/librdkafka/tests/0022-consume_batch.c +279 -0
  459. package/deps/librdkafka/tests/0025-timers.c +147 -0
  460. package/deps/librdkafka/tests/0026-consume_pause.c +547 -0
  461. package/deps/librdkafka/tests/0028-long_topicnames.c +79 -0
  462. package/deps/librdkafka/tests/0029-assign_offset.c +202 -0
  463. package/deps/librdkafka/tests/0030-offset_commit.c +589 -0
  464. package/deps/librdkafka/tests/0031-get_offsets.c +235 -0
  465. package/deps/librdkafka/tests/0033-regex_subscribe.c +536 -0
  466. package/deps/librdkafka/tests/0034-offset_reset.c +398 -0
  467. package/deps/librdkafka/tests/0035-api_version.c +73 -0
  468. package/deps/librdkafka/tests/0036-partial_fetch.c +87 -0
  469. package/deps/librdkafka/tests/0037-destroy_hang_local.c +85 -0
  470. package/deps/librdkafka/tests/0038-performance.c +121 -0
  471. package/deps/librdkafka/tests/0039-event.c +284 -0
  472. package/deps/librdkafka/tests/0040-io_event.c +257 -0
  473. package/deps/librdkafka/tests/0041-fetch_max_bytes.c +97 -0
  474. package/deps/librdkafka/tests/0042-many_topics.c +252 -0
  475. package/deps/librdkafka/tests/0043-no_connection.c +77 -0
  476. package/deps/librdkafka/tests/0044-partition_cnt.c +94 -0
  477. package/deps/librdkafka/tests/0045-subscribe_update.c +1010 -0
  478. package/deps/librdkafka/tests/0046-rkt_cache.c +65 -0
  479. package/deps/librdkafka/tests/0047-partial_buf_tmout.c +98 -0
  480. package/deps/librdkafka/tests/0048-partitioner.c +283 -0
  481. package/deps/librdkafka/tests/0049-consume_conn_close.c +162 -0
  482. package/deps/librdkafka/tests/0050-subscribe_adds.c +145 -0
  483. package/deps/librdkafka/tests/0051-assign_adds.c +126 -0
  484. package/deps/librdkafka/tests/0052-msg_timestamps.c +238 -0
  485. package/deps/librdkafka/tests/0053-stats_cb.cpp +527 -0
  486. package/deps/librdkafka/tests/0054-offset_time.cpp +236 -0
  487. package/deps/librdkafka/tests/0055-producer_latency.c +539 -0
  488. package/deps/librdkafka/tests/0056-balanced_group_mt.c +315 -0
  489. package/deps/librdkafka/tests/0057-invalid_topic.cpp +112 -0
  490. package/deps/librdkafka/tests/0058-log.cpp +123 -0
  491. package/deps/librdkafka/tests/0059-bsearch.cpp +241 -0
  492. package/deps/librdkafka/tests/0060-op_prio.cpp +163 -0
  493. package/deps/librdkafka/tests/0061-consumer_lag.cpp +295 -0
  494. package/deps/librdkafka/tests/0062-stats_event.c +126 -0
  495. package/deps/librdkafka/tests/0063-clusterid.cpp +180 -0
  496. package/deps/librdkafka/tests/0064-interceptors.c +481 -0
  497. package/deps/librdkafka/tests/0065-yield.cpp +140 -0
  498. package/deps/librdkafka/tests/0066-plugins.cpp +129 -0
  499. package/deps/librdkafka/tests/0067-empty_topic.cpp +151 -0
  500. package/deps/librdkafka/tests/0068-produce_timeout.c +136 -0
  501. package/deps/librdkafka/tests/0069-consumer_add_parts.c +119 -0
  502. package/deps/librdkafka/tests/0070-null_empty.cpp +197 -0
  503. package/deps/librdkafka/tests/0072-headers_ut.c +448 -0
  504. package/deps/librdkafka/tests/0073-headers.c +381 -0
  505. package/deps/librdkafka/tests/0074-producev.c +87 -0
  506. package/deps/librdkafka/tests/0075-retry.c +290 -0
  507. package/deps/librdkafka/tests/0076-produce_retry.c +452 -0
  508. package/deps/librdkafka/tests/0077-compaction.c +363 -0
  509. package/deps/librdkafka/tests/0078-c_from_cpp.cpp +96 -0
  510. package/deps/librdkafka/tests/0079-fork.c +93 -0
  511. package/deps/librdkafka/tests/0080-admin_ut.c +3095 -0
  512. package/deps/librdkafka/tests/0081-admin.c +5633 -0
  513. package/deps/librdkafka/tests/0082-fetch_max_bytes.cpp +137 -0
  514. package/deps/librdkafka/tests/0083-cb_event.c +233 -0
  515. package/deps/librdkafka/tests/0084-destroy_flags.c +208 -0
  516. package/deps/librdkafka/tests/0085-headers.cpp +392 -0
  517. package/deps/librdkafka/tests/0086-purge.c +368 -0
  518. package/deps/librdkafka/tests/0088-produce_metadata_timeout.c +162 -0
  519. package/deps/librdkafka/tests/0089-max_poll_interval.c +511 -0
  520. package/deps/librdkafka/tests/0090-idempotence.c +171 -0
  521. package/deps/librdkafka/tests/0091-max_poll_interval_timeout.c +295 -0
  522. package/deps/librdkafka/tests/0092-mixed_msgver.c +103 -0
  523. package/deps/librdkafka/tests/0093-holb.c +200 -0
  524. package/deps/librdkafka/tests/0094-idempotence_msg_timeout.c +231 -0
  525. package/deps/librdkafka/tests/0095-all_brokers_down.cpp +122 -0
  526. package/deps/librdkafka/tests/0097-ssl_verify.cpp +658 -0
  527. package/deps/librdkafka/tests/0098-consumer-txn.cpp +1218 -0
  528. package/deps/librdkafka/tests/0099-commit_metadata.c +194 -0
  529. package/deps/librdkafka/tests/0100-thread_interceptors.cpp +195 -0
  530. package/deps/librdkafka/tests/0101-fetch-from-follower.cpp +446 -0
  531. package/deps/librdkafka/tests/0102-static_group_rebalance.c +836 -0
  532. package/deps/librdkafka/tests/0103-transactions.c +1383 -0
  533. package/deps/librdkafka/tests/0104-fetch_from_follower_mock.c +625 -0
  534. package/deps/librdkafka/tests/0105-transactions_mock.c +3930 -0
  535. package/deps/librdkafka/tests/0106-cgrp_sess_timeout.c +318 -0
  536. package/deps/librdkafka/tests/0107-topic_recreate.c +259 -0
  537. package/deps/librdkafka/tests/0109-auto_create_topics.cpp +278 -0
  538. package/deps/librdkafka/tests/0110-batch_size.cpp +182 -0
  539. package/deps/librdkafka/tests/0111-delay_create_topics.cpp +127 -0
  540. package/deps/librdkafka/tests/0112-assign_unknown_part.c +87 -0
  541. package/deps/librdkafka/tests/0113-cooperative_rebalance.cpp +3473 -0
  542. package/deps/librdkafka/tests/0114-sticky_partitioning.cpp +176 -0
  543. package/deps/librdkafka/tests/0115-producer_auth.cpp +182 -0
  544. package/deps/librdkafka/tests/0116-kafkaconsumer_close.cpp +216 -0
  545. package/deps/librdkafka/tests/0117-mock_errors.c +331 -0
  546. package/deps/librdkafka/tests/0118-commit_rebalance.c +154 -0
  547. package/deps/librdkafka/tests/0119-consumer_auth.cpp +167 -0
  548. package/deps/librdkafka/tests/0120-asymmetric_subscription.c +185 -0
  549. package/deps/librdkafka/tests/0121-clusterid.c +115 -0
  550. package/deps/librdkafka/tests/0122-buffer_cleaning_after_rebalance.c +227 -0
  551. package/deps/librdkafka/tests/0123-connections_max_idle.c +98 -0
  552. package/deps/librdkafka/tests/0124-openssl_invalid_engine.c +69 -0
  553. package/deps/librdkafka/tests/0125-immediate_flush.c +144 -0
  554. package/deps/librdkafka/tests/0126-oauthbearer_oidc.c +528 -0
  555. package/deps/librdkafka/tests/0127-fetch_queue_backoff.cpp +165 -0
  556. package/deps/librdkafka/tests/0128-sasl_callback_queue.cpp +125 -0
  557. package/deps/librdkafka/tests/0129-fetch_aborted_msgs.c +79 -0
  558. package/deps/librdkafka/tests/0130-store_offsets.c +178 -0
  559. package/deps/librdkafka/tests/0131-connect_timeout.c +81 -0
  560. package/deps/librdkafka/tests/0132-strategy_ordering.c +179 -0
  561. package/deps/librdkafka/tests/0133-ssl_keys.c +150 -0
  562. package/deps/librdkafka/tests/0134-ssl_provider.c +92 -0
  563. package/deps/librdkafka/tests/0135-sasl_credentials.cpp +143 -0
  564. package/deps/librdkafka/tests/0136-resolve_cb.c +181 -0
  565. package/deps/librdkafka/tests/0137-barrier_batch_consume.c +619 -0
  566. package/deps/librdkafka/tests/0138-admin_mock.c +281 -0
  567. package/deps/librdkafka/tests/0139-offset_validation_mock.c +950 -0
  568. package/deps/librdkafka/tests/0140-commit_metadata.cpp +108 -0
  569. package/deps/librdkafka/tests/0142-reauthentication.c +515 -0
  570. package/deps/librdkafka/tests/0143-exponential_backoff_mock.c +552 -0
  571. package/deps/librdkafka/tests/0144-idempotence_mock.c +373 -0
  572. package/deps/librdkafka/tests/0145-pause_resume_mock.c +119 -0
  573. package/deps/librdkafka/tests/0146-metadata_mock.c +505 -0
  574. package/deps/librdkafka/tests/0147-consumer_group_consumer_mock.c +952 -0
  575. package/deps/librdkafka/tests/0148-offset_fetch_commit_error_mock.c +563 -0
  576. package/deps/librdkafka/tests/0149-broker-same-host-port.c +140 -0
  577. package/deps/librdkafka/tests/0150-telemetry_mock.c +651 -0
  578. package/deps/librdkafka/tests/0151-purge-brokers.c +566 -0
  579. package/deps/librdkafka/tests/0152-rebootstrap.c +59 -0
  580. package/deps/librdkafka/tests/0153-memberid.c +128 -0
  581. package/deps/librdkafka/tests/1000-unktopic.c +164 -0
  582. package/deps/librdkafka/tests/8000-idle.cpp +60 -0
  583. package/deps/librdkafka/tests/8001-fetch_from_follower_mock_manual.c +113 -0
  584. package/deps/librdkafka/tests/CMakeLists.txt +170 -0
  585. package/deps/librdkafka/tests/LibrdkafkaTestApp.py +291 -0
  586. package/deps/librdkafka/tests/Makefile +182 -0
  587. package/deps/librdkafka/tests/README.md +509 -0
  588. package/deps/librdkafka/tests/autotest.sh +33 -0
  589. package/deps/librdkafka/tests/backtrace.gdb +30 -0
  590. package/deps/librdkafka/tests/broker_version_tests.py +315 -0
  591. package/deps/librdkafka/tests/buildbox.sh +17 -0
  592. package/deps/librdkafka/tests/cleanup-checker-tests.sh +20 -0
  593. package/deps/librdkafka/tests/cluster_testing.py +191 -0
  594. package/deps/librdkafka/tests/delete-test-topics.sh +56 -0
  595. package/deps/librdkafka/tests/fixtures/oauthbearer/jwt_assertion_template.json +10 -0
  596. package/deps/librdkafka/tests/fixtures/ssl/Makefile +8 -0
  597. package/deps/librdkafka/tests/fixtures/ssl/README.md +13 -0
  598. package/deps/librdkafka/tests/fixtures/ssl/client.keystore.intermediate.p12 +0 -0
  599. package/deps/librdkafka/tests/fixtures/ssl/client.keystore.p12 +0 -0
  600. package/deps/librdkafka/tests/fixtures/ssl/client2.certificate.intermediate.pem +72 -0
  601. package/deps/librdkafka/tests/fixtures/ssl/client2.certificate.pem +50 -0
  602. package/deps/librdkafka/tests/fixtures/ssl/client2.intermediate.key +46 -0
  603. package/deps/librdkafka/tests/fixtures/ssl/client2.key +46 -0
  604. package/deps/librdkafka/tests/fixtures/ssl/create_keys.sh +168 -0
  605. package/deps/librdkafka/tests/fuzzers/Makefile +12 -0
  606. package/deps/librdkafka/tests/fuzzers/README.md +31 -0
  607. package/deps/librdkafka/tests/fuzzers/fuzz_regex.c +74 -0
  608. package/deps/librdkafka/tests/fuzzers/helpers.h +90 -0
  609. package/deps/librdkafka/tests/gen-ssl-certs.sh +165 -0
  610. package/deps/librdkafka/tests/interactive_broker_version.py +170 -0
  611. package/deps/librdkafka/tests/interceptor_test/CMakeLists.txt +16 -0
  612. package/deps/librdkafka/tests/interceptor_test/Makefile +22 -0
  613. package/deps/librdkafka/tests/interceptor_test/interceptor_test.c +314 -0
  614. package/deps/librdkafka/tests/interceptor_test/interceptor_test.h +54 -0
  615. package/deps/librdkafka/tests/java/IncrementalRebalanceCli.java +97 -0
  616. package/deps/librdkafka/tests/java/Makefile +13 -0
  617. package/deps/librdkafka/tests/java/Murmur2Cli.java +46 -0
  618. package/deps/librdkafka/tests/java/README.md +14 -0
  619. package/deps/librdkafka/tests/java/TransactionProducerCli.java +162 -0
  620. package/deps/librdkafka/tests/java/run-class.sh +11 -0
  621. package/deps/librdkafka/tests/librdkafka.suppressions +483 -0
  622. package/deps/librdkafka/tests/lz4_manual_test.sh +59 -0
  623. package/deps/librdkafka/tests/multi-broker-version-test.sh +50 -0
  624. package/deps/librdkafka/tests/parse-refcnt.sh +43 -0
  625. package/deps/librdkafka/tests/performance_plot.py +115 -0
  626. package/deps/librdkafka/tests/plugin_test/Makefile +19 -0
  627. package/deps/librdkafka/tests/plugin_test/plugin_test.c +58 -0
  628. package/deps/librdkafka/tests/requirements.txt +2 -0
  629. package/deps/librdkafka/tests/run-all-tests.sh +79 -0
  630. package/deps/librdkafka/tests/run-consumer-tests.sh +16 -0
  631. package/deps/librdkafka/tests/run-producer-tests.sh +16 -0
  632. package/deps/librdkafka/tests/run-test-batches.py +157 -0
  633. package/deps/librdkafka/tests/run-test.sh +140 -0
  634. package/deps/librdkafka/tests/rusage.c +249 -0
  635. package/deps/librdkafka/tests/sasl_test.py +289 -0
  636. package/deps/librdkafka/tests/scenarios/README.md +6 -0
  637. package/deps/librdkafka/tests/scenarios/ak23.json +6 -0
  638. package/deps/librdkafka/tests/scenarios/default.json +5 -0
  639. package/deps/librdkafka/tests/scenarios/noautocreate.json +5 -0
  640. package/deps/librdkafka/tests/sockem.c +801 -0
  641. package/deps/librdkafka/tests/sockem.h +85 -0
  642. package/deps/librdkafka/tests/sockem_ctrl.c +145 -0
  643. package/deps/librdkafka/tests/sockem_ctrl.h +61 -0
  644. package/deps/librdkafka/tests/test.c +7778 -0
  645. package/deps/librdkafka/tests/test.conf.example +27 -0
  646. package/deps/librdkafka/tests/test.h +1028 -0
  647. package/deps/librdkafka/tests/testcpp.cpp +131 -0
  648. package/deps/librdkafka/tests/testcpp.h +388 -0
  649. package/deps/librdkafka/tests/testshared.h +416 -0
  650. package/deps/librdkafka/tests/tools/README.md +4 -0
  651. package/deps/librdkafka/tests/tools/stats/README.md +21 -0
  652. package/deps/librdkafka/tests/tools/stats/filter.jq +42 -0
  653. package/deps/librdkafka/tests/tools/stats/graph.py +150 -0
  654. package/deps/librdkafka/tests/tools/stats/requirements.txt +3 -0
  655. package/deps/librdkafka/tests/tools/stats/to_csv.py +124 -0
  656. package/deps/librdkafka/tests/trivup/trivup-0.14.0.tar.gz +0 -0
  657. package/deps/librdkafka/tests/until-fail.sh +87 -0
  658. package/deps/librdkafka/tests/xxxx-assign_partition.c +122 -0
  659. package/deps/librdkafka/tests/xxxx-metadata.cpp +159 -0
  660. package/deps/librdkafka/vcpkg.json +23 -0
  661. package/deps/librdkafka/win32/README.md +5 -0
  662. package/deps/librdkafka/win32/build-package.bat +3 -0
  663. package/deps/librdkafka/win32/build.bat +19 -0
  664. package/deps/librdkafka/win32/common.vcxproj +84 -0
  665. package/deps/librdkafka/win32/interceptor_test/interceptor_test.vcxproj +87 -0
  666. package/deps/librdkafka/win32/librdkafka.autopkg.template +54 -0
  667. package/deps/librdkafka/win32/librdkafka.master.testing.targets +13 -0
  668. package/deps/librdkafka/win32/librdkafka.sln +226 -0
  669. package/deps/librdkafka/win32/librdkafka.vcxproj +276 -0
  670. package/deps/librdkafka/win32/librdkafkacpp/librdkafkacpp.vcxproj +104 -0
  671. package/deps/librdkafka/win32/msbuild.ps1 +15 -0
  672. package/deps/librdkafka/win32/openssl_engine_example/openssl_engine_example.vcxproj +132 -0
  673. package/deps/librdkafka/win32/package-zip.ps1 +46 -0
  674. package/deps/librdkafka/win32/packages/repositories.config +4 -0
  675. package/deps/librdkafka/win32/push-package.bat +4 -0
  676. package/deps/librdkafka/win32/rdkafka_complex_consumer_example_cpp/rdkafka_complex_consumer_example_cpp.vcxproj +67 -0
  677. package/deps/librdkafka/win32/rdkafka_example/rdkafka_example.vcxproj +97 -0
  678. package/deps/librdkafka/win32/rdkafka_performance/rdkafka_performance.vcxproj +97 -0
  679. package/deps/librdkafka/win32/setup-msys2.ps1 +47 -0
  680. package/deps/librdkafka/win32/setup-vcpkg.ps1 +34 -0
  681. package/deps/librdkafka/win32/tests/test.conf.example +25 -0
  682. package/deps/librdkafka/win32/tests/tests.vcxproj +253 -0
  683. package/deps/librdkafka/win32/win_ssl_cert_store/win_ssl_cert_store.vcxproj +132 -0
  684. package/deps/librdkafka/win32/wingetopt.c +564 -0
  685. package/deps/librdkafka/win32/wingetopt.h +101 -0
  686. package/deps/librdkafka/win32/wintime.h +33 -0
  687. package/deps/librdkafka.gyp +62 -0
  688. package/lib/admin.js +233 -0
  689. package/lib/client.js +573 -0
  690. package/lib/error.js +500 -0
  691. package/lib/index.js +34 -0
  692. package/lib/kafka-consumer-stream.js +397 -0
  693. package/lib/kafka-consumer.js +698 -0
  694. package/lib/producer/high-level-producer.js +323 -0
  695. package/lib/producer-stream.js +307 -0
  696. package/lib/producer.js +375 -0
  697. package/lib/tools/ref-counter.js +52 -0
  698. package/lib/topic-partition.js +88 -0
  699. package/lib/topic.js +42 -0
  700. package/lib/util.js +29 -0
  701. package/package.json +61 -0
  702. package/prebuilds/darwin-arm64/@point3+node-rdkafka.node +0 -0
  703. package/prebuilds/linux-x64/@point3+node-rdkafka.node +0 -0
  704. package/util/configure.js +30 -0
  705. package/util/get-env.js +6 -0
  706. package/util/test-compile.js +11 -0
  707. package/util/test-producer-delivery.js +100 -0
@@ -0,0 +1,1866 @@
1
+ /*
2
+ * C port of the snappy compressor from Google.
3
+ * This is a very fast compressor with comparable compression to lzo.
4
+ * Works best on 64bit little-endian, but should be good on others too.
5
+ * Ported by Andi Kleen.
6
+ * Uptodate with snappy 1.1.0
7
+ */
8
+
9
+ /*
10
+ * Copyright 2005 Google Inc. All Rights Reserved.
11
+ *
12
+ * Redistribution and use in source and binary forms, with or without
13
+ * modification, are permitted provided that the following conditions are
14
+ * met:
15
+ *
16
+ * * Redistributions of source code must retain the above copyright
17
+ * notice, this list of conditions and the following disclaimer.
18
+ * * Redistributions in binary form must reproduce the above
19
+ * copyright notice, this list of conditions and the following disclaimer
20
+ * in the documentation and/or other materials provided with the
21
+ * distribution.
22
+ * * Neither the name of Google Inc. nor the names of its
23
+ * contributors may be used to endorse or promote products derived from
24
+ * this software without specific prior written permission.
25
+ *
26
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
+ */
38
+
39
+ #ifdef __GNUC__
40
+ #pragma GCC diagnostic push
41
+ #pragma GCC diagnostic ignored "-Wcast-align"
42
+ #endif
43
+
44
+ #ifndef SG
45
+ #define SG /* Scatter-Gather / iovec support in Snappy */
46
+ #endif
47
+
48
+ #ifdef __KERNEL__
49
+ #include <linux/kernel.h>
50
+ #ifdef SG
51
+ #include <linux/uio.h>
52
+ #endif
53
+ #include <linux/module.h>
54
+ #include <linux/slab.h>
55
+ #include <linux/string.h>
56
+ #include <linux/snappy.h>
57
+ #include <linux/vmalloc.h>
58
+ #include <asm/unaligned.h>
59
+ #else
60
+ #include "snappy.h"
61
+ #include "snappy_compat.h"
62
+ #endif
63
+
64
+ #include "rd.h"
65
+
66
+ #ifdef _MSC_VER
67
+ #define inline __inline
68
+ #endif
69
+
70
+ static inline u64 get_unaligned64(const void *b)
71
+ {
72
+ u64 ret;
73
+ memcpy(&ret, b, sizeof(u64));
74
+ return ret;
75
+ }
76
+ static inline u32 get_unaligned32(const void *b)
77
+ {
78
+ u32 ret;
79
+ memcpy(&ret, b, sizeof(u32));
80
+ return ret;
81
+ }
82
+ #define get_unaligned_le32(x) (le32toh(get_unaligned32((u32 *)(x))))
83
+
84
+ static inline void put_unaligned64(u64 v, void *b)
85
+ {
86
+ memcpy(b, &v, sizeof(v));
87
+ }
88
+ static inline void put_unaligned32(u32 v, void *b)
89
+ {
90
+ memcpy(b, &v, sizeof(v));
91
+ }
92
+ static inline void put_unaligned16(u16 v, void *b)
93
+ {
94
+ memcpy(b, &v, sizeof(v));
95
+ }
96
+ #define put_unaligned_le16(v,x) (put_unaligned16(htole16(v), (u16 *)(x)))
97
+
98
+
99
+ #define CRASH_UNLESS(x) BUG_ON(!(x))
100
+ #define CHECK(cond) CRASH_UNLESS(cond)
101
+ #define CHECK_LE(a, b) CRASH_UNLESS((a) <= (b))
102
+ #define CHECK_GE(a, b) CRASH_UNLESS((a) >= (b))
103
+ #define CHECK_EQ(a, b) CRASH_UNLESS((a) == (b))
104
+ #define CHECK_NE(a, b) CRASH_UNLESS((a) != (b))
105
+ #define CHECK_LT(a, b) CRASH_UNLESS((a) < (b))
106
+ #define CHECK_GT(a, b) CRASH_UNLESS((a) > (b))
107
+
108
+ #define UNALIGNED_LOAD32(_p) get_unaligned32((u32 *)(_p))
109
+ #define UNALIGNED_LOAD64(_p) get_unaligned64((u64 *)(_p))
110
+
111
+ #define UNALIGNED_STORE16(_p, _val) put_unaligned16(_val, (u16 *)(_p))
112
+ #define UNALIGNED_STORE32(_p, _val) put_unaligned32(_val, (u32 *)(_p))
113
+ #define UNALIGNED_STORE64(_p, _val) put_unaligned64(_val, (u64 *)(_p))
114
+
115
+ /*
116
+ * This can be more efficient than UNALIGNED_LOAD64 + UNALIGNED_STORE64
117
+ * on some platforms, in particular ARM.
118
+ */
119
+ static inline void unaligned_copy64(const void *src, void *dst)
120
+ {
121
+ if (sizeof(void *) == 8) {
122
+ UNALIGNED_STORE64(dst, UNALIGNED_LOAD64(src));
123
+ } else {
124
+ const char *src_char = (const char *)(src);
125
+ char *dst_char = (char *)(dst);
126
+
127
+ UNALIGNED_STORE32(dst_char, UNALIGNED_LOAD32(src_char));
128
+ UNALIGNED_STORE32(dst_char + 4, UNALIGNED_LOAD32(src_char + 4));
129
+ }
130
+ }
131
+
132
+ #ifdef NDEBUG
133
+
134
+ #define DCHECK(cond) do {} while(0)
135
+ #define DCHECK_LE(a, b) do {} while(0)
136
+ #define DCHECK_GE(a, b) do {} while(0)
137
+ #define DCHECK_EQ(a, b) do {} while(0)
138
+ #define DCHECK_NE(a, b) do {} while(0)
139
+ #define DCHECK_LT(a, b) do {} while(0)
140
+ #define DCHECK_GT(a, b) do {} while(0)
141
+
142
+ #else
143
+
144
+ #define DCHECK(cond) CHECK(cond)
145
+ #define DCHECK_LE(a, b) CHECK_LE(a, b)
146
+ #define DCHECK_GE(a, b) CHECK_GE(a, b)
147
+ #define DCHECK_EQ(a, b) CHECK_EQ(a, b)
148
+ #define DCHECK_NE(a, b) CHECK_NE(a, b)
149
+ #define DCHECK_LT(a, b) CHECK_LT(a, b)
150
+ #define DCHECK_GT(a, b) CHECK_GT(a, b)
151
+
152
+ #endif
153
+
154
+ static inline bool is_little_endian(void)
155
+ {
156
+ #ifdef __LITTLE_ENDIAN__
157
+ return true;
158
+ #endif
159
+ return false;
160
+ }
161
+
162
+ #if defined(__xlc__) // xlc compiler on AIX
163
+ #define rd_clz(n) __cntlz4(n)
164
+ #define rd_ctz(n) __cnttz4(n)
165
+ #define rd_ctz64(n) __cnttz8(n)
166
+
167
+ #elif defined(__SUNPRO_C) // Solaris Studio compiler on sun
168
+ /*
169
+ * Source for following definitions is Hacker’s Delight, Second Edition by Henry S. Warren
170
+ * http://www.hackersdelight.org/permissions.htm
171
+ */
172
+ u32 rd_clz(u32 x) {
173
+ u32 n;
174
+
175
+ if (x == 0) return(32);
176
+ n = 1;
177
+ if ((x >> 16) == 0) {n = n +16; x = x <<16;}
178
+ if ((x >> 24) == 0) {n = n + 8; x = x << 8;}
179
+ if ((x >> 28) == 0) {n = n + 4; x = x << 4;}
180
+ if ((x >> 30) == 0) {n = n + 2; x = x << 2;}
181
+ n = n - (x >> 31);
182
+ return n;
183
+ }
184
+
185
+ u32 rd_ctz(u32 x) {
186
+ u32 y;
187
+ u32 n;
188
+
189
+ if (x == 0) return 32;
190
+ n = 31;
191
+ y = x <<16; if (y != 0) {n = n -16; x = y;}
192
+ y = x << 8; if (y != 0) {n = n - 8; x = y;}
193
+ y = x << 4; if (y != 0) {n = n - 4; x = y;}
194
+ y = x << 2; if (y != 0) {n = n - 2; x = y;}
195
+ y = x << 1; if (y != 0) {n = n - 1;}
196
+ return n;
197
+ }
198
+
199
+ u64 rd_ctz64(u64 x) {
200
+ u64 y;
201
+ u64 n;
202
+
203
+ if (x == 0) return 64;
204
+ n = 63;
205
+ y = x <<32; if (y != 0) {n = n -32; x = y;}
206
+ y = x <<16; if (y != 0) {n = n -16; x = y;}
207
+ y = x << 8; if (y != 0) {n = n - 8; x = y;}
208
+ y = x << 4; if (y != 0) {n = n - 4; x = y;}
209
+ y = x << 2; if (y != 0) {n = n - 2; x = y;}
210
+ y = x << 1; if (y != 0) {n = n - 1;}
211
+ return n;
212
+ }
213
+ #elif !defined(_MSC_VER)
214
+ #define rd_clz(n) __builtin_clz(n)
215
+ #define rd_ctz(n) __builtin_ctz(n)
216
+ #define rd_ctz64(n) __builtin_ctzll(n)
217
+ #else
218
+ #include <intrin.h>
219
+ static int inline rd_clz(u32 x) {
220
+ int r = 0;
221
+ if (_BitScanForward(&r, x))
222
+ return 31 - r;
223
+ else
224
+ return 32;
225
+ }
226
+
227
+ static int inline rd_ctz(u32 x) {
228
+ int r = 0;
229
+ if (_BitScanForward(&r, x))
230
+ return r;
231
+ else
232
+ return 32;
233
+ }
234
+
235
+ static int inline rd_ctz64(u64 x) {
236
+ #ifdef _M_X64
237
+ int r = 0;
238
+ if (_BitScanReverse64(&r, x))
239
+ return r;
240
+ else
241
+ return 64;
242
+ #else
243
+ int r;
244
+ if ((r = rd_ctz(x & 0xffffffff)) < 32)
245
+ return r;
246
+ return 32 + rd_ctz(x >> 32);
247
+ #endif
248
+ }
249
+ #endif
250
+
251
+
252
+ static inline int log2_floor(u32 n)
253
+ {
254
+ return n == 0 ? -1 : 31 ^ rd_clz(n);
255
+ }
256
+
257
+ static inline RD_UNUSED int find_lsb_set_non_zero(u32 n)
258
+ {
259
+ return rd_ctz(n);
260
+ }
261
+
262
+ static inline RD_UNUSED int find_lsb_set_non_zero64(u64 n)
263
+ {
264
+ return rd_ctz64(n);
265
+ }
266
+
267
+ #define kmax32 5
268
+
269
+ /*
270
+ * Attempts to parse a varint32 from a prefix of the bytes in [ptr,limit-1].
271
+ * Never reads a character at or beyond limit. If a valid/terminated varint32
272
+ * was found in the range, stores it in *OUTPUT and returns a pointer just
273
+ * past the last byte of the varint32. Else returns NULL. On success,
274
+ * "result <= limit".
275
+ */
276
+ static inline const char *varint_parse32_with_limit(const char *p,
277
+ const char *l,
278
+ u32 * OUTPUT)
279
+ {
280
+ const unsigned char *ptr = (const unsigned char *)(p);
281
+ const unsigned char *limit = (const unsigned char *)(l);
282
+ u32 b, result;
283
+
284
+ if (ptr >= limit)
285
+ return NULL;
286
+ b = *(ptr++);
287
+ result = b & 127;
288
+ if (b < 128)
289
+ goto done;
290
+ if (ptr >= limit)
291
+ return NULL;
292
+ b = *(ptr++);
293
+ result |= (b & 127) << 7;
294
+ if (b < 128)
295
+ goto done;
296
+ if (ptr >= limit)
297
+ return NULL;
298
+ b = *(ptr++);
299
+ result |= (b & 127) << 14;
300
+ if (b < 128)
301
+ goto done;
302
+ if (ptr >= limit)
303
+ return NULL;
304
+ b = *(ptr++);
305
+ result |= (b & 127) << 21;
306
+ if (b < 128)
307
+ goto done;
308
+ if (ptr >= limit)
309
+ return NULL;
310
+ b = *(ptr++);
311
+ result |= (b & 127) << 28;
312
+ if (b < 16)
313
+ goto done;
314
+ return NULL; /* Value is too long to be a varint32 */
315
+ done:
316
+ *OUTPUT = result;
317
+ return (const char *)(ptr);
318
+ }
319
+
320
+ /*
321
+ * REQUIRES "ptr" points to a buffer of length sufficient to hold "v".
322
+ * EFFECTS Encodes "v" into "ptr" and returns a pointer to the
323
+ * byte just past the last encoded byte.
324
+ */
325
+ static inline char *varint_encode32(char *sptr, u32 v)
326
+ {
327
+ /* Operate on characters as unsigneds */
328
+ unsigned char *ptr = (unsigned char *)(sptr);
329
+ static const int B = 128;
330
+
331
+ if (v < (1 << 7)) {
332
+ *(ptr++) = v;
333
+ } else if (v < (1 << 14)) {
334
+ *(ptr++) = v | B;
335
+ *(ptr++) = v >> 7;
336
+ } else if (v < (1 << 21)) {
337
+ *(ptr++) = v | B;
338
+ *(ptr++) = (v >> 7) | B;
339
+ *(ptr++) = v >> 14;
340
+ } else if (v < (1 << 28)) {
341
+ *(ptr++) = v | B;
342
+ *(ptr++) = (v >> 7) | B;
343
+ *(ptr++) = (v >> 14) | B;
344
+ *(ptr++) = v >> 21;
345
+ } else {
346
+ *(ptr++) = v | B;
347
+ *(ptr++) = (v >> 7) | B;
348
+ *(ptr++) = (v >> 14) | B;
349
+ *(ptr++) = (v >> 21) | B;
350
+ *(ptr++) = v >> 28;
351
+ }
352
+ return (char *)(ptr);
353
+ }
354
+
355
+ #ifdef SG
356
+
357
+ static inline void *n_bytes_after_addr(void *addr, size_t n_bytes)
358
+ {
359
+ return (void *) ((char *)addr + n_bytes);
360
+ }
361
+
362
+ struct source {
363
+ struct iovec *iov;
364
+ int iovlen;
365
+ int curvec;
366
+ int curoff;
367
+ size_t total;
368
+ };
369
+
370
+ /* Only valid at beginning when nothing is consumed */
371
+ static inline int available(struct source *s)
372
+ {
373
+ return (int) s->total;
374
+ }
375
+
376
+ static inline const char *peek(struct source *s, size_t *len)
377
+ {
378
+ if (likely(s->curvec < s->iovlen)) {
379
+ struct iovec *iv = &s->iov[s->curvec];
380
+ if ((unsigned)s->curoff < (size_t)iv->iov_len) {
381
+ *len = iv->iov_len - s->curoff;
382
+ return n_bytes_after_addr(iv->iov_base, s->curoff);
383
+ }
384
+ }
385
+ *len = 0;
386
+ return NULL;
387
+ }
388
+
389
+ static inline void skip(struct source *s, size_t n)
390
+ {
391
+ struct iovec *iv = &s->iov[s->curvec];
392
+ s->curoff += (int) n;
393
+ DCHECK_LE((unsigned)s->curoff, (size_t)iv->iov_len);
394
+ if ((unsigned)s->curoff >= (size_t)iv->iov_len &&
395
+ s->curvec + 1 < s->iovlen) {
396
+ s->curoff = 0;
397
+ s->curvec++;
398
+ }
399
+ }
400
+
401
+ struct sink {
402
+ struct iovec *iov;
403
+ int iovlen;
404
+ unsigned curvec;
405
+ unsigned curoff;
406
+ unsigned written;
407
+ };
408
+
409
+ static inline void append(struct sink *s, const char *data, size_t n)
410
+ {
411
+ struct iovec *iov = &s->iov[s->curvec];
412
+ char *dst = n_bytes_after_addr(iov->iov_base, s->curoff);
413
+ size_t nlen = min_t(size_t, iov->iov_len - s->curoff, n);
414
+ if (data != dst)
415
+ memcpy(dst, data, nlen);
416
+ s->written += (int) n;
417
+ s->curoff += (int) nlen;
418
+ while ((n -= nlen) > 0) {
419
+ data += nlen;
420
+ s->curvec++;
421
+ DCHECK_LT((signed)s->curvec, s->iovlen);
422
+ iov++;
423
+ nlen = min_t(size_t, (size_t)iov->iov_len, n);
424
+ memcpy(iov->iov_base, data, nlen);
425
+ s->curoff = (int) nlen;
426
+ }
427
+ }
428
+
429
+ static inline void *sink_peek(struct sink *s, size_t n)
430
+ {
431
+ struct iovec *iov = &s->iov[s->curvec];
432
+ if (s->curvec < (size_t)iov->iov_len && iov->iov_len - s->curoff >= n)
433
+ return n_bytes_after_addr(iov->iov_base, s->curoff);
434
+ return NULL;
435
+ }
436
+
437
+ #else
438
+
439
+ struct source {
440
+ const char *ptr;
441
+ size_t left;
442
+ };
443
+
444
+ static inline int available(struct source *s)
445
+ {
446
+ return s->left;
447
+ }
448
+
449
+ static inline const char *peek(struct source *s, size_t * len)
450
+ {
451
+ *len = s->left;
452
+ return s->ptr;
453
+ }
454
+
455
+ static inline void skip(struct source *s, size_t n)
456
+ {
457
+ s->left -= n;
458
+ s->ptr += n;
459
+ }
460
+
461
+ struct sink {
462
+ char *dest;
463
+ };
464
+
465
+ static inline void append(struct sink *s, const char *data, size_t n)
466
+ {
467
+ if (data != s->dest)
468
+ memcpy(s->dest, data, n);
469
+ s->dest += n;
470
+ }
471
+
472
+ #define sink_peek(s, n) sink_peek_no_sg(s)
473
+
474
+ static inline void *sink_peek_no_sg(const struct sink *s)
475
+ {
476
+ return s->dest;
477
+ }
478
+
479
+ #endif
480
+
481
+ struct writer {
482
+ char *base;
483
+ char *op;
484
+ char *op_limit;
485
+ };
486
+
487
+ /* Called before decompression */
488
+ static inline void writer_set_expected_length(struct writer *w, size_t len)
489
+ {
490
+ w->op_limit = w->op + len;
491
+ }
492
+
493
+ /* Called after decompression */
494
+ static inline bool writer_check_length(struct writer *w)
495
+ {
496
+ return w->op == w->op_limit;
497
+ }
498
+
499
+ /*
500
+ * Copy "len" bytes from "src" to "op", one byte at a time. Used for
501
+ * handling COPY operations where the input and output regions may
502
+ * overlap. For example, suppose:
503
+ * src == "ab"
504
+ * op == src + 2
505
+ * len == 20
506
+ * After IncrementalCopy(src, op, len), the result will have
507
+ * eleven copies of "ab"
508
+ * ababababababababababab
509
+ * Note that this does not match the semantics of either memcpy()
510
+ * or memmove().
511
+ */
512
+ static inline void incremental_copy(const char *src, char *op, ssize_t len)
513
+ {
514
+ DCHECK_GT(len, 0);
515
+ do {
516
+ *op++ = *src++;
517
+ } while (--len > 0);
518
+ }
519
+
520
+ /*
521
+ * Equivalent to IncrementalCopy except that it can write up to ten extra
522
+ * bytes after the end of the copy, and that it is faster.
523
+ *
524
+ * The main part of this loop is a simple copy of eight bytes at a time until
525
+ * we've copied (at least) the requested amount of bytes. However, if op and
526
+ * src are less than eight bytes apart (indicating a repeating pattern of
527
+ * length < 8), we first need to expand the pattern in order to get the correct
528
+ * results. For instance, if the buffer looks like this, with the eight-byte
529
+ * <src> and <op> patterns marked as intervals:
530
+ *
531
+ * abxxxxxxxxxxxx
532
+ * [------] src
533
+ * [------] op
534
+ *
535
+ * a single eight-byte copy from <src> to <op> will repeat the pattern once,
536
+ * after which we can move <op> two bytes without moving <src>:
537
+ *
538
+ * ababxxxxxxxxxx
539
+ * [------] src
540
+ * [------] op
541
+ *
542
+ * and repeat the exercise until the two no longer overlap.
543
+ *
544
+ * This allows us to do very well in the special case of one single byte
545
+ * repeated many times, without taking a big hit for more general cases.
546
+ *
547
+ * The worst case of extra writing past the end of the match occurs when
548
+ * op - src == 1 and len == 1; the last copy will read from byte positions
549
+ * [0..7] and write to [4..11], whereas it was only supposed to write to
550
+ * position 1. Thus, ten excess bytes.
551
+ */
552
+
553
+ #define kmax_increment_copy_overflow 10
554
+
555
+ static inline void incremental_copy_fast_path(const char *src, char *op,
556
+ ssize_t len)
557
+ {
558
+ while (op - src < 8) {
559
+ unaligned_copy64(src, op);
560
+ len -= op - src;
561
+ op += op - src;
562
+ }
563
+ while (len > 0) {
564
+ unaligned_copy64(src, op);
565
+ src += 8;
566
+ op += 8;
567
+ len -= 8;
568
+ }
569
+ }
570
+
571
+ static inline bool writer_append_from_self(struct writer *w, u32 offset,
572
+ u32 len)
573
+ {
574
+ char *const op = w->op;
575
+ CHECK_LE(op, w->op_limit);
576
+ const u32 space_left = (u32) (w->op_limit - op);
577
+
578
+ if ((unsigned)(op - w->base) <= offset - 1u) /* -1u catches offset==0 */
579
+ return false;
580
+ if (len <= 16 && offset >= 8 && space_left >= 16) {
581
+ /* Fast path, used for the majority (70-80%) of dynamic
582
+ * invocations. */
583
+ unaligned_copy64(op - offset, op);
584
+ unaligned_copy64(op - offset + 8, op + 8);
585
+ } else {
586
+ if (space_left >= len + kmax_increment_copy_overflow) {
587
+ incremental_copy_fast_path(op - offset, op, len);
588
+ } else {
589
+ if (space_left < len) {
590
+ return false;
591
+ }
592
+ incremental_copy(op - offset, op, len);
593
+ }
594
+ }
595
+
596
+ w->op = op + len;
597
+ return true;
598
+ }
599
+
600
+ static inline bool writer_append(struct writer *w, const char *ip, u32 len)
601
+ {
602
+ char *const op = w->op;
603
+ CHECK_LE(op, w->op_limit);
604
+ const u32 space_left = (u32) (w->op_limit - op);
605
+ if (space_left < len)
606
+ return false;
607
+ memcpy(op, ip, len);
608
+ w->op = op + len;
609
+ return true;
610
+ }
611
+
612
+ static inline bool writer_try_fast_append(struct writer *w, const char *ip,
613
+ u32 available_bytes, u32 len)
614
+ {
615
+ char *const op = w->op;
616
+ const int space_left = (int) (w->op_limit - op);
617
+ if (len <= 16 && available_bytes >= 16 && space_left >= 16) {
618
+ /* Fast path, used for the majority (~95%) of invocations */
619
+ unaligned_copy64(ip, op);
620
+ unaligned_copy64(ip + 8, op + 8);
621
+ w->op = op + len;
622
+ return true;
623
+ }
624
+ return false;
625
+ }
626
+
627
+ /*
628
+ * Any hash function will produce a valid compressed bitstream, but a good
629
+ * hash function reduces the number of collisions and thus yields better
630
+ * compression for compressible input, and more speed for incompressible
631
+ * input. Of course, it doesn't hurt if the hash function is reasonably fast
632
+ * either, as it gets called a lot.
633
+ */
634
+ static inline u32 hash_bytes(u32 bytes, int shift)
635
+ {
636
+ u32 kmul = 0x1e35a7bd;
637
+ return (bytes * kmul) >> shift;
638
+ }
639
+
640
+ static inline u32 hash(const char *p, int shift)
641
+ {
642
+ return hash_bytes(UNALIGNED_LOAD32(p), shift);
643
+ }
644
+
645
+ /*
646
+ * Compressed data can be defined as:
647
+ * compressed := item* literal*
648
+ * item := literal* copy
649
+ *
650
+ * The trailing literal sequence has a space blowup of at most 62/60
651
+ * since a literal of length 60 needs one tag byte + one extra byte
652
+ * for length information.
653
+ *
654
+ * Item blowup is trickier to measure. Suppose the "copy" op copies
655
+ * 4 bytes of data. Because of a special check in the encoding code,
656
+ * we produce a 4-byte copy only if the offset is < 65536. Therefore
657
+ * the copy op takes 3 bytes to encode, and this type of item leads
658
+ * to at most the 62/60 blowup for representing literals.
659
+ *
660
+ * Suppose the "copy" op copies 5 bytes of data. If the offset is big
661
+ * enough, it will take 5 bytes to encode the copy op. Therefore the
662
+ * worst case here is a one-byte literal followed by a five-byte copy.
663
+ * I.e., 6 bytes of input turn into 7 bytes of "compressed" data.
664
+ *
665
+ * This last factor dominates the blowup, so the final estimate is:
666
+ */
667
+ size_t rd_kafka_snappy_max_compressed_length(size_t source_len)
668
+ {
669
+ return 32 + source_len + source_len / 6;
670
+ }
671
+ EXPORT_SYMBOL(rd_kafka_snappy_max_compressed_length);
672
+
673
+ enum {
674
+ LITERAL = 0,
675
+ COPY_1_BYTE_OFFSET = 1, /* 3 bit length + 3 bits of offset in opcode */
676
+ COPY_2_BYTE_OFFSET = 2,
677
+ COPY_4_BYTE_OFFSET = 3
678
+ };
679
+
680
+ static inline char *emit_literal(char *op,
681
+ const char *literal,
682
+ int len, bool allow_fast_path)
683
+ {
684
+ int n = len - 1; /* Zero-length literals are disallowed */
685
+
686
+ if (n < 60) {
687
+ /* Fits in tag byte */
688
+ *op++ = LITERAL | (n << 2);
689
+
690
+ /*
691
+ * The vast majority of copies are below 16 bytes, for which a
692
+ * call to memcpy is overkill. This fast path can sometimes
693
+ * copy up to 15 bytes too much, but that is okay in the
694
+ * main loop, since we have a bit to go on for both sides:
695
+ *
696
+ * - The input will always have kInputMarginBytes = 15 extra
697
+ * available bytes, as long as we're in the main loop, and
698
+ * if not, allow_fast_path = false.
699
+ * - The output will always have 32 spare bytes (see
700
+ * MaxCompressedLength).
701
+ */
702
+ if (allow_fast_path && len <= 16) {
703
+ unaligned_copy64(literal, op);
704
+ unaligned_copy64(literal + 8, op + 8);
705
+ return op + len;
706
+ }
707
+ } else {
708
+ /* Encode in upcoming bytes */
709
+ char *base = op;
710
+ int count = 0;
711
+ op++;
712
+ while (n > 0) {
713
+ *op++ = n & 0xff;
714
+ n >>= 8;
715
+ count++;
716
+ }
717
+ DCHECK(count >= 1);
718
+ DCHECK(count <= 4);
719
+ *base = LITERAL | ((59 + count) << 2);
720
+ }
721
+ memcpy(op, literal, len);
722
+ return op + len;
723
+ }
724
+
725
+ static inline char *emit_copy_less_than64(char *op, int offset, int len)
726
+ {
727
+ DCHECK_LE(len, 64);
728
+ DCHECK_GE(len, 4);
729
+ DCHECK_LT(offset, 65536);
730
+
731
+ if ((len < 12) && (offset < 2048)) {
732
+ int len_minus_4 = len - 4;
733
+ DCHECK(len_minus_4 < 8); /* Must fit in 3 bits */
734
+ *op++ =
735
+ COPY_1_BYTE_OFFSET + ((len_minus_4) << 2) + ((offset >> 8)
736
+ << 5);
737
+ *op++ = offset & 0xff;
738
+ } else {
739
+ *op++ = COPY_2_BYTE_OFFSET + ((len - 1) << 2);
740
+ put_unaligned_le16(offset, op);
741
+ op += 2;
742
+ }
743
+ return op;
744
+ }
745
+
746
+ static inline char *emit_copy(char *op, int offset, int len)
747
+ {
748
+ /*
749
+ * Emit 64 byte copies but make sure to keep at least four bytes
750
+ * reserved
751
+ */
752
+ while (len >= 68) {
753
+ op = emit_copy_less_than64(op, offset, 64);
754
+ len -= 64;
755
+ }
756
+
757
+ /*
758
+ * Emit an extra 60 byte copy if have too much data to fit in
759
+ * one copy
760
+ */
761
+ if (len > 64) {
762
+ op = emit_copy_less_than64(op, offset, 60);
763
+ len -= 60;
764
+ }
765
+
766
+ /* Emit remainder */
767
+ op = emit_copy_less_than64(op, offset, len);
768
+ return op;
769
+ }
770
+
771
+ /**
772
+ * rd_kafka_snappy_uncompressed_length - return length of uncompressed output.
773
+ * @start: compressed buffer
774
+ * @n: length of compressed buffer.
775
+ * @result: Write the length of the uncompressed output here.
776
+ *
777
+ * Returns true when successfull, otherwise false.
778
+ */
779
+ bool rd_kafka_snappy_uncompressed_length(const char *start, size_t n, size_t * result)
780
+ {
781
+ u32 v = 0;
782
+ const char *limit = start + n;
783
+ if (varint_parse32_with_limit(start, limit, &v) != NULL) {
784
+ *result = v;
785
+ return true;
786
+ } else {
787
+ return false;
788
+ }
789
+ }
790
+ EXPORT_SYMBOL(rd_kafka_snappy_uncompressed_length);
791
+
792
+ /*
793
+ * The size of a compression block. Note that many parts of the compression
794
+ * code assumes that kBlockSize <= 65536; in particular, the hash table
795
+ * can only store 16-bit offsets, and EmitCopy() also assumes the offset
796
+ * is 65535 bytes or less. Note also that if you change this, it will
797
+ * affect the framing format
798
+ * Note that there might be older data around that is compressed with larger
799
+ * block sizes, so the decompression code should not rely on the
800
+ * non-existence of long backreferences.
801
+ */
802
+ #define kblock_log 16
803
+ #define kblock_size (1 << kblock_log)
804
+
805
+ /*
806
+ * This value could be halfed or quartered to save memory
807
+ * at the cost of slightly worse compression.
808
+ */
809
+ #define kmax_hash_table_bits 14
810
+ #define kmax_hash_table_size (1U << kmax_hash_table_bits)
811
+
812
+ /*
813
+ * Use smaller hash table when input.size() is smaller, since we
814
+ * fill the table, incurring O(hash table size) overhead for
815
+ * compression, and if the input is short, we won't need that
816
+ * many hash table entries anyway.
817
+ */
818
+ static u16 *get_hash_table(struct snappy_env *env, size_t input_size,
819
+ int *table_size)
820
+ {
821
+ unsigned htsize = 256;
822
+
823
+ DCHECK(kmax_hash_table_size >= 256);
824
+ while (htsize < kmax_hash_table_size && htsize < input_size)
825
+ htsize <<= 1;
826
+ CHECK_EQ(0, htsize & (htsize - 1));
827
+ CHECK_LE(htsize, kmax_hash_table_size);
828
+
829
+ u16 *table;
830
+ table = env->hash_table;
831
+
832
+ *table_size = htsize;
833
+ memset(table, 0, htsize * sizeof(*table));
834
+ return table;
835
+ }
836
+
837
+ /*
838
+ * Return the largest n such that
839
+ *
840
+ * s1[0,n-1] == s2[0,n-1]
841
+ * and n <= (s2_limit - s2).
842
+ *
843
+ * Does not read *s2_limit or beyond.
844
+ * Does not read *(s1 + (s2_limit - s2)) or beyond.
845
+ * Requires that s2_limit >= s2.
846
+ *
847
+ * Separate implementation for x86_64, for speed. Uses the fact that
848
+ * x86_64 is little endian.
849
+ */
850
+ #if defined(__LITTLE_ENDIAN__) && BITS_PER_LONG == 64
851
+ static inline int find_match_length(const char *s1,
852
+ const char *s2, const char *s2_limit)
853
+ {
854
+ int matched = 0;
855
+
856
+ DCHECK_GE(s2_limit, s2);
857
+ /*
858
+ * Find out how long the match is. We loop over the data 64 bits at a
859
+ * time until we find a 64-bit block that doesn't match; then we find
860
+ * the first non-matching bit and use that to calculate the total
861
+ * length of the match.
862
+ */
863
+ while (likely(s2 <= s2_limit - 8)) {
864
+ if (unlikely
865
+ (UNALIGNED_LOAD64(s2) == UNALIGNED_LOAD64(s1 + matched))) {
866
+ s2 += 8;
867
+ matched += 8;
868
+ } else {
869
+ /*
870
+ * On current (mid-2008) Opteron models there
871
+ * is a 3% more efficient code sequence to
872
+ * find the first non-matching byte. However,
873
+ * what follows is ~10% better on Intel Core 2
874
+ * and newer, and we expect AMD's bsf
875
+ * instruction to improve.
876
+ */
877
+ u64 x =
878
+ UNALIGNED_LOAD64(s2) ^ UNALIGNED_LOAD64(s1 +
879
+ matched);
880
+ int matching_bits = find_lsb_set_non_zero64(x);
881
+ matched += matching_bits >> 3;
882
+ return matched;
883
+ }
884
+ }
885
+ while (likely(s2 < s2_limit)) {
886
+ if (likely(s1[matched] == *s2)) {
887
+ ++s2;
888
+ ++matched;
889
+ } else {
890
+ return matched;
891
+ }
892
+ }
893
+ return matched;
894
+ }
895
+ #else
896
+ static inline int find_match_length(const char *s1,
897
+ const char *s2, const char *s2_limit)
898
+ {
899
+ /* Implementation based on the x86-64 version, above. */
900
+ DCHECK_GE(s2_limit, s2);
901
+ int matched = 0;
902
+
903
+ while (s2 <= s2_limit - 4 &&
904
+ UNALIGNED_LOAD32(s2) == UNALIGNED_LOAD32(s1 + matched)) {
905
+ s2 += 4;
906
+ matched += 4;
907
+ }
908
+ if (is_little_endian() && s2 <= s2_limit - 4) {
909
+ u32 x =
910
+ UNALIGNED_LOAD32(s2) ^ UNALIGNED_LOAD32(s1 + matched);
911
+ int matching_bits = find_lsb_set_non_zero(x);
912
+ matched += matching_bits >> 3;
913
+ } else {
914
+ while ((s2 < s2_limit) && (s1[matched] == *s2)) {
915
+ ++s2;
916
+ ++matched;
917
+ }
918
+ }
919
+ return matched;
920
+ }
921
+ #endif
922
+
923
+ /*
924
+ * For 0 <= offset <= 4, GetU32AtOffset(GetEightBytesAt(p), offset) will
925
+ * equal UNALIGNED_LOAD32(p + offset). Motivation: On x86-64 hardware we have
926
+ * empirically found that overlapping loads such as
927
+ * UNALIGNED_LOAD32(p) ... UNALIGNED_LOAD32(p+1) ... UNALIGNED_LOAD32(p+2)
928
+ * are slower than UNALIGNED_LOAD64(p) followed by shifts and casts to u32.
929
+ *
930
+ * We have different versions for 64- and 32-bit; ideally we would avoid the
931
+ * two functions and just inline the UNALIGNED_LOAD64 call into
932
+ * GetUint32AtOffset, but GCC (at least not as of 4.6) is seemingly not clever
933
+ * enough to avoid loading the value multiple times then. For 64-bit, the load
934
+ * is done when GetEightBytesAt() is called, whereas for 32-bit, the load is
935
+ * done at GetUint32AtOffset() time.
936
+ */
937
+
938
+ #if BITS_PER_LONG == 64
939
+
940
+ typedef u64 eight_bytes_reference;
941
+
942
+ static inline eight_bytes_reference get_eight_bytes_at(const char* ptr)
943
+ {
944
+ return UNALIGNED_LOAD64(ptr);
945
+ }
946
+
947
+ static inline u32 get_u32_at_offset(u64 v, int offset)
948
+ {
949
+ DCHECK_GE(offset, 0);
950
+ DCHECK_LE(offset, 4);
951
+ return v >> (is_little_endian()? 8 * offset : 32 - 8 * offset);
952
+ }
953
+
954
+ #else
955
+
956
+ typedef const char *eight_bytes_reference;
957
+
958
+ static inline eight_bytes_reference get_eight_bytes_at(const char* ptr)
959
+ {
960
+ return ptr;
961
+ }
962
+
963
+ static inline u32 get_u32_at_offset(const char *v, int offset)
964
+ {
965
+ DCHECK_GE(offset, 0);
966
+ DCHECK_LE(offset, 4);
967
+ return UNALIGNED_LOAD32(v + offset);
968
+ }
969
+ #endif
970
+
971
+ /*
972
+ * Flat array compression that does not emit the "uncompressed length"
973
+ * prefix. Compresses "input" string to the "*op" buffer.
974
+ *
975
+ * REQUIRES: "input" is at most "kBlockSize" bytes long.
976
+ * REQUIRES: "op" points to an array of memory that is at least
977
+ * "MaxCompressedLength(input.size())" in size.
978
+ * REQUIRES: All elements in "table[0..table_size-1]" are initialized to zero.
979
+ * REQUIRES: "table_size" is a power of two
980
+ *
981
+ * Returns an "end" pointer into "op" buffer.
982
+ * "end - op" is the compressed size of "input".
983
+ */
984
+
985
+ static char *compress_fragment(const char *const input,
986
+ const size_t input_size,
987
+ char *op, u16 * table, const unsigned table_size)
988
+ {
989
+ /* "ip" is the input pointer, and "op" is the output pointer. */
990
+ const char *ip = input;
991
+ CHECK_LE(input_size, kblock_size);
992
+ CHECK_EQ(table_size & (table_size - 1), 0);
993
+ const int shift = 32 - log2_floor(table_size);
994
+ DCHECK_EQ(UINT_MAX >> shift, table_size - 1);
995
+ const char *ip_end = input + input_size;
996
+ const char *baseip = ip;
997
+ /*
998
+ * Bytes in [next_emit, ip) will be emitted as literal bytes. Or
999
+ * [next_emit, ip_end) after the main loop.
1000
+ */
1001
+ const char *next_emit = ip;
1002
+
1003
+ const unsigned kinput_margin_bytes = 15;
1004
+
1005
+ if (likely(input_size >= kinput_margin_bytes)) {
1006
+ const char *const ip_limit = input + input_size -
1007
+ kinput_margin_bytes;
1008
+
1009
+ u32 next_hash;
1010
+ for (next_hash = hash(++ip, shift);;) {
1011
+ DCHECK_LT(next_emit, ip);
1012
+ /*
1013
+ * The body of this loop calls EmitLiteral once and then EmitCopy one or
1014
+ * more times. (The exception is that when we're close to exhausting
1015
+ * the input we goto emit_remainder.)
1016
+ *
1017
+ * In the first iteration of this loop we're just starting, so
1018
+ * there's nothing to copy, so calling EmitLiteral once is
1019
+ * necessary. And we only start a new iteration when the
1020
+ * current iteration has determined that a call to EmitLiteral will
1021
+ * precede the next call to EmitCopy (if any).
1022
+ *
1023
+ * Step 1: Scan forward in the input looking for a 4-byte-long match.
1024
+ * If we get close to exhausting the input then goto emit_remainder.
1025
+ *
1026
+ * Heuristic match skipping: If 32 bytes are scanned with no matches
1027
+ * found, start looking only at every other byte. If 32 more bytes are
1028
+ * scanned, look at every third byte, etc.. When a match is found,
1029
+ * immediately go back to looking at every byte. This is a small loss
1030
+ * (~5% performance, ~0.1% density) for lcompressible data due to more
1031
+ * bookkeeping, but for non-compressible data (such as JPEG) it's a huge
1032
+ * win since the compressor quickly "realizes" the data is incompressible
1033
+ * and doesn't bother looking for matches everywhere.
1034
+ *
1035
+ * The "skip" variable keeps track of how many bytes there are since the
1036
+ * last match; dividing it by 32 (ie. right-shifting by five) gives the
1037
+ * number of bytes to move ahead for each iteration.
1038
+ */
1039
+ u32 skip_bytes = 32;
1040
+
1041
+ const char *next_ip = ip;
1042
+ const char *candidate;
1043
+ do {
1044
+ ip = next_ip;
1045
+ u32 hval = next_hash;
1046
+ DCHECK_EQ(hval, hash(ip, shift));
1047
+ u32 bytes_between_hash_lookups = skip_bytes++ >> 5;
1048
+ next_ip = ip + bytes_between_hash_lookups;
1049
+ if (unlikely(next_ip > ip_limit)) {
1050
+ goto emit_remainder;
1051
+ }
1052
+ next_hash = hash(next_ip, shift);
1053
+ candidate = baseip + table[hval];
1054
+ DCHECK_GE(candidate, baseip);
1055
+ DCHECK_LT(candidate, ip);
1056
+
1057
+ table[hval] = (u16) (ip - baseip);
1058
+ } while (likely(UNALIGNED_LOAD32(ip) !=
1059
+ UNALIGNED_LOAD32(candidate)));
1060
+
1061
+ /*
1062
+ * Step 2: A 4-byte match has been found. We'll later see if more
1063
+ * than 4 bytes match. But, prior to the match, input
1064
+ * bytes [next_emit, ip) are unmatched. Emit them as "literal bytes."
1065
+ */
1066
+ DCHECK_LE(next_emit + 16, ip_end);
1067
+ op = emit_literal(op, next_emit, (int) (ip - next_emit), true);
1068
+
1069
+ /*
1070
+ * Step 3: Call EmitCopy, and then see if another EmitCopy could
1071
+ * be our next move. Repeat until we find no match for the
1072
+ * input immediately after what was consumed by the last EmitCopy call.
1073
+ *
1074
+ * If we exit this loop normally then we need to call EmitLiteral next,
1075
+ * though we don't yet know how big the literal will be. We handle that
1076
+ * by proceeding to the next iteration of the main loop. We also can exit
1077
+ * this loop via goto if we get close to exhausting the input.
1078
+ */
1079
+ eight_bytes_reference input_bytes;
1080
+ u32 candidate_bytes = 0;
1081
+
1082
+ do {
1083
+ /*
1084
+ * We have a 4-byte match at ip, and no need to emit any
1085
+ * "literal bytes" prior to ip.
1086
+ */
1087
+ const char *base = ip;
1088
+ int matched = 4 +
1089
+ find_match_length(candidate + 4, ip + 4,
1090
+ ip_end);
1091
+ ip += matched;
1092
+ int offset = (int) (base - candidate);
1093
+ DCHECK_EQ(0, memcmp(base, candidate, matched));
1094
+ op = emit_copy(op, offset, matched);
1095
+ /*
1096
+ * We could immediately start working at ip now, but to improve
1097
+ * compression we first update table[Hash(ip - 1, ...)].
1098
+ */
1099
+ const char *insert_tail = ip - 1;
1100
+ next_emit = ip;
1101
+ if (unlikely(ip >= ip_limit)) {
1102
+ goto emit_remainder;
1103
+ }
1104
+ input_bytes = get_eight_bytes_at(insert_tail);
1105
+ u32 prev_hash =
1106
+ hash_bytes(get_u32_at_offset
1107
+ (input_bytes, 0), shift);
1108
+ table[prev_hash] = (u16) (ip - baseip - 1);
1109
+ u32 cur_hash =
1110
+ hash_bytes(get_u32_at_offset
1111
+ (input_bytes, 1), shift);
1112
+ candidate = baseip + table[cur_hash];
1113
+ candidate_bytes = UNALIGNED_LOAD32(candidate);
1114
+ table[cur_hash] = (u16) (ip - baseip);
1115
+ } while (get_u32_at_offset(input_bytes, 1) ==
1116
+ candidate_bytes);
1117
+
1118
+ next_hash =
1119
+ hash_bytes(get_u32_at_offset(input_bytes, 2),
1120
+ shift);
1121
+ ++ip;
1122
+ }
1123
+ }
1124
+
1125
+ emit_remainder:
1126
+ /* Emit the remaining bytes as a literal */
1127
+ if (next_emit < ip_end)
1128
+ op = emit_literal(op, next_emit, (int) (ip_end - next_emit), false);
1129
+
1130
+ return op;
1131
+ }
1132
+
1133
+ /*
1134
+ * -----------------------------------------------------------------------
1135
+ * Lookup table for decompression code. Generated by ComputeTable() below.
1136
+ * -----------------------------------------------------------------------
1137
+ */
1138
+
1139
+ /* Mapping from i in range [0,4] to a mask to extract the bottom 8*i bits */
1140
+ static const u32 wordmask[] = {
1141
+ 0u, 0xffu, 0xffffu, 0xffffffu, 0xffffffffu
1142
+ };
1143
+
1144
+ /*
1145
+ * Data stored per entry in lookup table:
1146
+ * Range Bits-used Description
1147
+ * ------------------------------------
1148
+ * 1..64 0..7 Literal/copy length encoded in opcode byte
1149
+ * 0..7 8..10 Copy offset encoded in opcode byte / 256
1150
+ * 0..4 11..13 Extra bytes after opcode
1151
+ *
1152
+ * We use eight bits for the length even though 7 would have sufficed
1153
+ * because of efficiency reasons:
1154
+ * (1) Extracting a byte is faster than a bit-field
1155
+ * (2) It properly aligns copy offset so we do not need a <<8
1156
+ */
1157
+ static const u16 char_table[256] = {
1158
+ 0x0001, 0x0804, 0x1001, 0x2001, 0x0002, 0x0805, 0x1002, 0x2002,
1159
+ 0x0003, 0x0806, 0x1003, 0x2003, 0x0004, 0x0807, 0x1004, 0x2004,
1160
+ 0x0005, 0x0808, 0x1005, 0x2005, 0x0006, 0x0809, 0x1006, 0x2006,
1161
+ 0x0007, 0x080a, 0x1007, 0x2007, 0x0008, 0x080b, 0x1008, 0x2008,
1162
+ 0x0009, 0x0904, 0x1009, 0x2009, 0x000a, 0x0905, 0x100a, 0x200a,
1163
+ 0x000b, 0x0906, 0x100b, 0x200b, 0x000c, 0x0907, 0x100c, 0x200c,
1164
+ 0x000d, 0x0908, 0x100d, 0x200d, 0x000e, 0x0909, 0x100e, 0x200e,
1165
+ 0x000f, 0x090a, 0x100f, 0x200f, 0x0010, 0x090b, 0x1010, 0x2010,
1166
+ 0x0011, 0x0a04, 0x1011, 0x2011, 0x0012, 0x0a05, 0x1012, 0x2012,
1167
+ 0x0013, 0x0a06, 0x1013, 0x2013, 0x0014, 0x0a07, 0x1014, 0x2014,
1168
+ 0x0015, 0x0a08, 0x1015, 0x2015, 0x0016, 0x0a09, 0x1016, 0x2016,
1169
+ 0x0017, 0x0a0a, 0x1017, 0x2017, 0x0018, 0x0a0b, 0x1018, 0x2018,
1170
+ 0x0019, 0x0b04, 0x1019, 0x2019, 0x001a, 0x0b05, 0x101a, 0x201a,
1171
+ 0x001b, 0x0b06, 0x101b, 0x201b, 0x001c, 0x0b07, 0x101c, 0x201c,
1172
+ 0x001d, 0x0b08, 0x101d, 0x201d, 0x001e, 0x0b09, 0x101e, 0x201e,
1173
+ 0x001f, 0x0b0a, 0x101f, 0x201f, 0x0020, 0x0b0b, 0x1020, 0x2020,
1174
+ 0x0021, 0x0c04, 0x1021, 0x2021, 0x0022, 0x0c05, 0x1022, 0x2022,
1175
+ 0x0023, 0x0c06, 0x1023, 0x2023, 0x0024, 0x0c07, 0x1024, 0x2024,
1176
+ 0x0025, 0x0c08, 0x1025, 0x2025, 0x0026, 0x0c09, 0x1026, 0x2026,
1177
+ 0x0027, 0x0c0a, 0x1027, 0x2027, 0x0028, 0x0c0b, 0x1028, 0x2028,
1178
+ 0x0029, 0x0d04, 0x1029, 0x2029, 0x002a, 0x0d05, 0x102a, 0x202a,
1179
+ 0x002b, 0x0d06, 0x102b, 0x202b, 0x002c, 0x0d07, 0x102c, 0x202c,
1180
+ 0x002d, 0x0d08, 0x102d, 0x202d, 0x002e, 0x0d09, 0x102e, 0x202e,
1181
+ 0x002f, 0x0d0a, 0x102f, 0x202f, 0x0030, 0x0d0b, 0x1030, 0x2030,
1182
+ 0x0031, 0x0e04, 0x1031, 0x2031, 0x0032, 0x0e05, 0x1032, 0x2032,
1183
+ 0x0033, 0x0e06, 0x1033, 0x2033, 0x0034, 0x0e07, 0x1034, 0x2034,
1184
+ 0x0035, 0x0e08, 0x1035, 0x2035, 0x0036, 0x0e09, 0x1036, 0x2036,
1185
+ 0x0037, 0x0e0a, 0x1037, 0x2037, 0x0038, 0x0e0b, 0x1038, 0x2038,
1186
+ 0x0039, 0x0f04, 0x1039, 0x2039, 0x003a, 0x0f05, 0x103a, 0x203a,
1187
+ 0x003b, 0x0f06, 0x103b, 0x203b, 0x003c, 0x0f07, 0x103c, 0x203c,
1188
+ 0x0801, 0x0f08, 0x103d, 0x203d, 0x1001, 0x0f09, 0x103e, 0x203e,
1189
+ 0x1801, 0x0f0a, 0x103f, 0x203f, 0x2001, 0x0f0b, 0x1040, 0x2040
1190
+ };
1191
+
1192
+ struct snappy_decompressor {
1193
+ struct source *reader; /* Underlying source of bytes to decompress */
1194
+ const char *ip; /* Points to next buffered byte */
1195
+ const char *ip_limit; /* Points just past buffered bytes */
1196
+ u32 peeked; /* Bytes peeked from reader (need to skip) */
1197
+ bool eof; /* Hit end of input without an error? */
1198
+ char scratch[5]; /* Temporary buffer for peekfast boundaries */
1199
+ };
1200
+
1201
+ static void
1202
+ init_snappy_decompressor(struct snappy_decompressor *d, struct source *reader)
1203
+ {
1204
+ d->reader = reader;
1205
+ d->ip = NULL;
1206
+ d->ip_limit = NULL;
1207
+ d->peeked = 0;
1208
+ d->eof = false;
1209
+ }
1210
+
1211
+ static void exit_snappy_decompressor(struct snappy_decompressor *d)
1212
+ {
1213
+ skip(d->reader, d->peeked);
1214
+ }
1215
+
1216
+ /*
1217
+ * Read the uncompressed length stored at the start of the compressed data.
1218
+ * On succcess, stores the length in *result and returns true.
1219
+ * On failure, returns false.
1220
+ */
1221
+ static bool read_uncompressed_length(struct snappy_decompressor *d,
1222
+ u32 * result)
1223
+ {
1224
+ DCHECK(d->ip == NULL); /*
1225
+ * Must not have read anything yet
1226
+ * Length is encoded in 1..5 bytes
1227
+ */
1228
+ *result = 0;
1229
+ u32 shift = 0;
1230
+ while (true) {
1231
+ if (shift >= 32)
1232
+ return false;
1233
+ size_t n;
1234
+ const char *ip = peek(d->reader, &n);
1235
+ if (n == 0)
1236
+ return false;
1237
+ const unsigned char c = *(const unsigned char *)(ip);
1238
+ skip(d->reader, 1);
1239
+ *result |= (u32) (c & 0x7f) << shift;
1240
+ if (c < 128) {
1241
+ break;
1242
+ }
1243
+ shift += 7;
1244
+ }
1245
+ return true;
1246
+ }
1247
+
1248
+ static bool refill_tag(struct snappy_decompressor *d);
1249
+
1250
+ /*
1251
+ * Process the next item found in the input.
1252
+ * Returns true if successful, false on error or end of input.
1253
+ */
1254
+ static void decompress_all_tags(struct snappy_decompressor *d,
1255
+ struct writer *writer)
1256
+ {
1257
+ const char *ip = d->ip;
1258
+
1259
+ /*
1260
+ * We could have put this refill fragment only at the beginning of the loop.
1261
+ * However, duplicating it at the end of each branch gives the compiler more
1262
+ * scope to optimize the <ip_limit_ - ip> expression based on the local
1263
+ * context, which overall increases speed.
1264
+ */
1265
+ #define MAYBE_REFILL() \
1266
+ if (d->ip_limit - ip < 5) { \
1267
+ d->ip = ip; \
1268
+ if (!refill_tag(d)) return; \
1269
+ ip = d->ip; \
1270
+ }
1271
+
1272
+
1273
+ MAYBE_REFILL();
1274
+ for (;;) {
1275
+ if (d->ip_limit - ip < 5) {
1276
+ d->ip = ip;
1277
+ if (!refill_tag(d))
1278
+ return;
1279
+ ip = d->ip;
1280
+ }
1281
+
1282
+ const unsigned char c = *(const unsigned char *)(ip++);
1283
+
1284
+ if ((c & 0x3) == LITERAL) {
1285
+ u32 literal_length = (c >> 2) + 1;
1286
+ if (writer_try_fast_append(writer, ip, (u32) (d->ip_limit - ip),
1287
+ literal_length)) {
1288
+ DCHECK_LT(literal_length, 61);
1289
+ ip += literal_length;
1290
+ MAYBE_REFILL();
1291
+ continue;
1292
+ }
1293
+ if (unlikely(literal_length >= 61)) {
1294
+ /* Long literal */
1295
+ const u32 literal_ll = literal_length - 60;
1296
+ literal_length = (get_unaligned_le32(ip) &
1297
+ wordmask[literal_ll]) + 1;
1298
+ ip += literal_ll;
1299
+ }
1300
+
1301
+ u32 avail = (u32) (d->ip_limit - ip);
1302
+ while (avail < literal_length) {
1303
+ if (!writer_append(writer, ip, avail))
1304
+ return;
1305
+ literal_length -= avail;
1306
+ skip(d->reader, d->peeked);
1307
+ size_t n;
1308
+ ip = peek(d->reader, &n);
1309
+ avail = (u32) n;
1310
+ d->peeked = avail;
1311
+ if (avail == 0)
1312
+ return; /* Premature end of input */
1313
+ d->ip_limit = ip + avail;
1314
+ }
1315
+ if (!writer_append(writer, ip, literal_length))
1316
+ return;
1317
+ ip += literal_length;
1318
+ MAYBE_REFILL();
1319
+ } else {
1320
+ const u32 entry = char_table[c];
1321
+ const u32 trailer = get_unaligned_le32(ip) &
1322
+ wordmask[entry >> 11];
1323
+ const u32 length = entry & 0xff;
1324
+ ip += entry >> 11;
1325
+
1326
+ /*
1327
+ * copy_offset/256 is encoded in bits 8..10.
1328
+ * By just fetching those bits, we get
1329
+ * copy_offset (since the bit-field starts at
1330
+ * bit 8).
1331
+ */
1332
+ const u32 copy_offset = entry & 0x700;
1333
+ if (!writer_append_from_self(writer,
1334
+ copy_offset + trailer,
1335
+ length))
1336
+ return;
1337
+ MAYBE_REFILL();
1338
+ }
1339
+ }
1340
+ }
1341
+
1342
+ #undef MAYBE_REFILL
1343
+
1344
+ static bool refill_tag(struct snappy_decompressor *d)
1345
+ {
1346
+ const char *ip = d->ip;
1347
+
1348
+ if (ip == d->ip_limit) {
1349
+ size_t n;
1350
+ /* Fetch a new fragment from the reader */
1351
+ skip(d->reader, d->peeked); /* All peeked bytes are used up */
1352
+ ip = peek(d->reader, &n);
1353
+ d->peeked = (u32) n;
1354
+ if (n == 0) {
1355
+ d->eof = true;
1356
+ return false;
1357
+ }
1358
+ d->ip_limit = ip + n;
1359
+ }
1360
+
1361
+ /* Read the tag character */
1362
+ DCHECK_LT(ip, d->ip_limit);
1363
+ const unsigned char c = *(const unsigned char *)(ip);
1364
+ const u32 entry = char_table[c];
1365
+ const u32 needed = (entry >> 11) + 1; /* +1 byte for 'c' */
1366
+ DCHECK_LE(needed, sizeof(d->scratch));
1367
+
1368
+ /* Read more bytes from reader if needed */
1369
+ u32 nbuf = (u32) (d->ip_limit - ip);
1370
+
1371
+ if (nbuf < needed) {
1372
+ /*
1373
+ * Stitch together bytes from ip and reader to form the word
1374
+ * contents. We store the needed bytes in "scratch". They
1375
+ * will be consumed immediately by the caller since we do not
1376
+ * read more than we need.
1377
+ */
1378
+ memmove(d->scratch, ip, nbuf);
1379
+ skip(d->reader, d->peeked); /* All peeked bytes are used up */
1380
+ d->peeked = 0;
1381
+ while (nbuf < needed) {
1382
+ size_t length;
1383
+ const char *src = peek(d->reader, &length);
1384
+ if (length == 0)
1385
+ return false;
1386
+ u32 to_add = min_t(u32, needed - nbuf, (u32) length);
1387
+ memcpy(d->scratch + nbuf, src, to_add);
1388
+ nbuf += to_add;
1389
+ skip(d->reader, to_add);
1390
+ }
1391
+ DCHECK_EQ(nbuf, needed);
1392
+ d->ip = d->scratch;
1393
+ d->ip_limit = d->scratch + needed;
1394
+ } else if (nbuf < 5) {
1395
+ /*
1396
+ * Have enough bytes, but move into scratch so that we do not
1397
+ * read past end of input
1398
+ */
1399
+ memmove(d->scratch, ip, nbuf);
1400
+ skip(d->reader, d->peeked); /* All peeked bytes are used up */
1401
+ d->peeked = 0;
1402
+ d->ip = d->scratch;
1403
+ d->ip_limit = d->scratch + nbuf;
1404
+ } else {
1405
+ /* Pass pointer to buffer returned by reader. */
1406
+ d->ip = ip;
1407
+ }
1408
+ return true;
1409
+ }
1410
+
1411
+ static int internal_uncompress(struct source *r,
1412
+ struct writer *writer, u32 max_len)
1413
+ {
1414
+ struct snappy_decompressor decompressor;
1415
+ u32 uncompressed_len = 0;
1416
+
1417
+ init_snappy_decompressor(&decompressor, r);
1418
+
1419
+ if (!read_uncompressed_length(&decompressor, &uncompressed_len))
1420
+ return -EIO;
1421
+ /* Protect against possible DoS attack */
1422
+ if ((u64) (uncompressed_len) > max_len)
1423
+ return -EIO;
1424
+
1425
+ writer_set_expected_length(writer, uncompressed_len);
1426
+
1427
+ /* Process the entire input */
1428
+ decompress_all_tags(&decompressor, writer);
1429
+
1430
+ exit_snappy_decompressor(&decompressor);
1431
+ if (decompressor.eof && writer_check_length(writer))
1432
+ return 0;
1433
+ return -EIO;
1434
+ }
1435
+
1436
+ static inline int sn_compress(struct snappy_env *env, struct source *reader,
1437
+ struct sink *writer)
1438
+ {
1439
+ int err;
1440
+ size_t written = 0;
1441
+ int N = available(reader);
1442
+ char ulength[kmax32];
1443
+ char *p = varint_encode32(ulength, N);
1444
+
1445
+ append(writer, ulength, p - ulength);
1446
+ written += (p - ulength);
1447
+
1448
+ while (N > 0) {
1449
+ /* Get next block to compress (without copying if possible) */
1450
+ size_t fragment_size;
1451
+ const char *fragment = peek(reader, &fragment_size);
1452
+ if (fragment_size == 0) {
1453
+ err = -EIO;
1454
+ goto out;
1455
+ }
1456
+ const unsigned num_to_read = min_t(int, N, kblock_size);
1457
+ size_t bytes_read = fragment_size;
1458
+
1459
+ int pending_advance = 0;
1460
+ if (bytes_read >= num_to_read) {
1461
+ /* Buffer returned by reader is large enough */
1462
+ pending_advance = num_to_read;
1463
+ fragment_size = num_to_read;
1464
+ }
1465
+ else {
1466
+ memcpy(env->scratch, fragment, bytes_read);
1467
+ skip(reader, bytes_read);
1468
+
1469
+ while (bytes_read < num_to_read) {
1470
+ fragment = peek(reader, &fragment_size);
1471
+ size_t n =
1472
+ min_t(size_t, fragment_size,
1473
+ num_to_read - bytes_read);
1474
+ memcpy((char *)(env->scratch) + bytes_read, fragment, n);
1475
+ bytes_read += n;
1476
+ skip(reader, n);
1477
+ }
1478
+ DCHECK_EQ(bytes_read, num_to_read);
1479
+ fragment = env->scratch;
1480
+ fragment_size = num_to_read;
1481
+ }
1482
+ if (fragment_size < num_to_read)
1483
+ return -EIO;
1484
+
1485
+ /* Get encoding table for compression */
1486
+ int table_size;
1487
+ u16 *table = get_hash_table(env, num_to_read, &table_size);
1488
+
1489
+ /* Compress input_fragment and append to dest */
1490
+ char *dest;
1491
+ dest = sink_peek(writer, rd_kafka_snappy_max_compressed_length(num_to_read));
1492
+ if (!dest) {
1493
+ /*
1494
+ * Need a scratch buffer for the output,
1495
+ * because the byte sink doesn't have enough
1496
+ * in one piece.
1497
+ */
1498
+ dest = env->scratch_output;
1499
+ }
1500
+ char *end = compress_fragment(fragment, fragment_size,
1501
+ dest, table, table_size);
1502
+ append(writer, dest, end - dest);
1503
+ written += (end - dest);
1504
+
1505
+ N -= num_to_read;
1506
+ skip(reader, pending_advance);
1507
+ }
1508
+
1509
+ err = 0;
1510
+ out:
1511
+ return err;
1512
+ }
1513
+
1514
+ #ifdef SG
1515
+
1516
+ int rd_kafka_snappy_compress_iov(struct snappy_env *env,
1517
+ const struct iovec *iov_in, size_t iov_in_cnt,
1518
+ size_t input_length,
1519
+ struct iovec *iov_out) {
1520
+ struct source reader = {
1521
+ .iov = (struct iovec *)iov_in,
1522
+ .iovlen = (int)iov_in_cnt,
1523
+ .total = input_length
1524
+ };
1525
+ struct sink writer = {
1526
+ .iov = iov_out,
1527
+ .iovlen = 1
1528
+ };
1529
+ int err = sn_compress(env, &reader, &writer);
1530
+
1531
+ iov_out->iov_len = writer.written;
1532
+
1533
+ return err;
1534
+ }
1535
+ EXPORT_SYMBOL(rd_kafka_snappy_compress_iov);
1536
+
1537
+ /**
1538
+ * rd_kafka_snappy_compress - Compress a buffer using the snappy compressor.
1539
+ * @env: Preallocated environment
1540
+ * @input: Input buffer
1541
+ * @input_length: Length of input_buffer
1542
+ * @compressed: Output buffer for compressed data
1543
+ * @compressed_length: The real length of the output written here.
1544
+ *
1545
+ * Return 0 on success, otherwise an negative error code.
1546
+ *
1547
+ * The output buffer must be at least
1548
+ * rd_kafka_snappy_max_compressed_length(input_length) bytes long.
1549
+ *
1550
+ * Requires a preallocated environment from rd_kafka_snappy_init_env.
1551
+ * The environment does not keep state over individual calls
1552
+ * of this function, just preallocates the memory.
1553
+ */
1554
+ int rd_kafka_snappy_compress(struct snappy_env *env,
1555
+ const char *input,
1556
+ size_t input_length,
1557
+ char *compressed, size_t *compressed_length)
1558
+ {
1559
+ struct iovec iov_in = {
1560
+ .iov_base = (char *)input,
1561
+ .iov_len = input_length,
1562
+ };
1563
+ struct iovec iov_out = {
1564
+ .iov_base = compressed,
1565
+ .iov_len = 0xffffffff,
1566
+ };
1567
+ return rd_kafka_snappy_compress_iov(env,
1568
+ &iov_in, 1, input_length,
1569
+ &iov_out);
1570
+ }
1571
+ EXPORT_SYMBOL(rd_kafka_snappy_compress);
1572
+
1573
+ int rd_kafka_snappy_uncompress_iov(struct iovec *iov_in, int iov_in_len,
1574
+ size_t input_len, char *uncompressed)
1575
+ {
1576
+ struct source reader = {
1577
+ .iov = iov_in,
1578
+ .iovlen = iov_in_len,
1579
+ .total = input_len
1580
+ };
1581
+ struct writer output = {
1582
+ .base = uncompressed,
1583
+ .op = uncompressed
1584
+ };
1585
+ return internal_uncompress(&reader, &output, 0xffffffff);
1586
+ }
1587
+ EXPORT_SYMBOL(rd_kafka_snappy_uncompress_iov);
1588
+
1589
+ /**
1590
+ * rd_kafka_snappy_uncompress - Uncompress a snappy compressed buffer
1591
+ * @compressed: Input buffer with compressed data
1592
+ * @n: length of compressed buffer
1593
+ * @uncompressed: buffer for uncompressed data
1594
+ *
1595
+ * The uncompressed data buffer must be at least
1596
+ * rd_kafka_snappy_uncompressed_length(compressed) bytes long.
1597
+ *
1598
+ * Return 0 on success, otherwise an negative error code.
1599
+ */
1600
+ int rd_kafka_snappy_uncompress(const char *compressed, size_t n, char *uncompressed)
1601
+ {
1602
+ struct iovec iov = {
1603
+ .iov_base = (char *)compressed,
1604
+ .iov_len = n
1605
+ };
1606
+ return rd_kafka_snappy_uncompress_iov(&iov, 1, n, uncompressed);
1607
+ }
1608
+ EXPORT_SYMBOL(rd_kafka_snappy_uncompress);
1609
+
1610
+
1611
+ /**
1612
+ * @brief Decompress Snappy message with Snappy-java framing.
1613
+ *
1614
+ * @returns a malloced buffer with the uncompressed data, or NULL on failure.
1615
+ */
1616
+ char *rd_kafka_snappy_java_uncompress (const char *inbuf, size_t inlen,
1617
+ size_t *outlenp,
1618
+ char *errstr, size_t errstr_size) {
1619
+ int pass;
1620
+ char *outbuf = NULL;
1621
+
1622
+ /**
1623
+ * Traverse all chunks in two passes:
1624
+ * pass 1: calculate total uncompressed length
1625
+ * pass 2: uncompress
1626
+ *
1627
+ * Each chunk is prefixed with 4: length */
1628
+
1629
+ for (pass = 1 ; pass <= 2 ; pass++) {
1630
+ ssize_t of = 0; /* inbuf offset */
1631
+ ssize_t uof = 0; /* outbuf offset */
1632
+
1633
+ while (of + 4 <= (ssize_t)inlen) {
1634
+ uint32_t clen; /* compressed length */
1635
+ size_t ulen; /* uncompressed length */
1636
+ int r;
1637
+
1638
+ memcpy(&clen, inbuf+of, 4);
1639
+ clen = be32toh(clen);
1640
+ of += 4;
1641
+
1642
+ if (unlikely(clen > inlen - of)) {
1643
+ rd_snprintf(errstr, errstr_size,
1644
+ "Invalid snappy-java chunk length "
1645
+ "%"PRId32" > %"PRIdsz
1646
+ " available bytes",
1647
+ clen, (ssize_t)inlen - of);
1648
+ return NULL;
1649
+ }
1650
+
1651
+ /* Acquire uncompressed length */
1652
+ if (unlikely(!rd_kafka_snappy_uncompressed_length(
1653
+ inbuf+of, clen, &ulen))) {
1654
+ rd_snprintf(errstr, errstr_size,
1655
+ "Failed to get length of "
1656
+ "(snappy-java framed) Snappy "
1657
+ "compressed payload "
1658
+ "(clen %"PRId32")",
1659
+ clen);
1660
+ return NULL;
1661
+ }
1662
+
1663
+ if (pass == 1) {
1664
+ /* pass 1: calculate total length */
1665
+ of += clen;
1666
+ uof += ulen;
1667
+ continue;
1668
+ }
1669
+
1670
+ /* pass 2: Uncompress to outbuf */
1671
+ if (unlikely((r = rd_kafka_snappy_uncompress(
1672
+ inbuf+of, clen, outbuf+uof)))) {
1673
+ rd_snprintf(errstr, errstr_size,
1674
+ "Failed to decompress Snappy-java "
1675
+ "framed payload of size %"PRId32
1676
+ ": %s",
1677
+ clen,
1678
+ rd_strerror(-r/*negative errno*/));
1679
+ rd_free(outbuf);
1680
+ return NULL;
1681
+ }
1682
+
1683
+ of += clen;
1684
+ uof += ulen;
1685
+ }
1686
+
1687
+ if (unlikely(of != (ssize_t)inlen)) {
1688
+ rd_snprintf(errstr, errstr_size,
1689
+ "%"PRIusz" trailing bytes in Snappy-java "
1690
+ "framed compressed data",
1691
+ inlen - of);
1692
+ if (outbuf)
1693
+ rd_free(outbuf);
1694
+ return NULL;
1695
+ }
1696
+
1697
+ if (pass == 1) {
1698
+ if (uof <= 0) {
1699
+ rd_snprintf(errstr, errstr_size,
1700
+ "Empty Snappy-java framed data");
1701
+ return NULL;
1702
+ }
1703
+
1704
+ /* Allocate memory for uncompressed data */
1705
+ outbuf = rd_malloc(uof);
1706
+ if (unlikely(!outbuf)) {
1707
+ rd_snprintf(errstr, errstr_size,
1708
+ "Failed to allocate memory "
1709
+ "(%"PRIdsz") for "
1710
+ "uncompressed Snappy data: %s",
1711
+ uof, rd_strerror(errno));
1712
+ return NULL;
1713
+ }
1714
+
1715
+ } else {
1716
+ /* pass 2 */
1717
+ *outlenp = uof;
1718
+ }
1719
+ }
1720
+
1721
+ return outbuf;
1722
+ }
1723
+
1724
+
1725
+
1726
+ #else
1727
+ /**
1728
+ * rd_kafka_snappy_compress - Compress a buffer using the snappy compressor.
1729
+ * @env: Preallocated environment
1730
+ * @input: Input buffer
1731
+ * @input_length: Length of input_buffer
1732
+ * @compressed: Output buffer for compressed data
1733
+ * @compressed_length: The real length of the output written here.
1734
+ *
1735
+ * Return 0 on success, otherwise an negative error code.
1736
+ *
1737
+ * The output buffer must be at least
1738
+ * rd_kafka_snappy_max_compressed_length(input_length) bytes long.
1739
+ *
1740
+ * Requires a preallocated environment from rd_kafka_snappy_init_env.
1741
+ * The environment does not keep state over individual calls
1742
+ * of this function, just preallocates the memory.
1743
+ */
1744
+ int rd_kafka_snappy_compress(struct snappy_env *env,
1745
+ const char *input,
1746
+ size_t input_length,
1747
+ char *compressed, size_t *compressed_length)
1748
+ {
1749
+ struct source reader = {
1750
+ .ptr = input,
1751
+ .left = input_length
1752
+ };
1753
+ struct sink writer = {
1754
+ .dest = compressed,
1755
+ };
1756
+ int err = sn_compress(env, &reader, &writer);
1757
+
1758
+ /* Compute how many bytes were added */
1759
+ *compressed_length = (writer.dest - compressed);
1760
+ return err;
1761
+ }
1762
+ EXPORT_SYMBOL(rd_kafka_snappy_compress);
1763
+
1764
+ /**
1765
+ * rd_kafka_snappy_uncompress - Uncompress a snappy compressed buffer
1766
+ * @compressed: Input buffer with compressed data
1767
+ * @n: length of compressed buffer
1768
+ * @uncompressed: buffer for uncompressed data
1769
+ *
1770
+ * The uncompressed data buffer must be at least
1771
+ * rd_kafka_snappy_uncompressed_length(compressed) bytes long.
1772
+ *
1773
+ * Return 0 on success, otherwise an negative error code.
1774
+ */
1775
+ int rd_kafka_snappy_uncompress(const char *compressed, size_t n, char *uncompressed)
1776
+ {
1777
+ struct source reader = {
1778
+ .ptr = compressed,
1779
+ .left = n
1780
+ };
1781
+ struct writer output = {
1782
+ .base = uncompressed,
1783
+ .op = uncompressed
1784
+ };
1785
+ return internal_uncompress(&reader, &output, 0xffffffff);
1786
+ }
1787
+ EXPORT_SYMBOL(rd_kafka_snappy_uncompress);
1788
+ #endif
1789
+
1790
+ static inline void clear_env(struct snappy_env *env)
1791
+ {
1792
+ memset(env, 0, sizeof(*env));
1793
+ }
1794
+
1795
+ #ifdef SG
1796
+ /**
1797
+ * rd_kafka_snappy_init_env_sg - Allocate snappy compression environment
1798
+ * @env: Environment to preallocate
1799
+ * @sg: Input environment ever does scather gather
1800
+ *
1801
+ * If false is passed to sg then multiple entries in an iovec
1802
+ * are not legal.
1803
+ * Returns 0 on success, otherwise negative errno.
1804
+ * Must run in process context.
1805
+ */
1806
+ int rd_kafka_snappy_init_env_sg(struct snappy_env *env, bool sg)
1807
+ {
1808
+ if (rd_kafka_snappy_init_env(env) < 0)
1809
+ goto error;
1810
+
1811
+ if (sg) {
1812
+ env->scratch = vmalloc(kblock_size);
1813
+ if (!env->scratch)
1814
+ goto error;
1815
+ env->scratch_output =
1816
+ vmalloc(rd_kafka_snappy_max_compressed_length(kblock_size));
1817
+ if (!env->scratch_output)
1818
+ goto error;
1819
+ }
1820
+ return 0;
1821
+ error:
1822
+ rd_kafka_snappy_free_env(env);
1823
+ return -ENOMEM;
1824
+ }
1825
+ EXPORT_SYMBOL(rd_kafka_snappy_init_env_sg);
1826
+ #endif
1827
+
1828
+ /**
1829
+ * rd_kafka_snappy_init_env - Allocate snappy compression environment
1830
+ * @env: Environment to preallocate
1831
+ *
1832
+ * Passing multiple entries in an iovec is not allowed
1833
+ * on the environment allocated here.
1834
+ * Returns 0 on success, otherwise negative errno.
1835
+ * Must run in process context.
1836
+ */
1837
+ int rd_kafka_snappy_init_env(struct snappy_env *env)
1838
+ {
1839
+ clear_env(env);
1840
+ env->hash_table = vmalloc(sizeof(u16) * kmax_hash_table_size);
1841
+ if (!env->hash_table)
1842
+ return -ENOMEM;
1843
+ return 0;
1844
+ }
1845
+ EXPORT_SYMBOL(rd_kafka_snappy_init_env);
1846
+
1847
+ /**
1848
+ * rd_kafka_snappy_free_env - Free an snappy compression environment
1849
+ * @env: Environment to free.
1850
+ *
1851
+ * Must run in process context.
1852
+ */
1853
+ void rd_kafka_snappy_free_env(struct snappy_env *env)
1854
+ {
1855
+ vfree(env->hash_table);
1856
+ #ifdef SG
1857
+ vfree(env->scratch);
1858
+ vfree(env->scratch_output);
1859
+ #endif
1860
+ clear_env(env);
1861
+ }
1862
+ EXPORT_SYMBOL(rd_kafka_snappy_free_env);
1863
+
1864
+ #ifdef __GNUC__
1865
+ #pragma GCC diagnostic pop /* -Wcast-align ignore */
1866
+ #endif