protobuf.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836
  1. /* jshint esversion: 6 */
  2. var protobuf = protobuf || {};
  3. var base = base || require('./base');
  4. protobuf.get = (name) => {
  5. protobuf._map = protobuf._map || new Map();
  6. if (!protobuf._map.has(name)) {
  7. protobuf._map.set(name, {});
  8. }
  9. return protobuf._map.get(name);
  10. };
  11. protobuf.Reader = class {
  12. constructor(buffer) {
  13. this._buffer = buffer;
  14. this._length = buffer.length;
  15. this._position = 0;
  16. this._view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
  17. this._decoder = new TextDecoder('utf-8');
  18. }
  19. static create(buffer) {
  20. return new protobuf.Reader(buffer);
  21. }
  22. next(length) {
  23. if (length === undefined) {
  24. return this._length;
  25. }
  26. return this._position + length;
  27. }
  28. end(position) {
  29. return this._position < position;
  30. }
  31. get pos() {
  32. return this._position;
  33. }
  34. string() {
  35. return this._decoder.decode(this.bytes());
  36. }
  37. bool() {
  38. return this.uint32() !== 0;
  39. }
  40. bytes() {
  41. const length = this.uint32();
  42. const start = this._position;
  43. const end = this._position + length;
  44. if (end > this._length) {
  45. throw this._indexOutOfRangeError(length);
  46. }
  47. this._position += length;
  48. return this._buffer.slice(start, end);
  49. }
  50. uint32() {
  51. let value = 4294967295;
  52. value = (this._buffer[this._position] & 127) >>> 0;
  53. if (this._buffer[this._position++] < 128) {
  54. return value;
  55. }
  56. value = (value | (this._buffer[this._position] & 127) << 7) >>> 0;
  57. if (this._buffer[this._position++] < 128) return value;
  58. value = (value | (this._buffer[this._position] & 127) << 14) >>> 0; if (this._buffer[this._position++] < 128) return value;
  59. value = (value | (this._buffer[this._position] & 127) << 21) >>> 0; if (this._buffer[this._position++] < 128) return value;
  60. value = (value | (this._buffer[this._position] & 15) << 28) >>> 0; if (this._buffer[this._position++] < 128) return value;
  61. if ((this._position += 5) > this._length) {
  62. this._position = this._length;
  63. throw this._indexOutOfRangeError(10);
  64. }
  65. return value;
  66. }
  67. int32() {
  68. return this.uint32() | 0;
  69. }
  70. sint32() {
  71. const value = this.uint32();
  72. return value >>> 1 ^ -(value & 1) | 0;
  73. }
  74. int64() {
  75. return this._varint().toInt64();
  76. }
  77. uint64() {
  78. return this._varint().toInt64();
  79. }
  80. sint64() {
  81. return this._varint().zzDecode().toInt64();
  82. }
  83. fixed64() {
  84. const position = this._position;
  85. this.skip(8);
  86. return this._view.getUint64(position, true);
  87. }
  88. sfixed64() {
  89. const position = this._position;
  90. this.skip(8);
  91. return this._view.getInt64(position, true);
  92. }
  93. fixed32() {
  94. const position = this._position;
  95. this.skip(4);
  96. return this._view.getUint32(position, true);
  97. }
  98. sfixed32() {
  99. const position = this._position;
  100. this.skip(4);
  101. return this._view.getInt32(position, true);
  102. }
  103. float() {
  104. if (this._position + 4 > this._length) {
  105. throw this._indexOutOfRangeError(4);
  106. }
  107. const position = this._position;
  108. this._position += 4;
  109. return this._view.getFloat32(position, true);
  110. }
  111. double() {
  112. if (this._position + 8 > this._length) {
  113. throw this._indexOutOfRangeError(4);
  114. }
  115. const position = this._position;
  116. this._position += 8;
  117. return this._view.getFloat64(position, true);
  118. }
  119. array(obj, item, tag) {
  120. if ((tag & 7) === 2) {
  121. const end = this.uint32() + this._position;
  122. while (this._position < end) {
  123. obj.push(item());
  124. }
  125. }
  126. else {
  127. obj.push(item());
  128. }
  129. return obj;
  130. }
  131. floats(obj, tag) {
  132. if ((tag & 7) === 2) {
  133. if (obj && obj.length > 0) {
  134. throw new protobuf.Error('Invalid packed float array.');
  135. }
  136. const size = this.uint32();
  137. const end = this._position + size;
  138. const length = size >>> 2;
  139. obj = size > 1048576 ? new Float32Array(length) : new Array(length);
  140. let position = this._position;
  141. for (let i = 0; i < length; i++) {
  142. obj[i] = this._view.getFloat32(position, true);
  143. position += 4;
  144. }
  145. this._position = end;
  146. }
  147. else {
  148. if (obj !== undefined && obj.length < 1000000) {
  149. obj.push(this.float());
  150. }
  151. else {
  152. obj = undefined;
  153. this.float();
  154. }
  155. }
  156. return obj;
  157. }
  158. doubles(obj, tag) {
  159. if ((tag & 7) === 2) {
  160. if (obj && obj.length > 0) {
  161. throw new protobuf.Error('Invalid packed float array.');
  162. }
  163. const size = this.uint32();
  164. const end = this._position + size;
  165. const length = size >>> 3;
  166. obj = size > 1048576 ? new Float64Array(length) : new Array(length);
  167. let position = this._position;
  168. for (let i = 0; i < length; i++) {
  169. obj[i] = this._view.getFloat64(position, true);
  170. position += 8;
  171. }
  172. this._position = end;
  173. }
  174. else {
  175. if (obj !== undefined && obj.length < 1000000) {
  176. obj.push(this.double());
  177. }
  178. else {
  179. obj = undefined;
  180. this.double();
  181. }
  182. }
  183. return obj;
  184. }
  185. skip(offset) {
  186. this._position += offset;
  187. if (this._position > this._length) {
  188. throw this._indexOutOfRangeError(length);
  189. }
  190. }
  191. skipVarint() {
  192. do {
  193. if (this._position >= this._length) {
  194. throw this._indexOutOfRangeError();
  195. }
  196. }
  197. while (this._buffer[this._position++] & 128);
  198. }
  199. skipType(wireType) {
  200. switch (wireType) {
  201. case 0:
  202. this.skipVarint();
  203. break;
  204. case 1:
  205. this.skip(8);
  206. break;
  207. case 2:
  208. this.skip(this.uint32());
  209. break;
  210. case 3:
  211. while ((wireType = this.uint32() & 7) !== 4) {
  212. this.skipType(wireType);
  213. }
  214. break;
  215. case 5:
  216. this.skip(4);
  217. break;
  218. default:
  219. throw new protobuf.Error('invalid wire type ' + wireType + ' at offset ' + this._position);
  220. }
  221. }
  222. entry(obj, key, value) {
  223. this.skipVarint();
  224. this._position++;
  225. let k = key();
  226. if (!Number.isInteger(k) && typeof k !== 'string') {
  227. k = k.toNumber();
  228. }
  229. this._position++;
  230. const v = value();
  231. obj[k] = v;
  232. }
  233. _varint() {
  234. const bits = new protobuf.LongBits(0, 0);
  235. let i = 0;
  236. if (this._length - this._position > 4) { // fast route (lo)
  237. for (; i < 4; ++i) {
  238. // 1st..4th
  239. bits.lo = (bits.lo | (this._buffer[this._position] & 127) << i * 7) >>> 0;
  240. if (this._buffer[this._position++] < 128) {
  241. return bits;
  242. }
  243. }
  244. // 5th
  245. bits.lo = (bits.lo | (this._buffer[this._position] & 127) << 28) >>> 0;
  246. bits.hi = (bits.hi | (this._buffer[this._position] & 127) >> 4) >>> 0;
  247. if (this._buffer[this._position++] < 128) {
  248. return bits;
  249. }
  250. i = 0;
  251. }
  252. else {
  253. for (; i < 3; ++i) {
  254. if (this._position >= this._length)
  255. throw this._indexOutOfRangeError();
  256. bits.lo = (bits.lo | (this._buffer[this._position] & 127) << i * 7) >>> 0;
  257. if (this._buffer[this._position++] < 128) {
  258. return bits;
  259. }
  260. }
  261. bits.lo = (bits.lo | (this._buffer[this._position++] & 127) << i * 7) >>> 0;
  262. return bits;
  263. }
  264. if (this._length - this._position > 4) {
  265. for (; i < 5; ++i) {
  266. bits.hi = (bits.hi | (this._buffer[this._position] & 127) << i * 7 + 3) >>> 0;
  267. if (this._buffer[this._position++] < 128) {
  268. return bits;
  269. }
  270. }
  271. }
  272. else {
  273. for (; i < 5; ++i) {
  274. if (this._position >= this._length) {
  275. throw this._indexOutOfRangeError();
  276. }
  277. bits.hi = (bits.hi | (this._buffer[this._position] & 127) << i * 7 + 3) >>> 0;
  278. if (this._buffer[this._position++] < 128) {
  279. return bits;
  280. }
  281. }
  282. }
  283. throw new protobuf.Error('Invalid varint encoding.');
  284. }
  285. _indexOutOfRangeError(length) {
  286. return RangeError('index out of range: ' + this._position + ' + ' + (length || 1) + ' > ' + this._length);
  287. }
  288. };
  289. protobuf.TextReader = class {
  290. constructor(buffer) {
  291. this._buffer = buffer;
  292. this._position = 0;
  293. this._lineEnd = -1;
  294. this._line = -1;
  295. this._column = 0;
  296. this._depth = 0;
  297. this._arrayDepth = 0;
  298. this._token = undefined;
  299. this._tokenSize = -1;
  300. this._decoder = new TextDecoder('utf-8', { fatal: true });
  301. }
  302. static create(buffer) {
  303. return new protobuf.TextReader(buffer);
  304. }
  305. start() {
  306. if (this._depth > 0) {
  307. this.expect('{');
  308. }
  309. this._depth++;
  310. }
  311. end() {
  312. const token = this.peek();
  313. if (this._depth > 0 && token === '}') {
  314. this.expect('}');
  315. this.match(';');
  316. this._depth--;
  317. return true;
  318. }
  319. return token === '';
  320. }
  321. tag() {
  322. const name = this.read();
  323. const separator = this.peek();
  324. if (separator !== '[' && separator !== '{') {
  325. this.expect(':');
  326. }
  327. return name;
  328. }
  329. integer() {
  330. const token = this.read();
  331. const value = Number.parseInt(token, 10);
  332. if (Number.isNaN(token - value)) {
  333. throw new protobuf.Error("Couldn't parse integer '" + token + "'" + this._location());
  334. }
  335. this._semicolon();
  336. return value;
  337. }
  338. float() {
  339. let token = this.read();
  340. if (token.startsWith('nan')) {
  341. return NaN;
  342. }
  343. if (token.startsWith('inf')) {
  344. return Infinity;
  345. }
  346. if (token.startsWith('-inf')) {
  347. return -Infinity;
  348. }
  349. if (token.endsWith('f')) {
  350. token = token.substring(0, token.length - 1);
  351. }
  352. const value = Number.parseFloat(token);
  353. if (Number.isNaN(token - value)) {
  354. throw new protobuf.Error("Couldn't parse float '" + token + "'" + this._location());
  355. }
  356. this._semicolon();
  357. return value;
  358. }
  359. string() {
  360. const token = this.read();
  361. if (token.length < 2) {
  362. throw new protobuf.Error('String is too short' + this._location());
  363. }
  364. const quote = token[0];
  365. if (quote !== "'" && quote !== '"') {
  366. throw new protobuf.Error('String is not in quotes' + this._location());
  367. }
  368. if (quote !== token[token.length - 1]) {
  369. throw new protobuf.Error('String quotes do not match' + this._location());
  370. }
  371. const value = token.substring(1, token.length - 1);
  372. this._semicolon();
  373. return value;
  374. }
  375. boolean() {
  376. const token = this.read();
  377. switch (token) {
  378. case 'true':
  379. case 'True':
  380. case '1':
  381. this._semicolon();
  382. return true;
  383. case 'false':
  384. case 'False':
  385. case '0':
  386. this._semicolon();
  387. return false;
  388. }
  389. throw new protobuf.Error("Couldn't parse boolean '" + token + "'" + this._location());
  390. }
  391. bytes() {
  392. const token = this.string();
  393. let i = 0;
  394. let o = 0;
  395. const length = token.length;
  396. const a = new Uint8Array(length);
  397. while (i < length) {
  398. let c = token.charCodeAt(i++);
  399. if (c !== 0x5C) {
  400. a[o++] = c;
  401. }
  402. else {
  403. if (i >= length) {
  404. throw new protobuf.Error('Unexpected end of bytes string' + this._location());
  405. }
  406. c = token.charCodeAt(i++);
  407. switch (c) {
  408. case 0x27: a[o++] = 0x27; break; // '
  409. case 0x5C: a[o++] = 0x5C; break; // \\
  410. case 0x22: a[o++] = 0x22; break; // "
  411. case 0x72: a[o++] = 0x0D; break; // \r
  412. case 0x6E: a[o++] = 0x0A; break; // \n
  413. case 0x74: a[o++] = 0x09; break; // \t
  414. case 0x62: a[o++] = 0x08; break; // \b
  415. case 0x58: // x
  416. case 0x78: // X
  417. for (let xi = 0; xi < 2; xi++) {
  418. if (i >= length) {
  419. throw new protobuf.Error('Unexpected end of bytes string' + this._location());
  420. }
  421. let xd = token.charCodeAt(i++);
  422. xd = xd >= 65 && xd <= 70 ? xd - 55 : xd >= 97 && xd <= 102 ? xd - 87 : xd >= 48 && xd <= 57 ? xd - 48 : -1;
  423. if (xd === -1) {
  424. throw new protobuf.Error("Unexpected hex digit '" + xd + "' in bytes string" + this._location());
  425. }
  426. a[o] = a[o] << 4 | xd;
  427. }
  428. o++;
  429. break;
  430. default:
  431. if (c < 48 || c > 57) { // 0-9
  432. throw new protobuf.Error("Unexpected character '" + c + "' in bytes string" + this._location());
  433. }
  434. i--;
  435. for (let oi = 0; oi < 3; oi++) {
  436. if (i >= length) {
  437. throw new protobuf.Error('Unexpected end of bytes string' + this._location());
  438. }
  439. const od = token.charCodeAt(i++);
  440. if (od < 48 || od > 57) {
  441. throw new protobuf.Error("Unexpected octal digit '" + od + "' in bytes string" + this._location());
  442. }
  443. a[o] = a[o] << 3 | od - 48;
  444. }
  445. o++;
  446. break;
  447. }
  448. }
  449. }
  450. return a.slice(0, o);
  451. }
  452. enum(type) {
  453. const token = this.read();
  454. if (!Object.prototype.hasOwnProperty.call(type, token)) {
  455. const value = Number.parseInt(token, 10);
  456. if (!Number.isNaN(token - value)) {
  457. this._semicolon();
  458. return value;
  459. }
  460. throw new protobuf.Error("Couldn't parse enum '" + token + "'" + this._location());
  461. }
  462. this._semicolon();
  463. return type[token];
  464. }
  465. any(message) {
  466. if (this.match('[')) {
  467. this.read();
  468. const begin = this._position;
  469. const end = this._buffer.indexOf(']', begin);
  470. if (end === -1 || end >= this.next) {
  471. throw new protobuf.Error('End of Any type_url not found' + this._location());
  472. }
  473. message.type_url = this.__substring(begin, end);
  474. this._position = end + 1;
  475. this._column = 0;
  476. message.value = this.skip().substring(1);
  477. this.expect('}');
  478. this.match(';');
  479. return true;
  480. }
  481. return false;
  482. }
  483. entry(obj, key, value) {
  484. this.start();
  485. let k;
  486. let v;
  487. while (!this.end()) {
  488. switch (this.tag()) {
  489. case 'key':
  490. k = key();
  491. break;
  492. case 'value':
  493. v = value();
  494. break;
  495. }
  496. }
  497. obj[k] = v;
  498. }
  499. array(obj, item) {
  500. if (this.first()) {
  501. while (!this.last()) {
  502. obj.push(item());
  503. this.next();
  504. }
  505. }
  506. else {
  507. obj.push(item());
  508. }
  509. }
  510. first() {
  511. if (this.match('[')) {
  512. this._arrayDepth++;
  513. return true;
  514. }
  515. return false;
  516. }
  517. last() {
  518. if (this.match(']')) {
  519. this._arrayDepth--;
  520. return true;
  521. }
  522. return false;
  523. }
  524. next() {
  525. const token = this.peek();
  526. if (token === ',') {
  527. this.read();
  528. return;
  529. }
  530. if (token === ']') {
  531. return;
  532. }
  533. this.handle(token);
  534. }
  535. skip() {
  536. let token = this.peek();
  537. if (token === '{') {
  538. const message = this._position;
  539. const depth = this._depth;
  540. this.start();
  541. while (!this.end() || depth < this._depth) {
  542. token = this.peek();
  543. if (token === '{') {
  544. this.start();
  545. }
  546. else if (token !== '}') {
  547. this.read();
  548. this.match(';');
  549. }
  550. }
  551. return this._substring(message, this._position);
  552. }
  553. else if (token === '[') {
  554. const list = this._position;
  555. this.read();
  556. while (!this.last()) {
  557. token = this.read();
  558. if (token === '') {
  559. this.handle(token);
  560. }
  561. }
  562. return this._substring(list, this._position);
  563. }
  564. const position = this._position;
  565. this.read();
  566. this._semicolon();
  567. return this._substring(position, this._position);
  568. }
  569. handle(token) {
  570. throw new protobuf.Error("Unexpected token '" + token + "'" + this._location());
  571. }
  572. field(token /*, module */) {
  573. throw new protobuf.Error("Unknown field '" + token + "'" + this._location());
  574. }
  575. _get(position) {
  576. return String.fromCharCode(this._buffer[position]);
  577. }
  578. _substring(start, end) {
  579. return this._decoder.decode(this._buffer.subarray(start, end));
  580. }
  581. _whitespace() {
  582. for (;;) {
  583. while (this._position >= this._lineEnd) {
  584. this._column = 0;
  585. this._position = this._lineEnd + 1;
  586. if (this._position >= this._buffer.length) {
  587. return false;
  588. }
  589. this._lineEnd = this._buffer.indexOf(0x0a, this._position);
  590. if (this._lineEnd === -1) {
  591. this._lineEnd = this._buffer.length;
  592. }
  593. this._line++;
  594. }
  595. const c = this._buffer[this._position];
  596. switch (c) {
  597. case 0x09: // \t
  598. case 0x0D: // \n
  599. case 0x20: // ' '
  600. this._position++;
  601. this._column++;
  602. break;
  603. case 0x23: // #
  604. this._position = this._lineEnd;
  605. this._column = 0;
  606. break;
  607. default:
  608. return true;
  609. }
  610. }
  611. }
  612. tokenize() {
  613. if (!this._whitespace()) {
  614. this._tokenSize = 0;
  615. this._token = '';
  616. return;
  617. }
  618. let c = this._get(this._position);
  619. if (c === '[' && this._position + 2 < this._lineEnd) {
  620. let i = this._position + 1;
  621. let x = this._get(i);
  622. if (x >= 'a' && x <= 'z' || x >= 'A' && x <= 'Z') {
  623. i++;
  624. while (i < this._lineEnd) {
  625. x = this._get(i);
  626. i++;
  627. if (x >= 'a' && x <= 'z' || x >= 'A' && x <= 'Z' || x >= '0' && x <= '9' || x === '.' || x === '/') {
  628. continue;
  629. }
  630. if (x === ']') {
  631. this._tokenSize = i - this._position;
  632. this._token = this._substring(this._position, i);
  633. return;
  634. }
  635. }
  636. }
  637. }
  638. if (c === '{' || c === '}' || c === ':' || c === '[' || c === ',' || c === ']' || c === ';') {
  639. this._tokenSize = 1;
  640. this._token = c;
  641. return;
  642. }
  643. let position = this._position + 1;
  644. if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c === '_' || c === '$') {
  645. while (position < this._lineEnd) {
  646. c = this._get(position);
  647. if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c === '_' || c === '+' || c === '-') {
  648. position++;
  649. continue;
  650. }
  651. break;
  652. }
  653. this._tokenSize = position - this._position;
  654. this._token = this._substring(this._position, position);
  655. return;
  656. }
  657. if (c >= '0' && c <= '9' || c === '-' || c === '+' || c === '.') {
  658. while (position < this._lineEnd) {
  659. c = this._get(position);
  660. if (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= '0' && c <= '9' || c === '_' || c === '+' || c === '-' || c === '.') {
  661. position++;
  662. continue;
  663. }
  664. break;
  665. }
  666. this._tokenSize = position - this._position;
  667. this._token = this._substring(this._position, position);
  668. return;
  669. }
  670. if (c === '"' || c === "'") {
  671. const quote = c;
  672. while (position < this._lineEnd) {
  673. c = this._get(position);
  674. if (c === '\\' && position < this._lineEnd) {
  675. position += 2;
  676. continue;
  677. }
  678. position++;
  679. if (c === quote) {
  680. break;
  681. }
  682. }
  683. this._tokenSize = position - this._position;
  684. this._token = this._substring(this._position, position);
  685. return;
  686. }
  687. throw new protobuf.Error("Unexpected token '" + c + "'" + this._location());
  688. }
  689. peek() {
  690. if (this._tokenSize === -1) {
  691. this.tokenize();
  692. }
  693. return this._token;
  694. }
  695. read() {
  696. if (this._tokenSize === -1) {
  697. this.tokenize();
  698. }
  699. const token = this._token;
  700. this._position += this._tokenSize;
  701. this._column += this._token.length;
  702. this._tokenSize = -1;
  703. this._token = undefined;
  704. return token;
  705. }
  706. expect(value) {
  707. const token = this.peek();
  708. if (token !== value) {
  709. throw new protobuf.Error("Unexpected '" + token + "' instead of '" + value + "'" + this._location());
  710. }
  711. this.read();
  712. }
  713. match(value) {
  714. if (this.peek() === value) {
  715. this.read();
  716. return true;
  717. }
  718. return false;
  719. }
  720. _semicolon() {
  721. if (this._arrayDepth === 0) {
  722. this.match(';');
  723. }
  724. }
  725. _location() {
  726. return ' at ' + (this._line + 1).toString() + ':' + (this._column + 1).toString();
  727. }
  728. };
  729. protobuf.Int64 = base.Int64;
  730. protobuf.Uint64 = base.Uint64;
  731. protobuf.LongBits = class {
  732. constructor(lo, hi) {
  733. this.lo = lo >>> 0;
  734. this.hi = hi >>> 0;
  735. }
  736. zzDecode() {
  737. const mask = -(this.lo & 1);
  738. this.lo = ((this.lo >>> 1 | this.hi << 31) ^ mask) >>> 0;
  739. this.hi = ( this.hi >>> 1 ^ mask) >>> 0;
  740. return this;
  741. }
  742. toUint64() {
  743. return new base.Uint64(this.lo, this.hi);
  744. }
  745. toInt64() {
  746. return new base.Int64(this.lo, this.hi);
  747. }
  748. };
  749. protobuf.Error = class extends Error {
  750. constructor(message) {
  751. super(message);
  752. this.name = 'Protocol Buffer Error';
  753. this.message = message;
  754. }
  755. };
  756. if (typeof module !== 'undefined' && typeof module.exports === 'object') {
  757. module.exports.Reader = protobuf.Reader;
  758. module.exports.TextReader = protobuf.TextReader;
  759. module.exports.Error = protobuf.Error;
  760. module.exports.Int64 = protobuf.Int64;
  761. module.exports.Uint64 = protobuf.Uint64;
  762. module.exports.get = protobuf.get;
  763. }