protobuf.js 77 KB

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