protobufjs.js 78 KB

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