lordceaser-baileys 3.4.2 → 3.4.6

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 (301) hide show
  1. package/WAProto/index.js +115856 -5
  2. package/WAProto/package.json +1 -0
  3. package/index.js +37 -21
  4. package/lib/Utils/crypto.js +118 -8
  5. package/lib/Utils/lt-hash.js +8 -3
  6. package/lib/package.json +3 -0
  7. package/node_modules/@protobufjs/aspromise/LICENSE +26 -0
  8. package/node_modules/@protobufjs/aspromise/README.md +13 -0
  9. package/node_modules/@protobufjs/aspromise/index.d.ts +13 -0
  10. package/node_modules/@protobufjs/aspromise/index.js +52 -0
  11. package/node_modules/@protobufjs/aspromise/package.json +21 -0
  12. package/node_modules/@protobufjs/aspromise/tests/index.js +130 -0
  13. package/node_modules/@protobufjs/base64/LICENSE +26 -0
  14. package/node_modules/@protobufjs/base64/README.md +19 -0
  15. package/node_modules/@protobufjs/base64/index.d.ts +32 -0
  16. package/node_modules/@protobufjs/base64/index.js +139 -0
  17. package/node_modules/@protobufjs/base64/package.json +21 -0
  18. package/node_modules/@protobufjs/base64/tests/index.js +46 -0
  19. package/node_modules/@protobufjs/codegen/LICENSE +26 -0
  20. package/node_modules/@protobufjs/codegen/README.md +49 -0
  21. package/node_modules/@protobufjs/codegen/index.d.ts +31 -0
  22. package/node_modules/@protobufjs/codegen/index.js +112 -0
  23. package/node_modules/@protobufjs/codegen/package.json +13 -0
  24. package/node_modules/@protobufjs/codegen/tests/index.js +13 -0
  25. package/node_modules/@protobufjs/eventemitter/CHANGELOG.md +8 -0
  26. package/node_modules/@protobufjs/eventemitter/LICENSE +26 -0
  27. package/node_modules/@protobufjs/eventemitter/README.md +22 -0
  28. package/node_modules/@protobufjs/eventemitter/index.d.ts +45 -0
  29. package/node_modules/@protobufjs/eventemitter/index.js +86 -0
  30. package/node_modules/@protobufjs/eventemitter/package.json +21 -0
  31. package/node_modules/@protobufjs/eventemitter/tests/index.js +83 -0
  32. package/node_modules/@protobufjs/fetch/CHANGELOG.md +8 -0
  33. package/node_modules/@protobufjs/fetch/LICENSE +26 -0
  34. package/node_modules/@protobufjs/fetch/README.md +13 -0
  35. package/node_modules/@protobufjs/fetch/index.d.ts +56 -0
  36. package/node_modules/@protobufjs/fetch/index.js +112 -0
  37. package/node_modules/@protobufjs/fetch/package.json +27 -0
  38. package/node_modules/@protobufjs/fetch/tests/data/file.txt +1 -0
  39. package/node_modules/@protobufjs/fetch/tests/index.js +158 -0
  40. package/node_modules/@protobufjs/fetch/util/fs.js +11 -0
  41. package/node_modules/@protobufjs/float/LICENSE +26 -0
  42. package/node_modules/@protobufjs/float/README.md +102 -0
  43. package/node_modules/@protobufjs/float/bench/index.js +87 -0
  44. package/node_modules/@protobufjs/float/bench/suite.js +46 -0
  45. package/node_modules/@protobufjs/float/index.d.ts +83 -0
  46. package/node_modules/@protobufjs/float/index.js +335 -0
  47. package/node_modules/@protobufjs/float/package.json +26 -0
  48. package/node_modules/@protobufjs/float/tests/index.js +100 -0
  49. package/node_modules/@protobufjs/path/LICENSE +26 -0
  50. package/node_modules/@protobufjs/path/README.md +19 -0
  51. package/node_modules/@protobufjs/path/index.d.ts +22 -0
  52. package/node_modules/@protobufjs/path/index.js +65 -0
  53. package/node_modules/@protobufjs/path/package.json +21 -0
  54. package/node_modules/@protobufjs/path/tests/index.js +60 -0
  55. package/node_modules/@protobufjs/pool/.npmignore +3 -0
  56. package/node_modules/@protobufjs/pool/LICENSE +26 -0
  57. package/node_modules/@protobufjs/pool/README.md +13 -0
  58. package/node_modules/@protobufjs/pool/index.d.ts +32 -0
  59. package/node_modules/@protobufjs/pool/index.js +48 -0
  60. package/node_modules/@protobufjs/pool/package.json +21 -0
  61. package/node_modules/@protobufjs/pool/tests/index.js +33 -0
  62. package/node_modules/@protobufjs/utf8/CHANGELOG.md +8 -0
  63. package/node_modules/@protobufjs/utf8/LICENSE +26 -0
  64. package/node_modules/@protobufjs/utf8/README.md +20 -0
  65. package/node_modules/@protobufjs/utf8/index.d.ts +24 -0
  66. package/node_modules/@protobufjs/utf8/index.js +115 -0
  67. package/node_modules/@protobufjs/utf8/package.json +21 -0
  68. package/node_modules/@protobufjs/utf8/tests/data/surrogate_pair_bug.txt +207 -0
  69. package/node_modules/@protobufjs/utf8/tests/data/utf8.txt +216 -0
  70. package/node_modules/@protobufjs/utf8/tests/index.js +79 -0
  71. package/node_modules/@types/node/LICENSE +21 -0
  72. package/node_modules/@types/node/README.md +15 -0
  73. package/node_modules/@types/node/assert/strict.d.ts +8 -0
  74. package/node_modules/@types/node/assert.d.ts +1062 -0
  75. package/node_modules/@types/node/async_hooks.d.ts +605 -0
  76. package/node_modules/@types/node/buffer.buffer.d.ts +471 -0
  77. package/node_modules/@types/node/buffer.d.ts +1936 -0
  78. package/node_modules/@types/node/child_process.d.ts +1475 -0
  79. package/node_modules/@types/node/cluster.d.ts +577 -0
  80. package/node_modules/@types/node/compatibility/disposable.d.ts +16 -0
  81. package/node_modules/@types/node/compatibility/index.d.ts +9 -0
  82. package/node_modules/@types/node/compatibility/indexable.d.ts +20 -0
  83. package/node_modules/@types/node/compatibility/iterators.d.ts +21 -0
  84. package/node_modules/@types/node/console.d.ts +452 -0
  85. package/node_modules/@types/node/constants.d.ts +21 -0
  86. package/node_modules/@types/node/crypto.d.ts +4590 -0
  87. package/node_modules/@types/node/dgram.d.ts +597 -0
  88. package/node_modules/@types/node/diagnostics_channel.d.ts +578 -0
  89. package/node_modules/@types/node/dns/promises.d.ts +479 -0
  90. package/node_modules/@types/node/dns.d.ts +871 -0
  91. package/node_modules/@types/node/domain.d.ts +170 -0
  92. package/node_modules/@types/node/events.d.ts +977 -0
  93. package/node_modules/@types/node/fs/promises.d.ts +1270 -0
  94. package/node_modules/@types/node/fs.d.ts +4375 -0
  95. package/node_modules/@types/node/globals.d.ts +172 -0
  96. package/node_modules/@types/node/globals.typedarray.d.ts +38 -0
  97. package/node_modules/@types/node/http.d.ts +2049 -0
  98. package/node_modules/@types/node/http2.d.ts +2712 -0
  99. package/node_modules/@types/node/https.d.ts +578 -0
  100. package/node_modules/@types/node/index.d.ts +93 -0
  101. package/node_modules/@types/node/inspector.generated.d.ts +3966 -0
  102. package/node_modules/@types/node/module.d.ts +539 -0
  103. package/node_modules/@types/node/net.d.ts +1031 -0
  104. package/node_modules/@types/node/os.d.ts +506 -0
  105. package/node_modules/@types/node/package.json +140 -0
  106. package/node_modules/@types/node/path.d.ts +200 -0
  107. package/node_modules/@types/node/perf_hooks.d.ts +961 -0
  108. package/node_modules/@types/node/process.d.ts +1961 -0
  109. package/node_modules/@types/node/punycode.d.ts +117 -0
  110. package/node_modules/@types/node/querystring.d.ts +152 -0
  111. package/node_modules/@types/node/readline/promises.d.ts +162 -0
  112. package/node_modules/@types/node/readline.d.ts +589 -0
  113. package/node_modules/@types/node/repl.d.ts +430 -0
  114. package/node_modules/@types/node/sea.d.ts +153 -0
  115. package/node_modules/@types/node/stream/consumers.d.ts +38 -0
  116. package/node_modules/@types/node/stream/promises.d.ts +90 -0
  117. package/node_modules/@types/node/stream/web.d.ts +533 -0
  118. package/node_modules/@types/node/stream.d.ts +1698 -0
  119. package/node_modules/@types/node/string_decoder.d.ts +67 -0
  120. package/node_modules/@types/node/test.d.ts +1787 -0
  121. package/node_modules/@types/node/timers/promises.d.ts +108 -0
  122. package/node_modules/@types/node/timers.d.ts +286 -0
  123. package/node_modules/@types/node/tls.d.ts +1259 -0
  124. package/node_modules/@types/node/trace_events.d.ts +197 -0
  125. package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +468 -0
  126. package/node_modules/@types/node/ts5.6/globals.typedarray.d.ts +34 -0
  127. package/node_modules/@types/node/ts5.6/index.d.ts +93 -0
  128. package/node_modules/@types/node/tty.d.ts +208 -0
  129. package/node_modules/@types/node/url.d.ts +964 -0
  130. package/node_modules/@types/node/util.d.ts +2331 -0
  131. package/node_modules/@types/node/v8.d.ts +809 -0
  132. package/node_modules/@types/node/vm.d.ts +1001 -0
  133. package/node_modules/@types/node/wasi.d.ts +181 -0
  134. package/node_modules/@types/node/web-globals/abortcontroller.d.ts +34 -0
  135. package/node_modules/@types/node/web-globals/domexception.d.ts +68 -0
  136. package/node_modules/@types/node/web-globals/events.d.ts +97 -0
  137. package/node_modules/@types/node/web-globals/fetch.d.ts +55 -0
  138. package/node_modules/@types/node/worker_threads.d.ts +715 -0
  139. package/node_modules/@types/node/zlib.d.ts +598 -0
  140. package/node_modules/curve25519-js/.prettierrc +6 -0
  141. package/node_modules/curve25519-js/LICENSE +19 -0
  142. package/node_modules/curve25519-js/README.md +111 -0
  143. package/node_modules/curve25519-js/lib/index.d.ts +69 -0
  144. package/node_modules/curve25519-js/lib/index.js +1669 -0
  145. package/node_modules/curve25519-js/package.json +34 -0
  146. package/node_modules/curve25519-js/tsconfig.json +20 -0
  147. package/node_modules/curve25519-js/tslint.json +10 -0
  148. package/node_modules/libsignal/LICENSE +621 -0
  149. package/node_modules/libsignal/README.md +64 -0
  150. package/node_modules/libsignal/index.d.ts +55 -0
  151. package/node_modules/libsignal/index.js +10 -0
  152. package/node_modules/libsignal/package.json +34 -0
  153. package/node_modules/libsignal/src/.eslintrc.json +31 -0
  154. package/node_modules/libsignal/src/WhisperTextProtocol.js +933 -0
  155. package/node_modules/libsignal/src/base_key_type.js +7 -0
  156. package/node_modules/libsignal/src/chain_type.js +6 -0
  157. package/node_modules/libsignal/src/crypto.d.ts +19 -0
  158. package/node_modules/libsignal/src/crypto.js +98 -0
  159. package/node_modules/libsignal/src/curve.d.ts +22 -0
  160. package/node_modules/libsignal/src/curve.js +142 -0
  161. package/node_modules/libsignal/src/errors.js +33 -0
  162. package/node_modules/libsignal/src/keyhelper.js +45 -0
  163. package/node_modules/libsignal/src/numeric_fingerprint.js +72 -0
  164. package/node_modules/libsignal/src/protobufs.js +10 -0
  165. package/node_modules/libsignal/src/protocol_address.js +40 -0
  166. package/node_modules/libsignal/src/queue_job.js +69 -0
  167. package/node_modules/libsignal/src/session_builder.js +164 -0
  168. package/node_modules/libsignal/src/session_cipher.js +336 -0
  169. package/node_modules/libsignal/src/session_record.js +316 -0
  170. package/node_modules/long/LICENSE +202 -0
  171. package/node_modules/long/README.md +286 -0
  172. package/node_modules/long/index.d.ts +2 -0
  173. package/node_modules/long/index.js +1581 -0
  174. package/node_modules/long/package.json +58 -0
  175. package/node_modules/long/types.d.ts +474 -0
  176. package/node_modules/long/umd/index.d.ts +3 -0
  177. package/node_modules/long/umd/index.js +1622 -0
  178. package/node_modules/long/umd/package.json +3 -0
  179. package/node_modules/long/umd/types.d.ts +474 -0
  180. package/node_modules/protobufjs/LICENSE +39 -0
  181. package/node_modules/protobufjs/README.md +727 -0
  182. package/node_modules/protobufjs/dist/light/protobuf.js +8094 -0
  183. package/node_modules/protobufjs/dist/light/protobuf.js.map +1 -0
  184. package/node_modules/protobufjs/dist/light/protobuf.min.js +8 -0
  185. package/node_modules/protobufjs/dist/light/protobuf.min.js.map +1 -0
  186. package/node_modules/protobufjs/dist/minimal/protobuf.js +2811 -0
  187. package/node_modules/protobufjs/dist/minimal/protobuf.js.map +1 -0
  188. package/node_modules/protobufjs/dist/minimal/protobuf.min.js +8 -0
  189. package/node_modules/protobufjs/dist/minimal/protobuf.min.js.map +1 -0
  190. package/node_modules/protobufjs/dist/protobuf.js +9921 -0
  191. package/node_modules/protobufjs/dist/protobuf.js.map +1 -0
  192. package/node_modules/protobufjs/dist/protobuf.min.js +8 -0
  193. package/node_modules/protobufjs/dist/protobuf.min.js.map +1 -0
  194. package/node_modules/protobufjs/ext/debug/README.md +4 -0
  195. package/node_modules/protobufjs/ext/debug/index.js +71 -0
  196. package/node_modules/protobufjs/ext/descriptor/README.md +72 -0
  197. package/node_modules/protobufjs/ext/descriptor/index.d.ts +195 -0
  198. package/node_modules/protobufjs/ext/descriptor/index.js +1186 -0
  199. package/node_modules/protobufjs/ext/descriptor/test.js +54 -0
  200. package/node_modules/protobufjs/google/LICENSE +27 -0
  201. package/node_modules/protobufjs/google/README.md +1 -0
  202. package/node_modules/protobufjs/google/api/annotations.json +83 -0
  203. package/node_modules/protobufjs/google/api/annotations.proto +11 -0
  204. package/node_modules/protobufjs/google/api/http.json +86 -0
  205. package/node_modules/protobufjs/google/api/http.proto +31 -0
  206. package/node_modules/protobufjs/google/protobuf/api.json +118 -0
  207. package/node_modules/protobufjs/google/protobuf/api.proto +34 -0
  208. package/node_modules/protobufjs/google/protobuf/descriptor.json +1382 -0
  209. package/node_modules/protobufjs/google/protobuf/descriptor.proto +535 -0
  210. package/node_modules/protobufjs/google/protobuf/source_context.json +20 -0
  211. package/node_modules/protobufjs/google/protobuf/source_context.proto +7 -0
  212. package/node_modules/protobufjs/google/protobuf/type.json +202 -0
  213. package/node_modules/protobufjs/google/protobuf/type.proto +89 -0
  214. package/node_modules/protobufjs/index.d.ts +2832 -0
  215. package/node_modules/protobufjs/index.js +4 -0
  216. package/node_modules/protobufjs/light.d.ts +2 -0
  217. package/node_modules/protobufjs/light.js +4 -0
  218. package/node_modules/protobufjs/minimal.d.ts +2 -0
  219. package/node_modules/protobufjs/minimal.js +4 -0
  220. package/node_modules/protobufjs/package.json +119 -0
  221. package/node_modules/protobufjs/scripts/postinstall.js +32 -0
  222. package/node_modules/protobufjs/src/common.js +399 -0
  223. package/node_modules/protobufjs/src/converter.js +318 -0
  224. package/node_modules/protobufjs/src/decoder.js +164 -0
  225. package/node_modules/protobufjs/src/encoder.js +103 -0
  226. package/node_modules/protobufjs/src/enum.js +226 -0
  227. package/node_modules/protobufjs/src/field.js +453 -0
  228. package/node_modules/protobufjs/src/index-light.js +104 -0
  229. package/node_modules/protobufjs/src/index-minimal.js +36 -0
  230. package/node_modules/protobufjs/src/index.js +12 -0
  231. package/node_modules/protobufjs/src/mapfield.js +126 -0
  232. package/node_modules/protobufjs/src/message.js +143 -0
  233. package/node_modules/protobufjs/src/method.js +160 -0
  234. package/node_modules/protobufjs/src/namespace.js +558 -0
  235. package/node_modules/protobufjs/src/object.js +382 -0
  236. package/node_modules/protobufjs/src/oneof.js +222 -0
  237. package/node_modules/protobufjs/src/parse.js +992 -0
  238. package/node_modules/protobufjs/src/reader.js +446 -0
  239. package/node_modules/protobufjs/src/reader_buffer.js +51 -0
  240. package/node_modules/protobufjs/src/root.js +412 -0
  241. package/node_modules/protobufjs/src/roots.js +18 -0
  242. package/node_modules/protobufjs/src/rpc/service.js +142 -0
  243. package/node_modules/protobufjs/src/rpc.js +36 -0
  244. package/node_modules/protobufjs/src/service.js +193 -0
  245. package/node_modules/protobufjs/src/tokenize.js +416 -0
  246. package/node_modules/protobufjs/src/type.js +632 -0
  247. package/node_modules/protobufjs/src/types.js +196 -0
  248. package/node_modules/protobufjs/src/typescript.jsdoc +15 -0
  249. package/node_modules/protobufjs/src/util/fs.js +11 -0
  250. package/node_modules/protobufjs/src/util/longbits.js +200 -0
  251. package/node_modules/protobufjs/src/util/minimal.js +491 -0
  252. package/node_modules/protobufjs/src/util/patterns.js +7 -0
  253. package/node_modules/protobufjs/src/util.js +230 -0
  254. package/node_modules/protobufjs/src/verifier.js +180 -0
  255. package/node_modules/protobufjs/src/wrappers.js +111 -0
  256. package/node_modules/protobufjs/src/writer.js +467 -0
  257. package/node_modules/protobufjs/src/writer_buffer.js +85 -0
  258. package/node_modules/protobufjs/tsconfig.json +8 -0
  259. package/node_modules/undici-types/LICENSE +21 -0
  260. package/node_modules/undici-types/README.md +6 -0
  261. package/node_modules/undici-types/agent.d.ts +31 -0
  262. package/node_modules/undici-types/api.d.ts +43 -0
  263. package/node_modules/undici-types/balanced-pool.d.ts +29 -0
  264. package/node_modules/undici-types/cache.d.ts +36 -0
  265. package/node_modules/undici-types/client.d.ts +108 -0
  266. package/node_modules/undici-types/connector.d.ts +34 -0
  267. package/node_modules/undici-types/content-type.d.ts +21 -0
  268. package/node_modules/undici-types/cookies.d.ts +28 -0
  269. package/node_modules/undici-types/diagnostics-channel.d.ts +66 -0
  270. package/node_modules/undici-types/dispatcher.d.ts +256 -0
  271. package/node_modules/undici-types/env-http-proxy-agent.d.ts +21 -0
  272. package/node_modules/undici-types/errors.d.ts +149 -0
  273. package/node_modules/undici-types/eventsource.d.ts +61 -0
  274. package/node_modules/undici-types/fetch.d.ts +209 -0
  275. package/node_modules/undici-types/file.d.ts +39 -0
  276. package/node_modules/undici-types/filereader.d.ts +54 -0
  277. package/node_modules/undici-types/formdata.d.ts +108 -0
  278. package/node_modules/undici-types/global-dispatcher.d.ts +9 -0
  279. package/node_modules/undici-types/global-origin.d.ts +7 -0
  280. package/node_modules/undici-types/handlers.d.ts +15 -0
  281. package/node_modules/undici-types/header.d.ts +4 -0
  282. package/node_modules/undici-types/index.d.ts +71 -0
  283. package/node_modules/undici-types/interceptors.d.ts +17 -0
  284. package/node_modules/undici-types/mock-agent.d.ts +50 -0
  285. package/node_modules/undici-types/mock-client.d.ts +25 -0
  286. package/node_modules/undici-types/mock-errors.d.ts +12 -0
  287. package/node_modules/undici-types/mock-interceptor.d.ts +93 -0
  288. package/node_modules/undici-types/mock-pool.d.ts +25 -0
  289. package/node_modules/undici-types/package.json +55 -0
  290. package/node_modules/undici-types/patch.d.ts +33 -0
  291. package/node_modules/undici-types/pool-stats.d.ts +19 -0
  292. package/node_modules/undici-types/pool.d.ts +39 -0
  293. package/node_modules/undici-types/proxy-agent.d.ts +28 -0
  294. package/node_modules/undici-types/readable.d.ts +65 -0
  295. package/node_modules/undici-types/retry-agent.d.ts +8 -0
  296. package/node_modules/undici-types/retry-handler.d.ts +116 -0
  297. package/node_modules/undici-types/util.d.ts +18 -0
  298. package/node_modules/undici-types/webidl.d.ts +228 -0
  299. package/node_modules/undici-types/websocket.d.ts +150 -0
  300. package/package.json +65 -29
  301. package/WAProto/_orig.js +0 -115856
