1
0

Protobufjs.js 75 KB

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