説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

protobuf.js 76KB

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