智慧水务管理系统 - 精河县供水工程综合管理平台

protobuf.js 86KB

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