protobuf.js 75 KB

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