@@ -0,0 +1,2811 @@
1
+ /*!
2
+ * protobuf.js v7.6.6 (c) 2016, daniel wirtz
3
+ * compiled thu, 27 aug 2026 10:13:18 utc
4
+ * licensed under the bsd-3-clause license
5
+ * see: https://github.com/dcodeio/protobuf.js for details
6
+ */
7
+ (function(undefined){"use strict";(function prelude(modules, cache, entries) {
8
+
9
+ // This is the prelude used to bundle protobuf.js for the browser. Wraps up the CommonJS
10
+ // sources through a conflict-free require shim and is again wrapped within an iife that
11
+ // provides a minification-friendly `undefined` var plus a global "use strict" directive
12
+ // so that minification can remove the directives of each module.
13
+
14
+ function $require(name) {
15
+ var $module = cache[name];
16
+ if (!$module)
17
+ modules[name][0].call($module = cache[name] = { exports: {} }, $require, $module, $module.exports);
18
+ return $module.exports;
19
+ }
20
+
21
+ var protobuf = $require(entries[0]);
22
+
23
+ // Expose globally
24
+ protobuf.util.global.protobuf = protobuf;
25
+
26
+ // Be nice to AMD
27
+ if (typeof define === "function" && define.amd)
28
+ define(["long"], function(Long) {
29
+ if (Long && Long.isLong) {
30
+ protobuf.util.Long = Long;
31
+ protobuf.configure();
32
+ }
33
+ return protobuf;
34
+ });
35
+
36
+ // Be nice to CommonJS
37
+ if (typeof module === "object" && module && module.exports)
38
+ module.exports = protobuf;
39
+
40
+ })/* end of prelude */({1:[function(require,module,exports){
41
+ "use strict";
42
+ module.exports = asPromise;
43
+
44
+ /**
45
+ * Callback as used by {@link util.asPromise}.
46
+ * @typedef asPromiseCallback
47
+ * @type {function}
48
+ * @param {Error|null} error Error, if any
49
+ * @param {...*} params Additional arguments
50
+ * @returns {undefined}
51
+ */
52
+
53
+ /**
54
+ * Returns a promise from a node-style callback function.
55
+ * @memberof util
56
+ * @param {asPromiseCallback} fn Function to call
57
+ * @param {*} ctx Function context
58
+ * @param {...*} params Function arguments
59
+ * @returns {Promise<*>} Promisified function
60
+ */
61
+ function asPromise(fn, ctx/*, varargs */) {
62
+ var params = new Array(arguments.length - 1),
63
+ offset = 0,
64
+ index = 2,
65
+ pending = true;
66
+ while (index < arguments.length)
67
+ params[offset++] = arguments[index++];
68
+ return new Promise(function executor(resolve, reject) {
69
+ params[offset] = function callback(err/*, varargs */) {
70
+ if (pending) {
71
+ pending = false;
72
+ if (err)
73
+ reject(err);
74
+ else {
75
+ var params = new Array(arguments.length - 1),
76
+ offset = 0;
77
+ while (offset < params.length)
78
+ params[offset++] = arguments[offset];
79
+ resolve.apply(null, params);
80
+ }
81
+ }
82
+ };
83
+ try {
84
+ fn.apply(ctx || null, params);
85
+ } catch (err) {
86
+ if (pending) {
87
+ pending = false;
88
+ reject(err);
89
+ }
90
+ }
91
+ });
92
+ }
93
+
94
+ },{}],2:[function(require,module,exports){
95
+ "use strict";
96
+
97
+ /**
98
+ * A minimal base64 implementation for number arrays.
99
+ * @memberof util
100
+ * @namespace
101
+ */
102
+ var base64 = exports;
103
+
104
+ /**
105
+ * Calculates the byte length of a base64 encoded string.
106
+ * @param {string} string Base64 encoded string
107
+ * @returns {number} Byte length
108
+ */
109
+ base64.length = function length(string) {
110
+ var p = string.length;
111
+ if (!p)
112
+ return 0;
113
+ var n = 0;
114
+ while (--p % 4 > 1 && string.charAt(p) === "=")
115
+ ++n;
116
+ return Math.ceil(string.length * 3) / 4 - n;
117
+ };
118
+
119
+ // Base64 encoding table
120
+ var b64 = new Array(64);
121
+
122
+ // Base64 decoding table
123
+ var s64 = new Array(123);
124
+
125
+ // 65..90, 97..122, 48..57, 43, 47
126
+ for (var i = 0; i < 64;)
127
+ s64[b64[i] = i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i - 59 | 43] = i++;
128
+
129
+ /**
130
+ * Encodes a buffer to a base64 encoded string.
131
+ * @param {Uint8Array} buffer Source buffer
132
+ * @param {number} start Source start
133
+ * @param {number} end Source end
134
+ * @returns {string} Base64 encoded string
135
+ */
136
+ base64.encode = function encode(buffer, start, end) {
137
+ var parts = null,
138
+ chunk = [];
139
+ var i = 0, // output index
140
+ j = 0, // goto index
141
+ t; // temporary
142
+ while (start < end) {
143
+ var b = buffer[start++];
144
+ switch (j) {
145
+ case 0:
146
+ chunk[i++] = b64[b >> 2];
147
+ t = (b & 3) << 4;
148
+ j = 1;
149
+ break;
150
+ case 1:
151
+ chunk[i++] = b64[t | b >> 4];
152
+ t = (b & 15) << 2;
153
+ j = 2;
154
+ break;
155
+ case 2:
156
+ chunk[i++] = b64[t | b >> 6];
157
+ chunk[i++] = b64[b & 63];
158
+ j = 0;
159
+ break;
160
+ }
161
+ if (i > 8191) {
162
+ (parts || (parts = [])).push(String.fromCharCode.apply(String, chunk));
163
+ i = 0;
164
+ }
165
+ }
166
+ if (j) {
167
+ chunk[i++] = b64[t];
168
+ chunk[i++] = 61;
169
+ if (j === 1)
170
+ chunk[i++] = 61;
171
+ }
172
+ if (parts) {
173
+ if (i)
174
+ parts.push(String.fromCharCode.apply(String, chunk.slice(0, i)));
175
+ return parts.join("");
176
+ }
177
+ return String.fromCharCode.apply(String, chunk.slice(0, i));
178
+ };
179
+
180
+ var invalidEncoding = "invalid encoding";
181
+
182
+ /**
183
+ * Decodes a base64 encoded string to a buffer.
184
+ * @param {string} string Source string
185
+ * @param {Uint8Array} buffer Destination buffer
186
+ * @param {number} offset Destination offset
187
+ * @returns {number} Number of bytes written
188
+ * @throws {Error} If encoding is invalid
189
+ */
190
+ base64.decode = function decode(string, buffer, offset) {
191
+ var start = offset;
192
+ var j = 0, // goto index
193
+ t; // temporary
194
+ for (var i = 0; i < string.length;) {
195
+ var c = string.charCodeAt(i++);
196
+ if (c === 61 && j > 1)
197
+ break;
198
+ if ((c = s64[c]) === undefined)
199
+ throw Error(invalidEncoding);
200
+ switch (j) {
201
+ case 0:
202
+ t = c;
203
+ j = 1;
204
+ break;
205
+ case 1:
206
+ buffer[offset++] = t << 2 | (c & 48) >> 4;
207
+ t = c;
208
+ j = 2;
209
+ break;
210
+ case 2:
211
+ buffer[offset++] = (t & 15) << 4 | (c & 60) >> 2;
212
+ t = c;
213
+ j = 3;
214
+ break;
215
+ case 3:
216
+ buffer[offset++] = (t & 3) << 6 | c;
217
+ j = 0;
218
+ break;
219
+ }
220
+ }
221
+ if (j === 1)
222
+ throw Error(invalidEncoding);
223
+ return offset - start;
224
+ };
225
+
226
+ /**
227
+ * Tests if the specified string appears to be base64 encoded.
228
+ * @param {string} string String to test
229
+ * @returns {boolean} `true` if probably base64 encoded, otherwise false
230
+ */
231
+ base64.test = function test(string) {
232
+ return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(string);
233
+ };
234
+
235
+ },{}],3:[function(require,module,exports){
236
+ "use strict";
237
+ module.exports = EventEmitter;
238
+
239
+ /**
240
+ * Constructs a new event emitter instance.
241
+ * @classdesc A minimal event emitter.
242
+ * @memberof util
243
+ * @constructor
244
+ */
245
+ function EventEmitter() {
246
+
247
+ /**
248
+ * Registered listeners.
249
+ * @type {Object.<string,*>}
250
+ * @private
251
+ */
252
+ this._listeners = Object.create(null);
253
+ }
254
+
255
+ /**
256
+ * Event listener as used by {@link util.EventEmitter}.
257
+ * @typedef EventEmitterListener
258
+ * @type {function}
259
+ * @param {...*} args Arguments
260
+ * @returns {undefined}
261
+ */
262
+
263
+ /**
264
+ * Registers an event listener.
265
+ * @param {string} evt Event name
266
+ * @param {EventEmitterListener} fn Listener
267
+ * @param {*} [ctx] Listener context
268
+ * @returns {this} `this`
269
+ */
270
+ EventEmitter.prototype.on = function on(evt, fn, ctx) {
271
+ (this._listeners[evt] || (this._listeners[evt] = [])).push({
272
+ fn : fn,
273
+ ctx : ctx || this
274
+ });
275
+ return this;
276
+ };
277
+
278
+ /**
279
+ * Removes an event listener or any matching listeners if arguments are omitted.
280
+ * @param {string} [evt] Event name. Removes all listeners if omitted.
281
+ * @param {EventEmitterListener} [fn] Listener to remove. Removes all listeners of `evt` if omitted.
282
+ * @returns {this} `this`
283
+ */
284
+ EventEmitter.prototype.off = function off(evt, fn) {
285
+ if (evt === undefined)
286
+ this._listeners = Object.create(null);
287
+ else {
288
+ if (fn === undefined)
289
+ this._listeners[evt] = [];
290
+ else {
291
+ var listeners = this._listeners[evt];
292
+ if (!listeners)
293
+ return this;
294
+ for (var i = 0; i < listeners.length;)
295
+ if (listeners[i].fn === fn)
296
+ listeners.splice(i, 1);
297
+ else
298
+ ++i;
299
+ }
300
+ }
301
+ return this;
302
+ };
303
+
304
+ /**
305
+ * Emits an event by calling its listeners with the specified arguments.
306
+ * @param {string} evt Event name
307
+ * @param {...*} args Arguments
308
+ * @returns {this} `this`
309
+ */
310
+ EventEmitter.prototype.emit = function emit(evt) {
311
+ var listeners = this._listeners[evt];
312
+ if (listeners) {
313
+ var args = [],
314
+ i = 1;
315
+ for (; i < arguments.length;)
316
+ args.push(arguments[i++]);
317
+ for (i = 0; i < listeners.length;)
318
+ listeners[i].fn.apply(listeners[i++].ctx, args);
319
+ }
320
+ return this;
321
+ };
322
+
323
+ },{}],4:[function(require,module,exports){
324
+ "use strict";
325
+
326
+ module.exports = factory(factory);
327
+
328
+ /**
329
+ * Reads / writes floats / doubles from / to buffers.
330
+ * @name util.float
331
+ * @namespace
332
+ */
333
+
334
+ /**
335
+ * Writes a 32 bit float to a buffer using little endian byte order.
336
+ * @name util.float.writeFloatLE
337
+ * @function
338
+ * @param {number} val Value to write
339
+ * @param {Uint8Array} buf Target buffer
340
+ * @param {number} pos Target buffer offset
341
+ * @returns {undefined}
342
+ */
343
+
344
+ /**
345
+ * Writes a 32 bit float to a buffer using big endian byte order.
346
+ * @name util.float.writeFloatBE
347
+ * @function
348
+ * @param {number} val Value to write
349
+ * @param {Uint8Array} buf Target buffer
350
+ * @param {number} pos Target buffer offset
351
+ * @returns {undefined}
352
+ */
353
+
354
+ /**
355
+ * Reads a 32 bit float from a buffer using little endian byte order.
356
+ * @name util.float.readFloatLE
357
+ * @function
358
+ * @param {Uint8Array} buf Source buffer
359
+ * @param {number} pos Source buffer offset
360
+ * @returns {number} Value read
361
+ */
362
+
363
+ /**
364
+ * Reads a 32 bit float from a buffer using big endian byte order.
365
+ * @name util.float.readFloatBE
366
+ * @function
367
+ * @param {Uint8Array} buf Source buffer
368
+ * @param {number} pos Source buffer offset
369
+ * @returns {number} Value read
370
+ */
371
+
372
+ /**
373
+ * Writes a 64 bit double to a buffer using little endian byte order.
374
+ * @name util.float.writeDoubleLE
375
+ * @function
376
+ * @param {number} val Value to write
377
+ * @param {Uint8Array} buf Target buffer
378
+ * @param {number} pos Target buffer offset
379
+ * @returns {undefined}
380
+ */
381
+
382
+ /**
383
+ * Writes a 64 bit double to a buffer using big endian byte order.
384
+ * @name util.float.writeDoubleBE
385
+ * @function
386
+ * @param {number} val Value to write
387
+ * @param {Uint8Array} buf Target buffer
388
+ * @param {number} pos Target buffer offset
389
+ * @returns {undefined}
390
+ */
391
+
392
+ /**
393
+ * Reads a 64 bit double from a buffer using little endian byte order.
394
+ * @name util.float.readDoubleLE
395
+ * @function
396
+ * @param {Uint8Array} buf Source buffer
397
+ * @param {number} pos Source buffer offset
398
+ * @returns {number} Value read
399
+ */
400
+
401
+ /**
402
+ * Reads a 64 bit double from a buffer using big endian byte order.
403
+ * @name util.float.readDoubleBE
404
+ * @function
405
+ * @param {Uint8Array} buf Source buffer
406
+ * @param {number} pos Source buffer offset
407
+ * @returns {number} Value read
408
+ */
409
+
410
+ // Factory function for the purpose of node-based testing in modified global environments
411
+ function factory(exports) {
412
+
413
+ // float: typed array
414
+ if (typeof Float32Array !== "undefined") (function() {
415
+
416
+ var f32 = new Float32Array([ -0 ]),
417
+ f8b = new Uint8Array(f32.buffer),
418
+ le = f8b[3] === 128;
419
+
420
+ function writeFloat_f32_cpy(val, buf, pos) {
421
+ f32[0] = val;
422
+ buf[pos ] = f8b[0];
423
+ buf[pos + 1] = f8b[1];
424
+ buf[pos + 2] = f8b[2];
425
+ buf[pos + 3] = f8b[3];
426
+ }
427
+
428
+ function writeFloat_f32_rev(val, buf, pos) {
429
+ f32[0] = val;
430
+ buf[pos ] = f8b[3];
431
+ buf[pos + 1] = f8b[2];
432
+ buf[pos + 2] = f8b[1];
433
+ buf[pos + 3] = f8b[0];
434
+ }
435
+
436
+ /* istanbul ignore next */
437
+ exports.writeFloatLE = le ? writeFloat_f32_cpy : writeFloat_f32_rev;
438
+ /* istanbul ignore next */
439
+ exports.writeFloatBE = le ? writeFloat_f32_rev : writeFloat_f32_cpy;
440
+
441
+ function readFloat_f32_cpy(buf, pos) {
442
+ f8b[0] = buf[pos ];
443
+ f8b[1] = buf[pos + 1];
444
+ f8b[2] = buf[pos + 2];
445
+ f8b[3] = buf[pos + 3];
446
+ return f32[0];
447
+ }
448
+
449
+ function readFloat_f32_rev(buf, pos) {
450
+ f8b[3] = buf[pos ];
451
+ f8b[2] = buf[pos + 1];
452
+ f8b[1] = buf[pos + 2];
453
+ f8b[0] = buf[pos + 3];
454
+ return f32[0];
455
+ }
456
+
457
+ /* istanbul ignore next */
458
+ exports.readFloatLE = le ? readFloat_f32_cpy : readFloat_f32_rev;
459
+ /* istanbul ignore next */
460
+ exports.readFloatBE = le ? readFloat_f32_rev : readFloat_f32_cpy;
461
+
462
+ // float: ieee754
463
+ })(); else (function() {
464
+
465
+ function writeFloat_ieee754(writeUint, val, buf, pos) {
466
+ var sign = val < 0 ? 1 : 0;
467
+ if (sign)
468
+ val = -val;
469
+ if (val === 0)
470
+ writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos);
471
+ else if (isNaN(val))
472
+ writeUint(2143289344, buf, pos);
473
+ else if (val > 3.4028234663852886e+38) // +-Infinity
474
+ writeUint((sign << 31 | 2139095040) >>> 0, buf, pos);
475
+ else if (val < 1.1754943508222875e-38) // denormal
476
+ writeUint((sign << 31 | Math.round(val / 1.401298464324817e-45)) >>> 0, buf, pos);
477
+ else {
478
+ var exponent = Math.floor(Math.log(val) / Math.LN2),
479
+ mantissa = Math.round(val * Math.pow(2, -exponent) * 8388608) & 8388607;
480
+ writeUint((sign << 31 | exponent + 127 << 23 | mantissa) >>> 0, buf, pos);
481
+ }
482
+ }
483
+
484
+ exports.writeFloatLE = writeFloat_ieee754.bind(null, writeUintLE);
485
+ exports.writeFloatBE = writeFloat_ieee754.bind(null, writeUintBE);
486
+
487
+ function readFloat_ieee754(readUint, buf, pos) {
488
+ var uint = readUint(buf, pos),
489
+ sign = (uint >> 31) * 2 + 1,
490
+ exponent = uint >>> 23 & 255,
491
+ mantissa = uint & 8388607;
492
+ return exponent === 255
493
+ ? mantissa
494
+ ? NaN
495
+ : sign * Infinity
496
+ : exponent === 0 // denormal
497
+ ? sign * 1.401298464324817e-45 * mantissa
498
+ : sign * Math.pow(2, exponent - 150) * (mantissa + 8388608);
499
+ }
500
+
501
+ exports.readFloatLE = readFloat_ieee754.bind(null, readUintLE);
502
+ exports.readFloatBE = readFloat_ieee754.bind(null, readUintBE);
503
+
504
+ })();
505
+
506
+ // double: typed array
507
+ if (typeof Float64Array !== "undefined") (function() {
508
+
509
+ var f64 = new Float64Array([-0]),
510
+ f8b = new Uint8Array(f64.buffer),
511
+ le = f8b[7] === 128;
512
+
513
+ function writeDouble_f64_cpy(val, buf, pos) {
514
+ f64[0] = val;
515
+ buf[pos ] = f8b[0];
516
+ buf[pos + 1] = f8b[1];
517
+ buf[pos + 2] = f8b[2];
518
+ buf[pos + 3] = f8b[3];
519
+ buf[pos + 4] = f8b[4];
520
+ buf[pos + 5] = f8b[5];
521
+ buf[pos + 6] = f8b[6];
522
+ buf[pos + 7] = f8b[7];
523
+ }
524
+
525
+ function writeDouble_f64_rev(val, buf, pos) {
526
+ f64[0] = val;
527
+ buf[pos ] = f8b[7];
528
+ buf[pos + 1] = f8b[6];
529
+ buf[pos + 2] = f8b[5];
530
+ buf[pos + 3] = f8b[4];
531
+ buf[pos + 4] = f8b[3];
532
+ buf[pos + 5] = f8b[2];
533
+ buf[pos + 6] = f8b[1];
534
+ buf[pos + 7] = f8b[0];
535
+ }
536
+
537
+ /* istanbul ignore next */
538
+ exports.writeDoubleLE = le ? writeDouble_f64_cpy : writeDouble_f64_rev;
539
+ /* istanbul ignore next */
540
+ exports.writeDoubleBE = le ? writeDouble_f64_rev : writeDouble_f64_cpy;
541
+
542
+ function readDouble_f64_cpy(buf, pos) {
543
+ f8b[0] = buf[pos ];
544
+ f8b[1] = buf[pos + 1];
545
+ f8b[2] = buf[pos + 2];
546
+ f8b[3] = buf[pos + 3];
547
+ f8b[4] = buf[pos + 4];
548
+ f8b[5] = buf[pos + 5];
549
+ f8b[6] = buf[pos + 6];
550
+ f8b[7] = buf[pos + 7];
551
+ return f64[0];
552
+ }
553
+
554
+ function readDouble_f64_rev(buf, pos) {
555
+ f8b[7] = buf[pos ];
556
+ f8b[6] = buf[pos + 1];
557
+ f8b[5] = buf[pos + 2];
558
+ f8b[4] = buf[pos + 3];
559
+ f8b[3] = buf[pos + 4];
560
+ f8b[2] = buf[pos + 5];
561
+ f8b[1] = buf[pos + 6];
562
+ f8b[0] = buf[pos + 7];
563
+ return f64[0];
564
+ }
565
+
566
+ /* istanbul ignore next */
567
+ exports.readDoubleLE = le ? readDouble_f64_cpy : readDouble_f64_rev;
568
+ /* istanbul ignore next */
569
+ exports.readDoubleBE = le ? readDouble_f64_rev : readDouble_f64_cpy;
570
+
571
+ // double: ieee754
572
+ })(); else (function() {
573
+
574
+ function writeDouble_ieee754(writeUint, off0, off1, val, buf, pos) {
575
+ var sign = val < 0 ? 1 : 0;
576
+ if (sign)
577
+ val = -val;
578
+ if (val === 0) {
579
+ writeUint(0, buf, pos + off0);
580
+ writeUint(1 / val > 0 ? /* positive */ 0 : /* negative 0 */ 2147483648, buf, pos + off1);
581
+ } else if (isNaN(val)) {
582
+ writeUint(0, buf, pos + off0);
583
+ writeUint(2146959360, buf, pos + off1);
584
+ } else if (val > 1.7976931348623157e+308) { // +-Infinity
585
+ writeUint(0, buf, pos + off0);
586
+ writeUint((sign << 31 | 2146435072) >>> 0, buf, pos + off1);
587
+ } else {
588
+ var mantissa;
589
+ if (val < 2.2250738585072014e-308) { // denormal
590
+ mantissa = val / 5e-324;
591
+ writeUint(mantissa >>> 0, buf, pos + off0);
592
+ writeUint((sign << 31 | mantissa / 4294967296) >>> 0, buf, pos + off1);
593
+ } else {
594
+ var exponent = Math.floor(Math.log(val) / Math.LN2);
595
+ if (exponent === 1024)
596
+ exponent = 1023;
597
+ mantissa = val * Math.pow(2, -exponent);
598
+ writeUint(mantissa * 4503599627370496 >>> 0, buf, pos + off0);
599
+ writeUint((sign << 31 | exponent + 1023 << 20 | mantissa * 1048576 & 1048575) >>> 0, buf, pos + off1);
600
+ }
601
+ }
602
+ }
603
+
604
+ exports.writeDoubleLE = writeDouble_ieee754.bind(null, writeUintLE, 0, 4);
605
+ exports.writeDoubleBE = writeDouble_ieee754.bind(null, writeUintBE, 4, 0);
606
+
607
+ function readDouble_ieee754(readUint, off0, off1, buf, pos) {
608
+ var lo = readUint(buf, pos + off0),
609
+ hi = readUint(buf, pos + off1);
610
+ var sign = (hi >> 31) * 2 + 1,
611
+ exponent = hi >>> 20 & 2047,
612
+ mantissa = 4294967296 * (hi & 1048575) + lo;
613
+ return exponent === 2047
614
+ ? mantissa
615
+ ? NaN
616
+ : sign * Infinity
617
+ : exponent === 0 // denormal
618
+ ? sign * 5e-324 * mantissa
619
+ : sign * Math.pow(2, exponent - 1075) * (mantissa + 4503599627370496);
620
+ }
621
+
622
+ exports.readDoubleLE = readDouble_ieee754.bind(null, readUintLE, 0, 4);
623
+ exports.readDoubleBE = readDouble_ieee754.bind(null, readUintBE, 4, 0);
624
+
625
+ })();
626
+
627
+ return exports;
628
+ }
629
+
630
+ // uint helpers
631
+
632
+ function writeUintLE(val, buf, pos) {
633
+ buf[pos ] = val & 255;
634
+ buf[pos + 1] = val >>> 8 & 255;
635
+ buf[pos + 2] = val >>> 16 & 255;
636
+ buf[pos + 3] = val >>> 24;
637
+ }
638
+
639
+ function writeUintBE(val, buf, pos) {
640
+ buf[pos ] = val >>> 24;
641
+ buf[pos + 1] = val >>> 16 & 255;
642
+ buf[pos + 2] = val >>> 8 & 255;
643
+ buf[pos + 3] = val & 255;
644
+ }
645
+
646
+ function readUintLE(buf, pos) {
647
+ return (buf[pos ]
648
+ | buf[pos + 1] << 8
649
+ | buf[pos + 2] << 16
650
+ | buf[pos + 3] << 24) >>> 0;
651
+ }
652
+
653
+ function readUintBE(buf, pos) {
654
+ return (buf[pos ] << 24
655
+ | buf[pos + 1] << 16
656
+ | buf[pos + 2] << 8
657
+ | buf[pos + 3]) >>> 0;
658
+ }
659
+
660
+ },{}],5:[function(require,module,exports){
661
+ "use strict";
662
+ module.exports = pool;
663
+
664
+ /**
665
+ * An allocator as used by {@link util.pool}.
666
+ * @typedef PoolAllocator
667
+ * @type {function}
668
+ * @param {number} size Buffer size
669
+ * @returns {Uint8Array} Buffer
670
+ */
671
+
672
+ /**
673
+ * A slicer as used by {@link util.pool}.
674
+ * @typedef PoolSlicer
675
+ * @type {function}
676
+ * @param {number} start Start offset
677
+ * @param {number} end End offset
678
+ * @returns {Uint8Array} Buffer slice
679
+ * @this {Uint8Array}
680
+ */
681
+
682
+ /**
683
+ * A general purpose buffer pool.
684
+ * @memberof util
685
+ * @function
686
+ * @param {PoolAllocator} alloc Allocator
687
+ * @param {PoolSlicer} slice Slicer
688
+ * @param {number} [size=8192] Slab size
689
+ * @returns {PoolAllocator} Pooled allocator
690
+ */
691
+ function pool(alloc, slice, size) {
692
+ var SIZE = size || 8192;
693
+ var MAX = SIZE >>> 1;
694
+ var slab = null;
695
+ var offset = SIZE;
696
+ return function pool_alloc(size) {
697
+ if (size < 1 || size > MAX)
698
+ return alloc(size);
699
+ if (offset + size > SIZE) {
700
+ slab = alloc(SIZE);
701
+ offset = 0;
702
+ }
703
+ var buf = slice.call(slab, offset, offset += size);
704
+ if (offset & 7) // align to 32 bit
705
+ offset = (offset | 7) + 1;
706
+ return buf;
707
+ };
708
+ }
709
+
710
+ },{}],6:[function(require,module,exports){
711
+ "use strict";
712
+
713
+ /**
714
+ * A minimal UTF8 implementation for number arrays.
715
+ * @memberof util
716
+ * @namespace
717
+ */
718
+ var utf8 = exports,
719
+ replacementChar = "\ufffd";
720
+
721
+ /**
722
+ * Calculates the UTF8 byte length of a string.
723
+ * @param {string} string String
724
+ * @returns {number} Byte length
725
+ */
726
+ utf8.length = function utf8_length(string) {
727
+ var len = 0,
728
+ c = 0;
729
+ for (var i = 0; i < string.length; ++i) {
730
+ c = string.charCodeAt(i);
731
+ if (c < 128)
732
+ len += 1;
733
+ else if (c < 2048)
734
+ len += 2;
735
+ else if ((c & 0xFC00) === 0xD800 && (string.charCodeAt(i + 1) & 0xFC00) === 0xDC00) {
736
+ ++i;
737
+ len += 4;
738
+ } else
739
+ len += 3;
740
+ }
741
+ return len;
742
+ };
743
+
744
+ /**
745
+ * Reads UTF8 bytes as a string.
746
+ * @param {Uint8Array} buffer Source buffer
747
+ * @param {number} start Source start
748
+ * @param {number} end Source end
749
+ * @returns {string} String read
750
+ */
751
+ utf8.read = function utf8_read(buffer, start, end) {
752
+ if (end - start < 1) {
753
+ return "";
754
+ }
755
+
756
+ var str = "";
757
+ for (var i = start; i < end;) {
758
+ var t = buffer[i++];
759
+ if (t <= 0x7F) {
760
+ str += String.fromCharCode(t);
761
+ } else if (t >= 0xC0 && t < 0xE0) {
762
+ var c2 = (t & 0x1F) << 6 | buffer[i++] & 0x3F;
763
+ str += c2 >= 0x80 ? String.fromCharCode(c2) : replacementChar;
764
+ } else if (t >= 0xE0 && t < 0xF0) {
765
+ var c3 = (t & 0xF) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
766
+ str += c3 >= 0x800 ? String.fromCharCode(c3) : replacementChar;
767
+ } else if (t >= 0xF0) {
768
+ var t2 = (t & 7) << 18 | (buffer[i++] & 0x3F) << 12 | (buffer[i++] & 0x3F) << 6 | buffer[i++] & 0x3F;
769
+ if (t2 < 0x10000 || t2 > 0x10FFFF)
770
+ str += replacementChar;
771
+ else {
772
+ t2 -= 0x10000;
773
+ str += String.fromCharCode(0xD800 + (t2 >> 10));
774
+ str += String.fromCharCode(0xDC00 + (t2 & 0x3FF));
775
+ }
776
+ }
777
+ }
778
+
779
+ return str;
780
+ };
781
+
782
+ /**
783
+ * Writes a string as UTF8 bytes.
784
+ * @param {string} string Source string
785
+ * @param {Uint8Array} buffer Destination buffer
786
+ * @param {number} offset Destination offset
787
+ * @returns {number} Bytes written
788
+ */
789
+ utf8.write = function utf8_write(string, buffer, offset) {
790
+ var start = offset,
791
+ c1, // character 1
792
+ c2; // character 2
793
+ for (var i = 0; i < string.length; ++i) {
794
+ c1 = string.charCodeAt(i);
795
+ if (c1 < 128) {
796
+ buffer[offset++] = c1;
797
+ } else if (c1 < 2048) {
798
+ buffer[offset++] = c1 >> 6 | 192;
799
+ buffer[offset++] = c1 & 63 | 128;
800
+ } else if ((c1 & 0xFC00) === 0xD800 && ((c2 = string.charCodeAt(i + 1)) & 0xFC00) === 0xDC00) {
801
+ c1 = 0x10000 + ((c1 & 0x03FF) << 10) + (c2 & 0x03FF);
802
+ ++i;
803
+ buffer[offset++] = c1 >> 18 | 240;
804
+ buffer[offset++] = c1 >> 12 & 63 | 128;
805
+ buffer[offset++] = c1 >> 6 & 63 | 128;
806
+ buffer[offset++] = c1 & 63 | 128;
807
+ } else {
808
+ buffer[offset++] = c1 >> 12 | 224;
809
+ buffer[offset++] = c1 >> 6 & 63 | 128;
810
+ buffer[offset++] = c1 & 63 | 128;
811
+ }
812
+ }
813
+ return offset - start;
814
+ };
815
+
816
+ },{}],7:[function(require,module,exports){
817
+ "use strict";
818
+ var protobuf = exports;
819
+
820
+ /**
821
+ * Build type, one of `"full"`, `"light"` or `"minimal"`.
822
+ * @name build
823
+ * @type {string}
824
+ * @const
825
+ */
826
+ protobuf.build = "minimal";
827
+
828
+ // Serialization
829
+ protobuf.Writer = require(15);
830
+ protobuf.BufferWriter = require(16);
831
+ protobuf.Reader = require(8);
832
+ protobuf.BufferReader = require(9);
833
+
834
+ // Utility
835
+ protobuf.util = require(14);
836
+ protobuf.rpc = require(11);
837
+ protobuf.roots = require(10);
838
+ protobuf.configure = configure;
839
+
840
+ /* istanbul ignore next */
841
+ /**
842
+ * Reconfigures the library according to the environment.
843
+ * @returns {undefined}
844
+ */
845
+ function configure() {
846
+ protobuf.util._configure();
847
+ protobuf.Writer._configure(protobuf.BufferWriter);
848
+ protobuf.Reader._configure(protobuf.BufferReader);
849
+ }
850
+
851
+ // Set up buffer utility according to the environment
852
+ configure();
853
+
854
+ },{"10":10,"11":11,"14":14,"15":15,"16":16,"8":8,"9":9}],8:[function(require,module,exports){
855
+ "use strict";
856
+ module.exports = Reader;
857
+
858
+ var util = require(14);
859
+
860
+ var BufferReader; // cyclic
861
+
862
+ var LongBits = util.LongBits,
863
+ utf8 = util.utf8;
864
+
865
+ /* istanbul ignore next */
866
+ function indexOutOfRange(reader, writeLength) {
867
+ return RangeError("index out of range: " + reader.pos + " + " + (writeLength || 1) + " > " + reader.len);
868
+ }
869
+
870
+ /**
871
+ * Constructs a new reader instance using the specified buffer.
872
+ * @classdesc Wire format reader using `Uint8Array` if available, otherwise `Array`.
873
+ * @constructor
874
+ * @param {Uint8Array} buffer Buffer to read from
875
+ */
876
+ function Reader(buffer) {
877
+
878
+ /**
879
+ * Read buffer.
880
+ * @type {Uint8Array}
881
+ */
882
+ this.buf = buffer;
883
+
884
+ /**
885
+ * Read buffer position.
886
+ * @type {number}
887
+ */
888
+ this.pos = 0;
889
+
890
+ /**
891
+ * Read buffer length.
892
+ * @type {number}
893
+ */
894
+ this.len = buffer.length;
895
+ }
896
+
897
+ var create_array = typeof Uint8Array !== "undefined"
898
+ ? function create_typed_array(buffer) {
899
+ if (buffer instanceof Uint8Array || Array.isArray(buffer))
900
+ return new Reader(buffer);
901
+ throw Error("illegal buffer");
902
+ }
903
+ /* istanbul ignore next */
904
+ : function create_array(buffer) {
905
+ if (Array.isArray(buffer))
906
+ return new Reader(buffer);
907
+ throw Error("illegal buffer");
908
+ };
909
+
910
+ var create = function create() {
911
+ return util.Buffer
912
+ ? function create_buffer_setup(buffer) {
913
+ return (Reader.create = function create_buffer(buffer) {
914
+ return util.Buffer.isBuffer(buffer)
915
+ ? new BufferReader(buffer)
916
+ /* istanbul ignore next */
917
+ : create_array(buffer);
918
+ })(buffer);
919
+ }
920
+ /* istanbul ignore next */
921
+ : create_array;
922
+ };
923
+
924
+ /**
925
+ * Creates a new reader using the specified buffer.
926
+ * @function
927
+ * @param {Uint8Array|Buffer} buffer Buffer to read from
928
+ * @returns {Reader|BufferReader} A {@link BufferReader} if `buffer` is a Buffer, otherwise a {@link Reader}
929
+ * @throws {Error} If `buffer` is not a valid buffer
930
+ */
931
+ Reader.create = create();
932
+
933
+ Reader.prototype._slice = util.Array.prototype.subarray || /* istanbul ignore next */ util.Array.prototype.slice;
934
+
935
+ function readVarint32NearEnd(reader) {
936
+ // Safely read up to four bytes of a varint32 near the reader limit
937
+ var value = 0;
938
+ for (var i = 0; i < 4; ++i) {
939
+ if (reader.pos >= reader.len)
940
+ throw indexOutOfRange(reader);
941
+ var b = reader.buf[reader.pos++];
942
+ value = (value | (b & 127) << i * 7) >>> 0;
943
+ if (b < 128)
944
+ return value;
945
+ }
946
+ throw indexOutOfRange(reader);
947
+ }
948
+
949
+ /**
950
+ * Reads a varint as an unsigned 32 bit value.
951
+ * @function
952
+ * @returns {number} Value read
953
+ */
954
+ Reader.prototype.uint32 = (function read_uint32_setup() {
955
+ var value = 4294967295; // optimizer type-hint, tends to deopt otherwise (?!)
956
+ return function read_uint32() {
957
+ if (this.len - this.pos < 5) {
958
+ if (this.pos >= this.len)
959
+ throw indexOutOfRange(this);
960
+ if (this.buf[this.pos] >= 128)
961
+ return readVarint32NearEnd(this);
962
+ }
963
+ value = ( this.buf[this.pos] & 127 ) >>> 0; if (this.buf[this.pos++] < 128) return value;
964
+ value = (value | (this.buf[this.pos] & 127) << 7) >>> 0; if (this.buf[this.pos++] < 128) return value;
965
+ value = (value | (this.buf[this.pos] & 127) << 14) >>> 0; if (this.buf[this.pos++] < 128) return value;
966
+ value = (value | (this.buf[this.pos] & 127) << 21) >>> 0; if (this.buf[this.pos++] < 128) return value;
967
+ value = (value | (this.buf[this.pos] & 15) << 28) >>> 0; if (this.buf[this.pos++] < 128) return value;
968
+
969
+ /* istanbul ignore if */
970
+ if ((this.pos += 5) > this.len) {
971
+ this.pos = this.len;
972
+ throw indexOutOfRange(this, 10);
973
+ }
974
+ return value;
975
+ };
976
+ })();
977
+
978
+ /**
979
+ * Reads a varint as a signed 32 bit value.
980
+ * @returns {number} Value read
981
+ */
982
+ Reader.prototype.int32 = function read_int32() {
983
+ return this.uint32() | 0;
984
+ };
985
+
986
+ /**
987
+ * Reads a zig-zag encoded varint as a signed 32 bit value.
988
+ * @returns {number} Value read
989
+ */
990
+ Reader.prototype.sint32 = function read_sint32() {
991
+ var value = this.uint32();
992
+ return value >>> 1 ^ -(value & 1) | 0;
993
+ };
994
+
995
+ /* eslint-disable no-invalid-this */
996
+
997
+ function readLongVarint() {
998
+ // tends to deopt with local vars for octet etc.
999
+ var bits = new LongBits(0, 0);
1000
+ var i = 0;
1001
+ if (this.len - this.pos > 4) { // fast route (lo)
1002
+ for (; i < 4; ++i) {
1003
+ // 1st..4th
1004
+ bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
1005
+ if (this.buf[this.pos++] < 128)
1006
+ return bits;
1007
+ }
1008
+ // 5th
1009
+ bits.lo = (bits.lo | (this.buf[this.pos] & 127) << 28) >>> 0;
1010
+ bits.hi = (bits.hi | (this.buf[this.pos] & 127) >> 4) >>> 0;
1011
+ if (this.buf[this.pos++] < 128)
1012
+ return bits;
1013
+ i = 0;
1014
+ } else {
1015
+ for (; i < 3; ++i) {
1016
+ /* istanbul ignore if */
1017
+ if (this.pos >= this.len)
1018
+ throw indexOutOfRange(this);
1019
+ // 1st..3th
1020
+ bits.lo = (bits.lo | (this.buf[this.pos] & 127) << i * 7) >>> 0;
1021
+ if (this.buf[this.pos++] < 128)
1022
+ return bits;
1023
+ }
1024
+ // 4th
1025
+ bits.lo = (bits.lo | (this.buf[this.pos++] & 127) << i * 7) >>> 0;
1026
+ return bits;
1027
+ }
1028
+ if (this.len - this.pos > 4) { // fast route (hi)
1029
+ for (; i < 5; ++i) {
1030
+ // 6th..10th
1031
+ bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
1032
+ if (this.buf[this.pos++] < 128)
1033
+ return bits;
1034
+ }
1035
+ } else {
1036
+ for (; i < 5; ++i) {
1037
+ /* istanbul ignore if */
1038
+ if (this.pos >= this.len)
1039
+ throw indexOutOfRange(this);
1040
+ // 6th..10th
1041
+ bits.hi = (bits.hi | (this.buf[this.pos] & 127) << i * 7 + 3) >>> 0;
1042
+ if (this.buf[this.pos++] < 128)
1043
+ return bits;
1044
+ }
1045
+ }
1046
+ /* istanbul ignore next */
1047
+ throw Error("invalid varint encoding");
1048
+ }
1049
+
1050
+ /* eslint-enable no-invalid-this */
1051
+
1052
+ /**
1053
+ * Reads a varint as a signed 64 bit value.
1054
+ * @name Reader#int64
1055
+ * @function
1056
+ * @returns {Long} Value read
1057
+ */
1058
+
1059
+ /**
1060
+ * Reads a varint as an unsigned 64 bit value.
1061
+ * @name Reader#uint64
1062
+ * @function
1063
+ * @returns {Long} Value read
1064
+ */
1065
+
1066
+ /**
1067
+ * Reads a zig-zag encoded varint as a signed 64 bit value.
1068
+ * @name Reader#sint64
1069
+ * @function
1070
+ * @returns {Long} Value read
1071
+ */
1072
+
1073
+ /**
1074
+ * Reads a varint as a boolean.
1075
+ * @returns {boolean} Value read
1076
+ */
1077
+ Reader.prototype.bool = function read_bool() {
1078
+ return this.uint32() !== 0;
1079
+ };
1080
+
1081
+ function readFixed32_end(buf, end) { // note that this uses `end`, not `pos`
1082
+ return (buf[end - 4]
1083
+ | buf[end - 3] << 8
1084
+ | buf[end - 2] << 16
1085
+ | buf[end - 1] << 24) >>> 0;
1086
+ }
1087
+
1088
+ /**
1089
+ * Reads fixed 32 bits as an unsigned 32 bit integer.
1090
+ * @returns {number} Value read
1091
+ */
1092
+ Reader.prototype.fixed32 = function read_fixed32() {
1093
+
1094
+ /* istanbul ignore if */
1095
+ if (this.pos + 4 > this.len)
1096
+ throw indexOutOfRange(this, 4);
1097
+
1098
+ return readFixed32_end(this.buf, this.pos += 4);
1099
+ };
1100
+
1101
+ /**
1102
+ * Reads fixed 32 bits as a signed 32 bit integer.
1103
+ * @returns {number} Value read
1104
+ */
1105
+ Reader.prototype.sfixed32 = function read_sfixed32() {
1106
+
1107
+ /* istanbul ignore if */
1108
+ if (this.pos + 4 > this.len)
1109
+ throw indexOutOfRange(this, 4);
1110
+
1111
+ return readFixed32_end(this.buf, this.pos += 4) | 0;
1112
+ };
1113
+
1114
+ /* eslint-disable no-invalid-this */
1115
+
1116
+ function readFixed64(/* this: Reader */) {
1117
+
1118
+ /* istanbul ignore if */
1119
+ if (this.pos + 8 > this.len)
1120
+ throw indexOutOfRange(this, 8);
1121
+
1122
+ return new LongBits(readFixed32_end(this.buf, this.pos += 4), readFixed32_end(this.buf, this.pos += 4));
1123
+ }
1124
+
1125
+ /* eslint-enable no-invalid-this */
1126
+
1127
+ /**
1128
+ * Reads fixed 64 bits.
1129
+ * @name Reader#fixed64
1130
+ * @function
1131
+ * @returns {Long} Value read
1132
+ */
1133
+
1134
+ /**
1135
+ * Reads zig-zag encoded fixed 64 bits.
1136
+ * @name Reader#sfixed64
1137
+ * @function
1138
+ * @returns {Long} Value read
1139
+ */
1140
+
1141
+ /**
1142
+ * Reads a float (32 bit) as a number.
1143
+ * @function
1144
+ * @returns {number} Value read
1145
+ */
1146
+ Reader.prototype.float = function read_float() {
1147
+
1148
+ /* istanbul ignore if */
1149
+ if (this.pos + 4 > this.len)
1150
+ throw indexOutOfRange(this, 4);
1151
+
1152
+ var value = util.float.readFloatLE(this.buf, this.pos);
1153
+ this.pos += 4;
1154
+ return value;
1155
+ };
1156
+
1157
+ /**
1158
+ * Reads a double (64 bit float) as a number.
1159
+ * @function
1160
+ * @returns {number} Value read
1161
+ */
1162
+ Reader.prototype.double = function read_double() {
1163
+
1164
+ /* istanbul ignore if */
1165
+ if (this.pos + 8 > this.len)
1166
+ throw indexOutOfRange(this, 4);
1167
+
1168
+ var value = util.float.readDoubleLE(this.buf, this.pos);
1169
+ this.pos += 8;
1170
+ return value;
1171
+ };
1172
+
1173
+ /**
1174
+ * Reads a sequence of bytes preceeded by its length as a varint.
1175
+ * @returns {Uint8Array} Value read
1176
+ */
1177
+ Reader.prototype.bytes = function read_bytes() {
1178
+ var length = this.uint32(),
1179
+ start = this.pos,
1180
+ end = this.pos + length;
1181
+
1182
+ /* istanbul ignore if */
1183
+ if (end > this.len)
1184
+ throw indexOutOfRange(this, length);
1185
+
1186
+ this.pos += length;
1187
+ if (Array.isArray(this.buf)) // plain array
1188
+ return this.buf.slice(start, end);
1189
+
1190
+ if (start === end) { // fix for IE 10/Win8 and others' subarray returning array of size 1
1191
+ var nativeBuffer = util.Buffer;
1192
+ return nativeBuffer
1193
+ ? nativeBuffer.alloc(0)
1194
+ : new this.buf.constructor(0);
1195
+ }
1196
+ return this._slice.call(this.buf, start, end);
1197
+ };
1198
+
1199
+ /**
1200
+ * Reads a string preceeded by its byte length as a varint.
1201
+ * @returns {string} Value read
1202
+ */
1203
+ Reader.prototype.string = function read_string() {
1204
+ var bytes = this.bytes();
1205
+ return utf8.read(bytes, 0, bytes.length);
1206
+ };
1207
+
1208
+ /**
1209
+ * Skips the specified number of bytes if specified, otherwise skips a varint.
1210
+ * @param {number} [length] Length if known, otherwise a varint is assumed
1211
+ * @returns {Reader} `this`
1212
+ */
1213
+ Reader.prototype.skip = function skip(length) {
1214
+ if (typeof length === "number") {
1215
+ /* istanbul ignore if */
1216
+ if (this.pos + length > this.len)
1217
+ throw indexOutOfRange(this, length);
1218
+ this.pos += length;
1219
+ } else {
1220
+ do {
1221
+ /* istanbul ignore if */
1222
+ if (this.pos >= this.len)
1223
+ throw indexOutOfRange(this);
1224
+ } while (this.buf[this.pos++] & 128);
1225
+ }
1226
+ return this;
1227
+ };
1228
+
1229
+ /**
1230
+ * Recursion limit.
1231
+ * @type {number}
1232
+ */
1233
+ Reader.recursionLimit = util.recursionLimit;
1234
+
1235
+ /**
1236
+ * Skips the next element of the specified wire type.
1237
+ * @param {number} wireType Wire type received
1238
+ * @param {number} [depth] Depth of recursion to control nested calls; 0 if omitted
1239
+ * @returns {Reader} `this`
1240
+ */
1241
+ Reader.prototype.skipType = function(wireType, depth) {
1242
+ if (depth === undefined) depth = 0;
1243
+ if (depth > Reader.recursionLimit)
1244
+ throw Error("maximum nesting depth exceeded");
1245
+ switch (wireType) {
1246
+ case 0:
1247
+ this.skip();
1248
+ break;
1249
+ case 1:
1250
+ this.skip(8);
1251
+ break;
1252
+ case 2:
1253
+ this.skip(this.uint32());
1254
+ break;
1255
+ case 3:
1256
+ while ((wireType = this.uint32() & 7) !== 4) {
1257
+ this.skipType(wireType, depth + 1);
1258
+ }
1259
+ break;
1260
+ case 5:
1261
+ this.skip(4);
1262
+ break;
1263
+
1264
+ /* istanbul ignore next */
1265
+ default:
1266
+ throw Error("invalid wire type " + wireType + " at offset " + this.pos);
1267
+ }
1268
+ return this;
1269
+ };
1270
+
1271
+ Reader._configure = function(BufferReader_) {
1272
+ BufferReader = BufferReader_;
1273
+ Reader.create = create();
1274
+ BufferReader._configure();
1275
+
1276
+ var fn = util.Long ? "toLong" : /* istanbul ignore next */ "toNumber";
1277
+ util.merge(Reader.prototype, {
1278
+
1279
+ int64: function read_int64() {
1280
+ return readLongVarint.call(this)[fn](false);
1281
+ },
1282
+
1283
+ uint64: function read_uint64() {
1284
+ return readLongVarint.call(this)[fn](true);
1285
+ },
1286
+
1287
+ sint64: function read_sint64() {
1288
+ return readLongVarint.call(this).zzDecode()[fn](false);
1289
+ },
1290
+
1291
+ fixed64: function read_fixed64() {
1292
+ return readFixed64.call(this)[fn](true);
1293
+ },
1294
+
1295
+ sfixed64: function read_sfixed64() {
1296
+ return readFixed64.call(this)[fn](false);
1297
+ }
1298
+
1299
+ });
1300
+ };
1301
+
1302
+ },{"14":14}],9:[function(require,module,exports){
1303
+ "use strict";
1304
+ module.exports = BufferReader;
1305
+
1306
+ // extends Reader
1307
+ var Reader = require(8);
1308
+ (BufferReader.prototype = Object.create(Reader.prototype)).constructor = BufferReader;
1309
+
1310
+ var util = require(14);
1311
+
1312
+ /**
1313
+ * Constructs a new buffer reader instance.
1314
+ * @classdesc Wire format reader using node buffers.
1315
+ * @extends Reader
1316
+ * @constructor
1317
+ * @param {Buffer} buffer Buffer to read from
1318
+ */
1319
+ function BufferReader(buffer) {
1320
+ Reader.call(this, buffer);
1321
+
1322
+ /**
1323
+ * Read buffer.
1324
+ * @name BufferReader#buf
1325
+ * @type {Buffer}
1326
+ */
1327
+ }
1328
+
1329
+ BufferReader._configure = function () {
1330
+ /* istanbul ignore else */
1331
+ if (util.Buffer)
1332
+ BufferReader.prototype._slice = util.Buffer.prototype.slice;
1333
+ };
1334
+
1335
+
1336
+ /**
1337
+ * @override
1338
+ */
1339
+ BufferReader.prototype.string = function read_string_buffer() {
1340
+ var len = this.uint32(); // modifies pos
1341
+ return this.buf.utf8Slice
1342
+ ? this.buf.utf8Slice(this.pos, this.pos = Math.min(this.pos + len, this.len))
1343
+ : this.buf.toString("utf-8", this.pos, this.pos = Math.min(this.pos + len, this.len));
1344
+ };
1345
+
1346
+ /**
1347
+ * Reads a sequence of bytes preceeded by its length as a varint.
1348
+ * @name BufferReader#bytes
1349
+ * @function
1350
+ * @returns {Buffer} Value read
1351
+ */
1352
+
1353
+ BufferReader._configure();
1354
+
1355
+ },{"14":14,"8":8}],10:[function(require,module,exports){
1356
+ "use strict";
1357
+ module.exports = Object.create(null);
1358
+
1359
+ /**
1360
+ * Named roots.
1361
+ * This is where pbjs stores generated structures (the option `-r, --root` specifies a name).
1362
+ * Can also be used manually to make roots available across modules.
1363
+ * @name roots
1364
+ * @type {Object.<string,Root>}
1365
+ * @example
1366
+ * // pbjs -r myroot -o compiled.js ...
1367
+ *
1368
+ * // in another module:
1369
+ * require("./compiled.js");
1370
+ *
1371
+ * // in any subsequent module:
1372
+ * var root = protobuf.roots["myroot"];
1373
+ */
1374
+
1375
+ },{}],11:[function(require,module,exports){
1376
+ "use strict";
1377
+
1378
+ /**
1379
+ * Streaming RPC helpers.
1380
+ * @namespace
1381
+ */
1382
+ var rpc = exports;
1383
+
1384
+ /**
1385
+ * RPC implementation passed to {@link Service#create} performing a service request on network level, i.e. by utilizing http requests or websockets.
1386
+ * @typedef RPCImpl
1387
+ * @type {function}
1388
+ * @param {Method|rpc.ServiceMethod<Message<{}>,Message<{}>>} method Reflected or static method being called
1389
+ * @param {Uint8Array} requestData Request data
1390
+ * @param {RPCImplCallback} callback Callback function
1391
+ * @returns {undefined}
1392
+ * @example
1393
+ * function rpcImpl(method, requestData, callback) {
1394
+ * if (protobuf.util.lcFirst(method.name) !== "myMethod") // compatible with static code
1395
+ * throw Error("no such method");
1396
+ * asynchronouslyObtainAResponse(requestData, function(err, responseData) {
1397
+ * callback(err, responseData);
1398
+ * });
1399
+ * }
1400
+ */
1401
+
1402
+ /**
1403
+ * Node-style callback as used by {@link RPCImpl}.
1404
+ * @typedef RPCImplCallback
1405
+ * @type {function}
1406
+ * @param {Error|null} error Error, if any, otherwise `null`
1407
+ * @param {Uint8Array|null} [response] Response data or `null` to signal end of stream, if there hasn't been an error
1408
+ * @returns {undefined}
1409
+ */
1410
+
1411
+ rpc.Service = require(12);
1412
+
1413
+ },{"12":12}],12:[function(require,module,exports){
1414
+ "use strict";
1415
+ module.exports = Service;
1416
+
1417
+ var util = require(14);
1418
+
1419
+ // Extends EventEmitter
1420
+ (Service.prototype = Object.create(util.EventEmitter.prototype)).constructor = Service;
1421
+
1422
+ /**
1423
+ * A service method callback as used by {@link rpc.ServiceMethod|ServiceMethod}.
1424
+ *
1425
+ * Differs from {@link RPCImplCallback} in that it is an actual callback of a service method which may not return `response = null`.
1426
+ * @typedef rpc.ServiceMethodCallback
1427
+ * @template TRes extends Message<TRes>
1428
+ * @type {function}
1429
+ * @param {Error|null} error Error, if any
1430
+ * @param {TRes} [response] Response message
1431
+ * @returns {undefined}
1432
+ */
1433
+
1434
+ /**
1435
+ * A service method part of a {@link rpc.Service} as created by {@link Service.create}.
1436
+ * @typedef rpc.ServiceMethod
1437
+ * @template TReq extends Message<TReq>
1438
+ * @template TRes extends Message<TRes>
1439
+ * @type {function}
1440
+ * @param {TReq|Properties<TReq>} request Request message or plain object
1441
+ * @param {rpc.ServiceMethodCallback<TRes>} [callback] Node-style callback called with the error, if any, and the response message
1442
+ * @returns {Promise<Message<TRes>>} Promise if `callback` has been omitted, otherwise `undefined`
1443
+ */
1444
+
1445
+ /**
1446
+ * Constructs a new RPC service instance.
1447
+ * @classdesc An RPC service as returned by {@link Service#create}.
1448
+ * @exports rpc.Service
1449
+ * @extends util.EventEmitter
1450
+ * @constructor
1451
+ * @param {RPCImpl} rpcImpl RPC implementation
1452
+ * @param {boolean} [requestDelimited=false] Whether requests are length-delimited
1453
+ * @param {boolean} [responseDelimited=false] Whether responses are length-delimited
1454
+ */
1455
+ function Service(rpcImpl, requestDelimited, responseDelimited) {
1456
+
1457
+ if (typeof rpcImpl !== "function")
1458
+ throw TypeError("rpcImpl must be a function");
1459
+
1460
+ util.EventEmitter.call(this);
1461
+
1462
+ /**
1463
+ * RPC implementation. Becomes `null` once the service is ended.
1464
+ * @type {RPCImpl|null}
1465
+ */
1466
+ this.rpcImpl = rpcImpl;
1467
+
1468
+ /**
1469
+ * Whether requests are length-delimited.
1470
+ * @type {boolean}
1471
+ */
1472
+ this.requestDelimited = Boolean(requestDelimited);
1473
+
1474
+ /**
1475
+ * Whether responses are length-delimited.
1476
+ * @type {boolean}
1477
+ */
1478
+ this.responseDelimited = Boolean(responseDelimited);
1479
+ }
1480
+
1481
+ /**
1482
+ * Calls a service method through {@link rpc.Service#rpcImpl|rpcImpl}.
1483
+ * @param {Method|rpc.ServiceMethod<TReq,TRes>} method Reflected or static method
1484
+ * @param {Constructor<TReq>} requestCtor Request constructor
1485
+ * @param {Constructor<TRes>} responseCtor Response constructor
1486
+ * @param {TReq|Properties<TReq>} request Request message or plain object
1487
+ * @param {rpc.ServiceMethodCallback<TRes>} callback Service callback
1488
+ * @returns {undefined}
1489
+ * @template TReq extends Message<TReq>
1490
+ * @template TRes extends Message<TRes>
1491
+ */
1492
+ Service.prototype.rpcCall = function rpcCall(method, requestCtor, responseCtor, request, callback) {
1493
+
1494
+ if (!request)
1495
+ throw TypeError("request must be specified");
1496
+
1497
+ var self = this;
1498
+ if (!callback)
1499
+ return util.asPromise(rpcCall, self, method, requestCtor, responseCtor, request);
1500
+
1501
+ if (!self.rpcImpl) {
1502
+ setTimeout(function() { callback(Error("already ended")); }, 0);
1503
+ return undefined;
1504
+ }
1505
+
1506
+ try {
1507
+ return self.rpcImpl(
1508
+ method,
1509
+ requestCtor[self.requestDelimited ? "encodeDelimited" : "encode"](request).finish(),
1510
+ function rpcCallback(err, response) {
1511
+
1512
+ if (err) {
1513
+ self.emit("error", err, method);
1514
+ return callback(err);
1515
+ }
1516
+
1517
+ if (response === null) {
1518
+ self.end(/* endedByRPC */ true);
1519
+ return undefined;
1520
+ }
1521
+
1522
+ if (!(response instanceof responseCtor)) {
1523
+ try {
1524
+ response = responseCtor[self.responseDelimited ? "decodeDelimited" : "decode"](response);
1525
+ } catch (err) {
1526
+ self.emit("error", err, method);
1527
+ return callback(err);
1528
+ }
1529
+ }
1530
+
1531
+ self.emit("data", response, method);
1532
+ return callback(null, response);
1533
+ }
1534
+ );
1535
+ } catch (err) {
1536
+ self.emit("error", err, method);
1537
+ setTimeout(function() { callback(err); }, 0);
1538
+ return undefined;
1539
+ }
1540
+ };
1541
+
1542
+ /**
1543
+ * Ends this service and emits the `end` event.
1544
+ * @param {boolean} [endedByRPC=false] Whether the service has been ended by the RPC implementation.
1545
+ * @returns {rpc.Service} `this`
1546
+ */
1547
+ Service.prototype.end = function end(endedByRPC) {
1548
+ if (this.rpcImpl) {
1549
+ if (!endedByRPC) // signal end to rpcImpl
1550
+ this.rpcImpl(null, null, null);
1551
+ this.rpcImpl = null;
1552
+ this.emit("end").off();
1553
+ }
1554
+ return this;
1555
+ };
1556
+
1557
+ },{"14":14}],13:[function(require,module,exports){
1558
+ "use strict";
1559
+ module.exports = LongBits;
1560
+
1561
+ var util = require(14);
1562
+
1563
+ /**
1564
+ * Constructs new long bits.
1565
+ * @classdesc Helper class for working with the low and high bits of a 64 bit value.
1566
+ * @memberof util
1567
+ * @constructor
1568
+ * @param {number} lo Low 32 bits, unsigned
1569
+ * @param {number} hi High 32 bits, unsigned
1570
+ */
1571
+ function LongBits(lo, hi) {
1572
+
1573
+ // note that the casts below are theoretically unnecessary as of today, but older statically
1574
+ // generated converter code might still call the ctor with signed 32bits. kept for compat.
1575
+
1576
+ /**
1577
+ * Low bits.
1578
+ * @type {number}
1579
+ */
1580
+ this.lo = lo >>> 0;
1581
+
1582
+ /**
1583
+ * High bits.
1584
+ * @type {number}
1585
+ */
1586
+ this.hi = hi >>> 0;
1587
+ }
1588
+
1589
+ /**
1590
+ * Zero bits.
1591
+ * @memberof util.LongBits
1592
+ * @type {util.LongBits}
1593
+ */
1594
+ var zero = LongBits.zero = new LongBits(0, 0);
1595
+
1596
+ zero.toNumber = function() { return 0; };
1597
+ zero.zzEncode = zero.zzDecode = function() { return this; };
1598
+ zero.length = function() { return 1; };
1599
+
1600
+ /**
1601
+ * Zero hash.
1602
+ * @memberof util.LongBits
1603
+ * @type {string}
1604
+ */
1605
+ var zeroHash = LongBits.zeroHash = "\0\0\0\0\0\0\0\0";
1606
+
1607
+ /**
1608
+ * Constructs new long bits from the specified number.
1609
+ * @param {number} value Value
1610
+ * @returns {util.LongBits} Instance
1611
+ */
1612
+ LongBits.fromNumber = function fromNumber(value) {
1613
+ if (value === 0)
1614
+ return zero;
1615
+ var sign = value < 0;
1616
+ if (sign)
1617
+ value = -value;
1618
+ var lo = value >>> 0,
1619
+ hi = (value - lo) / 4294967296 >>> 0;
1620
+ if (sign) {
1621
+ hi = ~hi >>> 0;
1622
+ lo = ~lo >>> 0;
1623
+ if (++lo > 4294967295) {
1624
+ lo = 0;
1625
+ if (++hi > 4294967295)
1626
+ hi = 0;
1627
+ }
1628
+ }
1629
+ return new LongBits(lo, hi);
1630
+ };
1631
+
1632
+ /**
1633
+ * Constructs new long bits from a number, long or string.
1634
+ * @param {Long|number|string} value Value
1635
+ * @returns {util.LongBits} Instance
1636
+ */
1637
+ LongBits.from = function from(value) {
1638
+ if (typeof value === "number")
1639
+ return LongBits.fromNumber(value);
1640
+ if (util.isString(value)) {
1641
+ /* istanbul ignore else */
1642
+ if (util.Long)
1643
+ value = util.Long.fromString(value);
1644
+ else
1645
+ return LongBits.fromNumber(parseInt(value, 10));
1646
+ }
1647
+ return value.low || value.high ? new LongBits(value.low >>> 0, value.high >>> 0) : zero;
1648
+ };
1649
+
1650
+ /**
1651
+ * Converts this long bits to a possibly unsafe JavaScript number.
1652
+ * @param {boolean} [unsigned=false] Whether unsigned or not
1653
+ * @returns {number} Possibly unsafe number
1654
+ */
1655
+ LongBits.prototype.toNumber = function toNumber(unsigned) {
1656
+ if (!unsigned && this.hi >>> 31) {
1657
+ var lo = ~this.lo + 1 >>> 0,
1658
+ hi = ~this.hi >>> 0;
1659
+ if (!lo)
1660
+ hi = hi + 1 >>> 0;
1661
+ return -(lo + hi * 4294967296);
1662
+ }
1663
+ return this.lo + this.hi * 4294967296;
1664
+ };
1665
+
1666
+ /**
1667
+ * Converts this long bits to a long.
1668
+ * @param {boolean} [unsigned=false] Whether unsigned or not
1669
+ * @returns {Long} Long
1670
+ */
1671
+ LongBits.prototype.toLong = function toLong(unsigned) {
1672
+ return util.Long
1673
+ ? new util.Long(this.lo | 0, this.hi | 0, Boolean(unsigned))
1674
+ /* istanbul ignore next */
1675
+ : { low: this.lo | 0, high: this.hi | 0, unsigned: Boolean(unsigned) };
1676
+ };
1677
+
1678
+ var charCodeAt = String.prototype.charCodeAt;
1679
+
1680
+ /**
1681
+ * Constructs new long bits from the specified 8 characters long hash.
1682
+ * @param {string} hash Hash
1683
+ * @returns {util.LongBits} Bits
1684
+ */
1685
+ LongBits.fromHash = function fromHash(hash) {
1686
+ if (hash === zeroHash)
1687
+ return zero;
1688
+ return new LongBits(
1689
+ ( charCodeAt.call(hash, 0)
1690
+ | charCodeAt.call(hash, 1) << 8
1691
+ | charCodeAt.call(hash, 2) << 16
1692
+ | charCodeAt.call(hash, 3) << 24) >>> 0
1693
+ ,
1694
+ ( charCodeAt.call(hash, 4)
1695
+ | charCodeAt.call(hash, 5) << 8
1696
+ | charCodeAt.call(hash, 6) << 16
1697
+ | charCodeAt.call(hash, 7) << 24) >>> 0
1698
+ );
1699
+ };
1700
+
1701
+ /**
1702
+ * Converts this long bits to a 8 characters long hash.
1703
+ * @returns {string} Hash
1704
+ */
1705
+ LongBits.prototype.toHash = function toHash() {
1706
+ return String.fromCharCode(
1707
+ this.lo & 255,
1708
+ this.lo >>> 8 & 255,
1709
+ this.lo >>> 16 & 255,
1710
+ this.lo >>> 24 ,
1711
+ this.hi & 255,
1712
+ this.hi >>> 8 & 255,
1713
+ this.hi >>> 16 & 255,
1714
+ this.hi >>> 24
1715
+ );
1716
+ };
1717
+
1718
+ /**
1719
+ * Zig-zag encodes this long bits.
1720
+ * @returns {util.LongBits} `this`
1721
+ */
1722
+ LongBits.prototype.zzEncode = function zzEncode() {
1723
+ var mask = this.hi >> 31;
1724
+ this.hi = ((this.hi << 1 | this.lo >>> 31) ^ mask) >>> 0;
1725
+ this.lo = ( this.lo << 1 ^ mask) >>> 0;
1726
+ return this;
1727
+ };
1728
+
1729
+ /**
1730
+ * Zig-zag decodes this long bits.
1731
+ * @returns {util.LongBits} `this`
1732
+ */
1733
+ LongBits.prototype.zzDecode = function zzDecode() {
1734
+ var mask = -(this.lo & 1);
1735
+ this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0;
1736
+ this.hi = ( this.hi >>> 1 ^ mask) >>> 0;
1737
+ return this;
1738
+ };
1739
+
1740
+ /**
1741
+ * Calculates the length of this longbits when encoded as a varint.
1742
+ * @returns {number} Length
1743
+ */
1744
+ LongBits.prototype.length = function length() {
1745
+ var part0 = this.lo,
1746
+ part1 = (this.lo >>> 28 | this.hi << 4) >>> 0,
1747
+ part2 = this.hi >>> 24;
1748
+ return part2 === 0
1749
+ ? part1 === 0
1750
+ ? part0 < 16384
1751
+ ? part0 < 128 ? 1 : 2
1752
+ : part0 < 2097152 ? 3 : 4
1753
+ : part1 < 16384
1754
+ ? part1 < 128 ? 5 : 6
1755
+ : part1 < 2097152 ? 7 : 8
1756
+ : part2 < 128 ? 9 : 10;
1757
+ };
1758
+
1759
+ },{"14":14}],14:[function(require,module,exports){
1760
+ "use strict";
1761
+ var util = exports;
1762
+
1763
+ // used to return a Promise where callback is omitted
1764
+ util.asPromise = require(1);
1765
+
1766
+ // converts to / from base64 encoded strings
1767
+ util.base64 = require(2);
1768
+
1769
+ // base class of rpc.Service
1770
+ util.EventEmitter = require(3);
1771
+
1772
+ // float handling accross browsers
1773
+ util.float = require(4);
1774
+
1775
+ // converts to / from utf8 encoded strings
1776
+ util.utf8 = require(6);
1777
+
1778
+ // provides a node-like buffer pool in the browser
1779
+ util.pool = require(5);
1780
+
1781
+ // utility to work with the low and high bits of a 64 bit value
1782
+ util.LongBits = require(13);
1783
+
1784
+ /**
1785
+ * Tests if the specified key can affect object prototypes.
1786
+ * @memberof util
1787
+ * @param {string} key Key to test
1788
+ * @returns {boolean} `true` if the key is unsafe
1789
+ */
1790
+ function isUnsafeProperty(key) {
1791
+ return key === "__proto__" || key === "prototype" || key === "constructor";
1792
+ }
1793
+
1794
+ util.isUnsafeProperty = isUnsafeProperty;
1795
+
1796
+ /**
1797
+ * Whether running within node or not.
1798
+ * @memberof util
1799
+ * @type {boolean}
1800
+ */
1801
+ util.isNode = Boolean(typeof global !== "undefined"
1802
+ && global
1803
+ && global.process
1804
+ && global.process.versions
1805
+ && global.process.versions.node);
1806
+
1807
+ /**
1808
+ * Global object reference.
1809
+ * @memberof util
1810
+ * @type {Object}
1811
+ */
1812
+ util.global = util.isNode && global
1813
+ || typeof window !== "undefined" && window
1814
+ || typeof self !== "undefined" && self
1815
+ || this; // eslint-disable-line no-invalid-this
1816
+
1817
+ /**
1818
+ * An immuable empty array.
1819
+ * @memberof util
1820
+ * @type {Array.<*>}
1821
+ * @const
1822
+ */
1823
+ util.emptyArray = Object.freeze ? Object.freeze([]) : /* istanbul ignore next */ []; // used on prototypes
1824
+
1825
+ /**
1826
+ * An immutable empty object.
1827
+ * @type {Object}
1828
+ * @const
1829
+ */
1830
+ util.emptyObject = Object.freeze ? Object.freeze({}) : /* istanbul ignore next */ {}; // used on prototypes
1831
+
1832
+ /**
1833
+ * Tests if the specified value is an integer.
1834
+ * @function
1835
+ * @param {*} value Value to test
1836
+ * @returns {boolean} `true` if the value is an integer
1837
+ */
1838
+ util.isInteger = Number.isInteger || /* istanbul ignore next */ function isInteger(value) {
1839
+ return typeof value === "number" && isFinite(value) && Math.floor(value) === value;
1840
+ };
1841
+
1842
+ /**
1843
+ * Tests if the specified value is a string.
1844
+ * @param {*} value Value to test
1845
+ * @returns {boolean} `true` if the value is a string
1846
+ */
1847
+ util.isString = function isString(value) {
1848
+ return typeof value === "string" || value instanceof String;
1849
+ };
1850
+
1851
+ /**
1852
+ * Tests if the specified value is a non-null object.
1853
+ * @param {*} value Value to test
1854
+ * @returns {boolean} `true` if the value is a non-null object
1855
+ */
1856
+ util.isObject = function isObject(value) {
1857
+ return value && typeof value === "object";
1858
+ };
1859
+
1860
+ /**
1861
+ * Checks if a property on a message is considered to be present.
1862
+ * This is an alias of {@link util.isSet}.
1863
+ * @function
1864
+ * @param {Object} obj Plain object or message instance
1865
+ * @param {string} prop Property name
1866
+ * @returns {boolean} `true` if considered to be present, otherwise `false`
1867
+ */
1868
+ util.isset =
1869
+
1870
+ /**
1871
+ * Checks if a property on a message is considered to be present.
1872
+ * @param {Object} obj Plain object or message instance
1873
+ * @param {string} prop Property name
1874
+ * @returns {boolean} `true` if considered to be present, otherwise `false`
1875
+ */
1876
+ util.isSet = function isSet(obj, prop) {
1877
+ var value = obj[prop];
1878
+ if (value != null && Object.hasOwnProperty.call(obj, prop)) // eslint-disable-line eqeqeq
1879
+ return typeof value !== "object" || (Array.isArray(value) ? value.length : Object.keys(value).length) > 0;
1880
+ return false;
1881
+ };
1882
+
1883
+ /**
1884
+ * Any compatible Buffer instance.
1885
+ * This is a minimal stand-alone definition of a Buffer instance. The actual type is that exported by node's typings.
1886
+ * @interface Buffer
1887
+ * @extends Uint8Array
1888
+ */
1889
+
1890
+ /**
1891
+ * Node's Buffer class if available.
1892
+ * @type {Constructor<Buffer>}
1893
+ */
1894
+ util.Buffer = (function() {
1895
+ try {
1896
+ var Buffer = util.global.Buffer;
1897
+ // refuse to use non-node buffers if not explicitly assigned (perf reasons):
1898
+ return Buffer.prototype.utf8Write ? Buffer : /* istanbul ignore next */ null;
1899
+ } catch (e) {
1900
+ /* istanbul ignore next */
1901
+ return null;
1902
+ }
1903
+ })();
1904
+
1905
+ // Internal alias of or polyfull for Buffer.from.
1906
+ util._Buffer_from = null;
1907
+
1908
+ // Internal alias of or polyfill for Buffer.allocUnsafe.
1909
+ util._Buffer_allocUnsafe = null;
1910
+
1911
+ /**
1912
+ * Creates a new buffer of whatever type supported by the environment.
1913
+ * @param {number|number[]} [sizeOrArray=0] Buffer size or number array
1914
+ * @returns {Uint8Array|Buffer} Buffer
1915
+ */
1916
+ util.newBuffer = function newBuffer(sizeOrArray) {
1917
+ /* istanbul ignore next */
1918
+ return typeof sizeOrArray === "number"
1919
+ ? util.Buffer
1920
+ ? util._Buffer_allocUnsafe(sizeOrArray)
1921
+ : new util.Array(sizeOrArray)
1922
+ : util.Buffer
1923
+ ? util._Buffer_from(sizeOrArray)
1924
+ : typeof Uint8Array === "undefined"
1925
+ ? sizeOrArray
1926
+ : new Uint8Array(sizeOrArray);
1927
+ };
1928
+
1929
+ /**
1930
+ * Array implementation used in the browser. `Uint8Array` if supported, otherwise `Array`.
1931
+ * @type {Constructor<Uint8Array>}
1932
+ */
1933
+ util.Array = typeof Uint8Array !== "undefined" ? Uint8Array /* istanbul ignore next */ : Array;
1934
+
1935
+ /**
1936
+ * Any compatible Long instance.
1937
+ * This is a minimal stand-alone definition of a Long instance. The actual type is that exported by long.js.
1938
+ * @interface Long
1939
+ * @property {number} low Low bits
1940
+ * @property {number} high High bits
1941
+ * @property {boolean} unsigned Whether unsigned or not
1942
+ */
1943
+
1944
+ /**
1945
+ * Long.js's Long class if available.
1946
+ * @type {Constructor<Long>}
1947
+ */
1948
+ util.Long = /* istanbul ignore next */ util.global.dcodeIO && /* istanbul ignore next */ util.global.dcodeIO.Long
1949
+ || /* istanbul ignore next */ util.global.Long
1950
+ || (function() {
1951
+ try {
1952
+ var Long = require("long");
1953
+ return Long && Long.isLong ? Long : null;
1954
+ } catch (e) {
1955
+ /* istanbul ignore next */
1956
+ return null;
1957
+ }
1958
+ })();
1959
+
1960
+ /**
1961
+ * Regular expression used to verify 2 bit (`bool`) map keys.
1962
+ * @type {RegExp}
1963
+ * @const
1964
+ */
1965
+ util.key2Re = /^true|false|0|1$/;
1966
+
1967
+ /**
1968
+ * Regular expression used to verify 32 bit (`int32` etc.) map keys.
1969
+ * @type {RegExp}
1970
+ * @const
1971
+ */
1972
+ util.key32Re = /^-?(?:0|[1-9][0-9]*)$/;
1973
+
1974
+ /**
1975
+ * Regular expression used to verify 64 bit (`int64` etc.) map keys.
1976
+ * @type {RegExp}
1977
+ * @const
1978
+ */
1979
+ util.key64Re = /^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/;
1980
+
1981
+ /**
1982
+ * Converts a number or long to an 8 characters long hash string.
1983
+ * @param {Long|number} value Value to convert
1984
+ * @returns {string} Hash
1985
+ */
1986
+ util.longToHash = function longToHash(value) {
1987
+ return value
1988
+ ? util.LongBits.from(value).toHash()
1989
+ : util.LongBits.zeroHash;
1990
+ };
1991
+
1992
+ /**
1993
+ * Converts an 8 characters long hash string to a long or number.
1994
+ * @param {string} hash Hash
1995
+ * @param {boolean} [unsigned=false] Whether unsigned or not
1996
+ * @returns {Long|number} Original value
1997
+ */
1998
+ util.longFromHash = function longFromHash(hash, unsigned) {
1999
+ var bits = util.LongBits.fromHash(hash);
2000
+ if (util.Long)
2001
+ return util.Long.fromBits(bits.lo, bits.hi, unsigned);
2002
+ return bits.toNumber(Boolean(unsigned));
2003
+ };
2004
+
2005
+ /**
2006
+ * Merges the properties of the source object into the destination object.
2007
+ * @memberof util
2008
+ * @param {Object.<string,*>} dst Destination object
2009
+ * @param {...(Object.<string,*>|boolean)} src Source objects, optionally followed by an `ifNotSet` flag
2010
+ * @returns {Object.<string,*>} Destination object
2011
+ */
2012
+ function merge(dst) { // used by converters
2013
+ var ifNotSet = typeof arguments[arguments.length - 1] === "boolean",
2014
+ limit = ifNotSet ? arguments.length - 1 : arguments.length;
2015
+ ifNotSet = ifNotSet && arguments[arguments.length - 1];
2016
+ for (var a = 1; a < limit; ++a) {
2017
+ var src = arguments[a];
2018
+ if (!src)
2019
+ continue;
2020
+ for (var keys = Object.keys(src), i = 0; i < keys.length; ++i)
2021
+ if (!isUnsafeProperty(keys[i]) && (dst[keys[i]] === undefined || !ifNotSet))
2022
+ dst[keys[i]] = src[keys[i]];
2023
+ }
2024
+ return dst;
2025
+ }
2026
+
2027
+ util.merge = merge;
2028
+
2029
+ /**
2030
+ * Schema declaration nesting limit.
2031
+ * @memberof util
2032
+ * @type {number}
2033
+ */
2034
+ util.nestingLimit = 32; // protoc: MaxMessageDeclarationNestingDepth
2035
+
2036
+ /**
2037
+ * Recursion limit.
2038
+ * @memberof util
2039
+ * @type {number}
2040
+ */
2041
+ util.recursionLimit = 100; // protoc: CodedInputStream::default_recursion_limit_
2042
+
2043
+ /**
2044
+ * Makes a property safe for assignment as an own property.
2045
+ * @memberof util
2046
+ * @param {Object.<string,*>} obj Object
2047
+ * @param {string} key Property key
2048
+ * @returns {undefined}
2049
+ */
2050
+ util.makeProp = function makeProp(obj, key) {
2051
+ Object.defineProperty(obj, key, {
2052
+ enumerable: true,
2053
+ configurable: true,
2054
+ writable: true
2055
+ });
2056
+ };
2057
+
2058
+ /**
2059
+ * Converts the first character of a string to lower case.
2060
+ * @param {string} str String to convert
2061
+ * @returns {string} Converted string
2062
+ */
2063
+ util.lcFirst = function lcFirst(str) {
2064
+ return str.charAt(0).toLowerCase() + str.substring(1);
2065
+ };
2066
+
2067
+ /**
2068
+ * Creates a custom error constructor.
2069
+ * @memberof util
2070
+ * @param {string} name Error name
2071
+ * @returns {Constructor<Error>} Custom error constructor
2072
+ */
2073
+ function newError(name) {
2074
+
2075
+ function CustomError(message, properties) {
2076
+
2077
+ if (!(this instanceof CustomError))
2078
+ return new CustomError(message, properties);
2079
+
2080
+ // Error.call(this, message);
2081
+ // ^ just returns a new error instance because the ctor can be called as a function
2082
+
2083
+ Object.defineProperty(this, "message", { get: function() { return message; } });
2084
+
2085
+ /* istanbul ignore next */
2086
+ if (Error.captureStackTrace) // node
2087
+ Error.captureStackTrace(this, CustomError);
2088
+ else
2089
+ Object.defineProperty(this, "stack", { value: new Error().stack || "" });
2090
+
2091
+ if (properties)
2092
+ merge(this, properties);
2093
+ }
2094
+
2095
+ CustomError.prototype = Object.create(Error.prototype, {
2096
+ constructor: {
2097
+ value: CustomError,
2098
+ writable: true,
2099
+ enumerable: false,
2100
+ configurable: true,
2101
+ },
2102
+ name: {
2103
+ get: function get() { return name; },
2104
+ set: undefined,
2105
+ enumerable: false,
2106
+ // configurable: false would accurately preserve the behavior of
2107
+ // the original, but I'm guessing that was not intentional.
2108
+ // For an actual error subclass, this property would
2109
+ // be configurable.
2110
+ configurable: true,
2111
+ },
2112
+ toString: {
2113
+ value: function value() { return this.name + ": " + this.message; },
2114
+ writable: true,
2115
+ enumerable: false,
2116
+ configurable: true,
2117
+ },
2118
+ });
2119
+
2120
+ return CustomError;
2121
+ }
2122
+
2123
+ util.newError = newError;
2124
+
2125
+ /**
2126
+ * Constructs a new protocol error.
2127
+ * @classdesc Error subclass indicating a protocol specifc error.
2128
+ * @memberof util
2129
+ * @extends Error
2130
+ * @template T extends Message<T>
2131
+ * @constructor
2132
+ * @param {string} message Error message
2133
+ * @param {Object.<string,*>} [properties] Additional properties
2134
+ * @example
2135
+ * try {
2136
+ * MyMessage.decode(someBuffer); // throws if required fields are missing
2137
+ * } catch (e) {
2138
+ * if (e instanceof ProtocolError && e.instance)
2139
+ * console.log("decoded so far: " + JSON.stringify(e.instance));
2140
+ * }
2141
+ */
2142
+ util.ProtocolError = newError("ProtocolError");
2143
+
2144
+ /**
2145
+ * So far decoded message instance.
2146
+ * @name util.ProtocolError#instance
2147
+ * @type {Message<T>}
2148
+ */
2149
+
2150
+ /**
2151
+ * A OneOf getter as returned by {@link util.oneOfGetter}.
2152
+ * @typedef OneOfGetter
2153
+ * @type {function}
2154
+ * @returns {string|undefined} Set field name, if any
2155
+ */
2156
+
2157
+ /**
2158
+ * Builds a getter for a oneof's present field name.
2159
+ * @param {string[]} fieldNames Field names
2160
+ * @returns {OneOfGetter} Unbound getter
2161
+ */
2162
+ util.oneOfGetter = function getOneOf(fieldNames) {
2163
+ var fieldMap = {};
2164
+ for (var i = 0; i < fieldNames.length; ++i)
2165
+ fieldMap[fieldNames[i]] = 1;
2166
+
2167
+ /**
2168
+ * @returns {string|undefined} Set field name, if any
2169
+ * @this Object
2170
+ * @ignore
2171
+ */
2172
+ return function() { // eslint-disable-line consistent-return
2173
+ for (var keys = Object.keys(this), i = keys.length - 1; i > -1; --i)
2174
+ if (fieldMap[keys[i]] === 1 && this[keys[i]] !== undefined && this[keys[i]] !== null)
2175
+ return keys[i];
2176
+ };
2177
+ };
2178
+
2179
+ /**
2180
+ * A OneOf setter as returned by {@link util.oneOfSetter}.
2181
+ * @typedef OneOfSetter
2182
+ * @type {function}
2183
+ * @param {string|undefined} value Field name
2184
+ * @returns {undefined}
2185
+ */
2186
+
2187
+ /**
2188
+ * Builds a setter for a oneof's present field name.
2189
+ * @param {string[]} fieldNames Field names
2190
+ * @returns {OneOfSetter} Unbound setter
2191
+ */
2192
+ util.oneOfSetter = function setOneOf(fieldNames) {
2193
+
2194
+ /**
2195
+ * @param {string} name Field name
2196
+ * @returns {undefined}
2197
+ * @this Object
2198
+ * @ignore
2199
+ */
2200
+ return function(name) {
2201
+ for (var i = 0; i < fieldNames.length; ++i)
2202
+ if (fieldNames[i] !== name)
2203
+ delete this[fieldNames[i]];
2204
+ };
2205
+ };
2206
+
2207
+ /**
2208
+ * Default conversion options used for {@link Message#toJSON} implementations.
2209
+ *
2210
+ * These options are close to proto3's JSON mapping with the exception that internal types like Any are handled just like messages. More precisely:
2211
+ *
2212
+ * - Longs become strings
2213
+ * - Enums become string keys
2214
+ * - Bytes become base64 encoded strings
2215
+ * - (Sub-)Messages become plain objects
2216
+ * - Maps become plain objects with all string keys
2217
+ * - Repeated fields become arrays
2218
+ * - NaN and Infinity for float and double fields become strings
2219
+ *
2220
+ * @type {IConversionOptions}
2221
+ * @see https://developers.google.com/protocol-buffers/docs/proto3?hl=en#json
2222
+ */
2223
+ util.toJSONOptions = {
2224
+ longs: String,
2225
+ enums: String,
2226
+ bytes: String,
2227
+ json: true
2228
+ };
2229
+
2230
+ // Sets up buffer utility according to the environment (called in index-minimal)
2231
+ util._configure = function() {
2232
+ var Buffer = util.Buffer;
2233
+ /* istanbul ignore if */
2234
+ if (!Buffer) {
2235
+ util._Buffer_from = util._Buffer_allocUnsafe = null;
2236
+ return;
2237
+ }
2238
+ // because node 4.x buffers are incompatible & immutable
2239
+ // see: https://github.com/dcodeIO/protobuf.js/pull/665
2240
+ util._Buffer_from = Buffer.from !== Uint8Array.from && Buffer.from ||
2241
+ /* istanbul ignore next */
2242
+ function Buffer_from(value, encoding) {
2243
+ return new Buffer(value, encoding);
2244
+ };
2245
+ util._Buffer_allocUnsafe = Buffer.allocUnsafe ||
2246
+ /* istanbul ignore next */
2247
+ function Buffer_allocUnsafe(size) {
2248
+ return new Buffer(size);
2249
+ };
2250
+ };
2251
+
2252
+ },{"1":1,"13":13,"2":2,"3":3,"4":4,"5":5,"6":6,"long":"long"}],15:[function(require,module,exports){
2253
+ "use strict";
2254
+ module.exports = Writer;
2255
+
2256
+ var util = require(14);
2257
+
2258
+ var BufferWriter; // cyclic
2259
+
2260
+ var LongBits = util.LongBits,
2261
+ base64 = util.base64,
2262
+ utf8 = util.utf8;
2263
+
2264
+ /**
2265
+ * Constructs a new writer operation instance.
2266
+ * @classdesc Scheduled writer operation.
2267
+ * @constructor
2268
+ * @param {function(*, Uint8Array, number)} fn Function to call
2269
+ * @param {number} len Value byte length
2270
+ * @param {*} val Value to write
2271
+ * @ignore
2272
+ */
2273
+ function Op(fn, len, val) {
2274
+
2275
+ /**
2276
+ * Function to call.
2277
+ * @type {function(Uint8Array, number, *)}
2278
+ */
2279
+ this.fn = fn;
2280
+
2281
+ /**
2282
+ * Value byte length.
2283
+ * @type {number}
2284
+ */
2285
+ this.len = len;
2286
+
2287
+ /**
2288
+ * Next operation.
2289
+ * @type {Writer.Op|undefined}
2290
+ */
2291
+ this.next = undefined;
2292
+
2293
+ /**
2294
+ * Value to write.
2295
+ * @type {*}
2296
+ */
2297
+ this.val = val; // type varies
2298
+ }
2299
+
2300
+ /* istanbul ignore next */
2301
+ function noop() {} // eslint-disable-line no-empty-function
2302
+
2303
+ /**
2304
+ * Constructs a new writer state instance.
2305
+ * @classdesc Copied writer state.
2306
+ * @memberof Writer
2307
+ * @constructor
2308
+ * @param {Writer} writer Writer to copy state from
2309
+ * @ignore
2310
+ */
2311
+ function State(writer) {
2312
+
2313
+ /**
2314
+ * Current head.
2315
+ * @type {Writer.Op}
2316
+ */
2317
+ this.head = writer.head;
2318
+
2319
+ /**
2320
+ * Current tail.
2321
+ * @type {Writer.Op}
2322
+ */
2323
+ this.tail = writer.tail;
2324
+
2325
+ /**
2326
+ * Current buffer length.
2327
+ * @type {number}
2328
+ */
2329
+ this.len = writer.len;
2330
+
2331
+ /**
2332
+ * Next state.
2333
+ * @type {State|null}
2334
+ */
2335
+ this.next = writer.states;
2336
+ }
2337
+
2338
+ /**
2339
+ * Constructs a new writer instance.
2340
+ * @classdesc Wire format writer using `Uint8Array` if available, otherwise `Array`.
2341
+ * @constructor
2342
+ */
2343
+ function Writer() {
2344
+
2345
+ /**
2346
+ * Current length.
2347
+ * @type {number}
2348
+ */
2349
+ this.len = 0;
2350
+
2351
+ /**
2352
+ * Operations head.
2353
+ * @type {Object}
2354
+ */
2355
+ this.head = new Op(noop, 0, 0);
2356
+
2357
+ /**
2358
+ * Operations tail
2359
+ * @type {Object}
2360
+ */
2361
+ this.tail = this.head;
2362
+
2363
+ /**
2364
+ * Linked forked states.
2365
+ * @type {Object|null}
2366
+ */
2367
+ this.states = null;
2368
+
2369
+ // When a value is written, the writer calculates its byte length and puts it into a linked
2370
+ // list of operations to perform when finish() is called. This both allows us to allocate
2371
+ // buffers of the exact required size and reduces the amount of work we have to do compared
2372
+ // to first calculating over objects and then encoding over objects. In our case, the encoding
2373
+ // part is just a linked list walk calling operations with already prepared values.
2374
+ }
2375
+
2376
+ var create = function create() {
2377
+ return util.Buffer
2378
+ ? function create_buffer_setup() {
2379
+ return (Writer.create = function create_buffer() {
2380
+ return new BufferWriter();
2381
+ })();
2382
+ }
2383
+ /* istanbul ignore next */
2384
+ : function create_array() {
2385
+ return new Writer();
2386
+ };
2387
+ };
2388
+
2389
+ /**
2390
+ * Creates a new writer.
2391
+ * @function
2392
+ * @returns {BufferWriter|Writer} A {@link BufferWriter} when Buffers are supported, otherwise a {@link Writer}
2393
+ */
2394
+ Writer.create = create();
2395
+
2396
+ /**
2397
+ * Allocates a buffer of the specified size.
2398
+ * @param {number} size Buffer size
2399
+ * @returns {Uint8Array} Buffer
2400
+ */
2401
+ Writer.alloc = function alloc(size) {
2402
+ return new util.Array(size);
2403
+ };
2404
+
2405
+ // Use Uint8Array buffer pool in the browser, just like node does with buffers
2406
+ /* istanbul ignore else */
2407
+ if (util.Array !== Array)
2408
+ Writer.alloc = util.pool(Writer.alloc, util.Array.prototype.subarray);
2409
+
2410
+ /**
2411
+ * Pushes a new operation to the queue.
2412
+ * @param {function(Uint8Array, number, *)} fn Function to call
2413
+ * @param {number} len Value byte length
2414
+ * @param {number} val Value to write
2415
+ * @returns {Writer} `this`
2416
+ * @private
2417
+ */
2418
+ Writer.prototype._push = function push(fn, len, val) {
2419
+ this.tail = this.tail.next = new Op(fn, len, val);
2420
+ this.len += len;
2421
+ return this;
2422
+ };
2423
+
2424
+ function writeByte(val, buf, pos) {
2425
+ buf[pos] = val & 255;
2426
+ }
2427
+
2428
+ function writeVarint32(val, buf, pos) {
2429
+ while (val > 127) {
2430
+ buf[pos++] = val & 127 | 128;
2431
+ val >>>= 7;
2432
+ }
2433
+ buf[pos] = val;
2434
+ }
2435
+
2436
+ /**
2437
+ * Constructs a new varint writer operation instance.
2438
+ * @classdesc Scheduled varint writer operation.
2439
+ * @extends Op
2440
+ * @constructor
2441
+ * @param {number} len Value byte length
2442
+ * @param {number} val Value to write
2443
+ * @ignore
2444
+ */
2445
+ function VarintOp(len, val) {
2446
+ this.len = len;
2447
+ this.next = undefined;
2448
+ this.val = val;
2449
+ }
2450
+
2451
+ VarintOp.prototype = Object.create(Op.prototype);
2452
+ VarintOp.prototype.fn = writeVarint32;
2453
+
2454
+ /**
2455
+ * Writes an unsigned 32 bit value as a varint.
2456
+ * @param {number} value Value to write
2457
+ * @returns {Writer} `this`
2458
+ */
2459
+ Writer.prototype.uint32 = function write_uint32(value) {
2460
+ // here, the call to this.push has been inlined and a varint specific Op subclass is used.
2461
+ // uint32 is by far the most frequently used operation and benefits significantly from this.
2462
+ this.len += (this.tail = this.tail.next = new VarintOp(
2463
+ (value = value >>> 0)
2464
+ < 128 ? 1
2465
+ : value < 16384 ? 2
2466
+ : value < 2097152 ? 3
2467
+ : value < 268435456 ? 4
2468
+ : 5,
2469
+ value)).len;
2470
+ return this;
2471
+ };
2472
+
2473
+ /**
2474
+ * Writes a signed 32 bit value as a varint.
2475
+ * @function
2476
+ * @param {number} value Value to write
2477
+ * @returns {Writer} `this`
2478
+ */
2479
+ Writer.prototype.int32 = function write_int32(value) {
2480
+ return (value |= 0) < 0
2481
+ ? this._push(writeVarint64, 10, LongBits.fromNumber(value)) // 10 bytes per spec
2482
+ : this.uint32(value);
2483
+ };
2484
+
2485
+ /**
2486
+ * Writes a 32 bit value as a varint, zig-zag encoded.
2487
+ * @param {number} value Value to write
2488
+ * @returns {Writer} `this`
2489
+ */
2490
+ Writer.prototype.sint32 = function write_sint32(value) {
2491
+ return this.uint32((value << 1 ^ value >> 31) >>> 0);
2492
+ };
2493
+
2494
+ function writeVarint64(val, buf, pos) {
2495
+ var lo = val.lo,
2496
+ hi = val.hi;
2497
+ while (hi) {
2498
+ buf[pos++] = lo & 127 | 128;
2499
+ lo = (lo >>> 7 | hi << 25) >>> 0;
2500
+ hi >>>= 7;
2501
+ }
2502
+ while (lo > 127) {
2503
+ buf[pos++] = lo & 127 | 128;
2504
+ lo = lo >>> 7;
2505
+ }
2506
+ buf[pos++] = lo;
2507
+ }
2508
+
2509
+ /**
2510
+ * Writes an unsigned 64 bit value as a varint.
2511
+ * @param {Long|number|string} value Value to write
2512
+ * @returns {Writer} `this`
2513
+ * @throws {TypeError} If `value` is a string and no long library is present.
2514
+ */
2515
+ Writer.prototype.uint64 = function write_uint64(value) {
2516
+ var bits = LongBits.from(value);
2517
+ return this._push(writeVarint64, bits.length(), bits);
2518
+ };
2519
+
2520
+ /**
2521
+ * Writes a signed 64 bit value as a varint.
2522
+ * @function
2523
+ * @param {Long|number|string} value Value to write
2524
+ * @returns {Writer} `this`
2525
+ * @throws {TypeError} If `value` is a string and no long library is present.
2526
+ */
2527
+ Writer.prototype.int64 = Writer.prototype.uint64;
2528
+
2529
+ /**
2530
+ * Writes a signed 64 bit value as a varint, zig-zag encoded.
2531
+ * @param {Long|number|string} value Value to write
2532
+ * @returns {Writer} `this`
2533
+ * @throws {TypeError} If `value` is a string and no long library is present.
2534
+ */
2535
+ Writer.prototype.sint64 = function write_sint64(value) {
2536
+ var bits = LongBits.from(value).zzEncode();
2537
+ return this._push(writeVarint64, bits.length(), bits);
2538
+ };
2539
+
2540
+ /**
2541
+ * Writes a boolish value as a varint.
2542
+ * @param {boolean} value Value to write
2543
+ * @returns {Writer} `this`
2544
+ */
2545
+ Writer.prototype.bool = function write_bool(value) {
2546
+ return this._push(writeByte, 1, value ? 1 : 0);
2547
+ };
2548
+
2549
+ function writeFixed32(val, buf, pos) {
2550
+ buf[pos ] = val & 255;
2551
+ buf[pos + 1] = val >>> 8 & 255;
2552
+ buf[pos + 2] = val >>> 16 & 255;
2553
+ buf[pos + 3] = val >>> 24;
2554
+ }
2555
+
2556
+ /**
2557
+ * Writes an unsigned 32 bit value as fixed 32 bits.
2558
+ * @param {number} value Value to write
2559
+ * @returns {Writer} `this`
2560
+ */
2561
+ Writer.prototype.fixed32 = function write_fixed32(value) {
2562
+ return this._push(writeFixed32, 4, value >>> 0);
2563
+ };
2564
+
2565
+ /**
2566
+ * Writes a signed 32 bit value as fixed 32 bits.
2567
+ * @function
2568
+ * @param {number} value Value to write
2569
+ * @returns {Writer} `this`
2570
+ */
2571
+ Writer.prototype.sfixed32 = Writer.prototype.fixed32;
2572
+
2573
+ /**
2574
+ * Writes an unsigned 64 bit value as fixed 64 bits.
2575
+ * @param {Long|number|string} value Value to write
2576
+ * @returns {Writer} `this`
2577
+ * @throws {TypeError} If `value` is a string and no long library is present.
2578
+ */
2579
+ Writer.prototype.fixed64 = function write_fixed64(value) {
2580
+ var bits = LongBits.from(value);
2581
+ return this._push(writeFixed32, 4, bits.lo)._push(writeFixed32, 4, bits.hi);
2582
+ };
2583
+
2584
+ /**
2585
+ * Writes a signed 64 bit value as fixed 64 bits.
2586
+ * @function
2587
+ * @param {Long|number|string} value Value to write
2588
+ * @returns {Writer} `this`
2589
+ * @throws {TypeError} If `value` is a string and no long library is present.
2590
+ */
2591
+ Writer.prototype.sfixed64 = Writer.prototype.fixed64;
2592
+
2593
+ /**
2594
+ * Writes a float (32 bit).
2595
+ * @function
2596
+ * @param {number} value Value to write
2597
+ * @returns {Writer} `this`
2598
+ */
2599
+ Writer.prototype.float = function write_float(value) {
2600
+ return this._push(util.float.writeFloatLE, 4, value);
2601
+ };
2602
+
2603
+ /**
2604
+ * Writes a double (64 bit float).
2605
+ * @function
2606
+ * @param {number} value Value to write
2607
+ * @returns {Writer} `this`
2608
+ */
2609
+ Writer.prototype.double = function write_double(value) {
2610
+ return this._push(util.float.writeDoubleLE, 8, value);
2611
+ };
2612
+
2613
+ var writeBytes = util.Array.prototype.set
2614
+ ? function writeBytes_set(val, buf, pos) {
2615
+ buf.set(val, pos); // also works for plain array values
2616
+ }
2617
+ /* istanbul ignore next */
2618
+ : function writeBytes_for(val, buf, pos) {
2619
+ for (var i = 0; i < val.length; ++i)
2620
+ buf[pos + i] = val[i];
2621
+ };
2622
+
2623
+ /**
2624
+ * Writes a sequence of bytes.
2625
+ * @param {Uint8Array|string} value Buffer or base64 encoded string to write
2626
+ * @returns {Writer} `this`
2627
+ */
2628
+ Writer.prototype.bytes = function write_bytes(value) {
2629
+ var len = value.length >>> 0;
2630
+ if (!len)
2631
+ return this._push(writeByte, 1, 0);
2632
+ if (util.isString(value)) {
2633
+ var buf = Writer.alloc(len = base64.length(value));
2634
+ base64.decode(value, buf, 0);
2635
+ value = buf;
2636
+ }
2637
+ return this.uint32(len)._push(writeBytes, len, value);
2638
+ };
2639
+
2640
+ /**
2641
+ * Writes a string.
2642
+ * @param {string} value Value to write
2643
+ * @returns {Writer} `this`
2644
+ */
2645
+ Writer.prototype.string = function write_string(value) {
2646
+ var len = utf8.length(value);
2647
+ return len
2648
+ ? this.uint32(len)._push(utf8.write, len, value)
2649
+ : this._push(writeByte, 1, 0);
2650
+ };
2651
+
2652
+ /**
2653
+ * Forks this writer's state by pushing it to a stack.
2654
+ * Calling {@link Writer#reset|reset} or {@link Writer#ldelim|ldelim} resets the writer to the previous state.
2655
+ * @returns {Writer} `this`
2656
+ */
2657
+ Writer.prototype.fork = function fork() {
2658
+ this.states = new State(this);
2659
+ this.head = this.tail = new Op(noop, 0, 0);
2660
+ this.len = 0;
2661
+ return this;
2662
+ };
2663
+
2664
+ /**
2665
+ * Resets this instance to the last state.
2666
+ * @returns {Writer} `this`
2667
+ */
2668
+ Writer.prototype.reset = function reset() {
2669
+ if (this.states) {
2670
+ this.head = this.states.head;
2671
+ this.tail = this.states.tail;
2672
+ this.len = this.states.len;
2673
+ this.states = this.states.next;
2674
+ } else {
2675
+ this.head = this.tail = new Op(noop, 0, 0);
2676
+ this.len = 0;
2677
+ }
2678
+ return this;
2679
+ };
2680
+
2681
+ /**
2682
+ * Resets to the last state and appends the fork state's current write length as a varint followed by its operations.
2683
+ * @returns {Writer} `this`
2684
+ */
2685
+ Writer.prototype.ldelim = function ldelim() {
2686
+ var head = this.head,
2687
+ tail = this.tail,
2688
+ len = this.len;
2689
+ this.reset().uint32(len);
2690
+ if (len) {
2691
+ this.tail.next = head.next; // skip noop
2692
+ this.tail = tail;
2693
+ this.len += len;
2694
+ }
2695
+ return this;
2696
+ };
2697
+
2698
+ /**
2699
+ * Finishes the write operation.
2700
+ * @returns {Uint8Array} Finished buffer
2701
+ */
2702
+ Writer.prototype.finish = function finish() {
2703
+ var head = this.head.next, // skip noop
2704
+ buf = this.constructor.alloc(this.len),
2705
+ pos = 0;
2706
+ while (head) {
2707
+ head.fn(head.val, buf, pos);
2708
+ pos += head.len;
2709
+ head = head.next;
2710
+ }
2711
+ // this.head = this.tail = null;
2712
+ return buf;
2713
+ };
2714
+
2715
+ Writer._configure = function(BufferWriter_) {
2716
+ BufferWriter = BufferWriter_;
2717
+ Writer.create = create();
2718
+ BufferWriter._configure();
2719
+ };
2720
+
2721
+ },{"14":14}],16:[function(require,module,exports){
2722
+ "use strict";
2723
+ module.exports = BufferWriter;
2724
+
2725
+ // extends Writer
2726
+ var Writer = require(15);
2727
+ (BufferWriter.prototype = Object.create(Writer.prototype)).constructor = BufferWriter;
2728
+
2729
+ var util = require(14);
2730
+
2731
+ /**
2732
+ * Constructs a new buffer writer instance.
2733
+ * @classdesc Wire format writer using node buffers.
2734
+ * @extends Writer
2735
+ * @constructor
2736
+ */
2737
+ function BufferWriter() {
2738
+ Writer.call(this);
2739
+ }
2740
+
2741
+ BufferWriter._configure = function () {
2742
+ /**
2743
+ * Allocates a buffer of the specified size.
2744
+ * @function
2745
+ * @param {number} size Buffer size
2746
+ * @returns {Buffer} Buffer
2747
+ */
2748
+ BufferWriter.alloc = util._Buffer_allocUnsafe;
2749
+
2750
+ BufferWriter.writeBytesBuffer = util.Buffer && util.Buffer.prototype instanceof Uint8Array && util.Buffer.prototype.set.name === "set"
2751
+ ? function writeBytesBuffer_set(val, buf, pos) {
2752
+ buf.set(val, pos); // faster than copy (requires node >= 4 where Buffers extend Uint8Array and set is properly inherited)
2753
+ // also works for plain array values
2754
+ }
2755
+ /* istanbul ignore next */
2756
+ : function writeBytesBuffer_copy(val, buf, pos) {
2757
+ if (val.copy) // Buffer values
2758
+ val.copy(buf, pos, 0, val.length);
2759
+ else for (var i = 0; i < val.length;) // plain array values
2760
+ buf[pos++] = val[i++];
2761
+ };
2762
+ };
2763
+
2764
+
2765
+ /**
2766
+ * @override
2767
+ */
2768
+ BufferWriter.prototype.bytes = function write_bytes_buffer(value) {
2769
+ if (util.isString(value))
2770
+ value = util._Buffer_from(value, "base64");
2771
+ var len = value.length >>> 0;
2772
+ this.uint32(len);
2773
+ if (len)
2774
+ this._push(BufferWriter.writeBytesBuffer, len, value);
2775
+ return this;
2776
+ };
2777
+
2778
+ function writeStringBuffer(val, buf, pos) {
2779
+ if (val.length < 40) // plain js is faster for short strings (probably due to redundant assertions)
2780
+ util.utf8.write(val, buf, pos);
2781
+ else if (buf.utf8Write)
2782
+ buf.utf8Write(val, pos);
2783
+ else
2784
+ buf.write(val, pos);
2785
+ }
2786
+
2787
+ /**
2788
+ * @override
2789
+ */
2790
+ BufferWriter.prototype.string = function write_string_buffer(value) {
2791
+ var len = util.Buffer.byteLength(value);
2792
+ this.uint32(len);
2793
+ if (len)
2794
+ this._push(writeStringBuffer, len, value);
2795
+ return this;
2796
+ };
2797
+
2798
+
2799
+ /**
2800
+ * Finishes the write operation.
2801
+ * @name BufferWriter#finish
2802
+ * @function
2803
+ * @returns {Buffer} Finished buffer
2804
+ */
2805
+
2806
+ BufferWriter._configure();
2807
+
2808
+ },{"14":14,"15":15}]},{},[7])
2809
+
2810
+ })();
2811
+ //# sourceMappingURL=protobuf.js.map