protobuf-minimal.js 69 KB

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