protobuf.js 75 KB

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