protobuf.js 77 KB

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