1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
3 | typeof define === 'function' && define.amd ? define('leancloud-realtime', ['exports'], factory) :
|
4 | (global = global || self, factory(global.AV = global.AV || {}));
|
5 | }(this, function (exports) { 'use strict';
|
6 |
|
7 | var define = undefined;
|
8 | var require = require || function(id) {throw new Error('Unexpected required ' + id)};
|
9 |
|
10 |
|
11 |
|
12 | var process = (typeof window !== 'undefined' && window.process) || {};
|
13 | process.env = process.env || {};
|
14 |
|
15 | var XMLHttpRequest;
|
16 |
|
17 | function _typeof(obj) {
|
18 | if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
19 | _typeof = function (obj) {
|
20 | return typeof obj;
|
21 | };
|
22 | } else {
|
23 | _typeof = function (obj) {
|
24 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
25 | };
|
26 | }
|
27 |
|
28 | return _typeof(obj);
|
29 | }
|
30 |
|
31 | function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
32 | try {
|
33 | var info = gen[key](arg);
|
34 | var value = info.value;
|
35 | } catch (error) {
|
36 | reject(error);
|
37 | return;
|
38 | }
|
39 |
|
40 | if (info.done) {
|
41 | resolve(value);
|
42 | } else {
|
43 | Promise.resolve(value).then(_next, _throw);
|
44 | }
|
45 | }
|
46 |
|
47 | function _asyncToGenerator(fn) {
|
48 | return function () {
|
49 | var self = this,
|
50 | args = arguments;
|
51 | return new Promise(function (resolve, reject) {
|
52 | var gen = fn.apply(self, args);
|
53 |
|
54 | function _next(value) {
|
55 | asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
56 | }
|
57 |
|
58 | function _throw(err) {
|
59 | asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
60 | }
|
61 |
|
62 | _next(undefined);
|
63 | });
|
64 | };
|
65 | }
|
66 |
|
67 | function _defineProperties(target, props) {
|
68 | for (var i = 0; i < props.length; i++) {
|
69 | var descriptor = props[i];
|
70 | descriptor.enumerable = descriptor.enumerable || false;
|
71 | descriptor.configurable = true;
|
72 | if ("value" in descriptor) descriptor.writable = true;
|
73 | Object.defineProperty(target, descriptor.key, descriptor);
|
74 | }
|
75 | }
|
76 |
|
77 | function _createClass(Constructor, protoProps, staticProps) {
|
78 | if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
79 | if (staticProps) _defineProperties(Constructor, staticProps);
|
80 | return Constructor;
|
81 | }
|
82 |
|
83 | function _defineProperty(obj, key, value) {
|
84 | if (key in obj) {
|
85 | Object.defineProperty(obj, key, {
|
86 | value: value,
|
87 | enumerable: true,
|
88 | configurable: true,
|
89 | writable: true
|
90 | });
|
91 | } else {
|
92 | obj[key] = value;
|
93 | }
|
94 |
|
95 | return obj;
|
96 | }
|
97 |
|
98 | function _objectSpread(target) {
|
99 | for (var i = 1; i < arguments.length; i++) {
|
100 | var source = arguments[i] != null ? arguments[i] : {};
|
101 | var ownKeys = Object.keys(source);
|
102 |
|
103 | if (typeof Object.getOwnPropertySymbols === 'function') {
|
104 | ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
|
105 | return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
106 | }));
|
107 | }
|
108 |
|
109 | ownKeys.forEach(function (key) {
|
110 | _defineProperty(target, key, source[key]);
|
111 | });
|
112 | }
|
113 |
|
114 | return target;
|
115 | }
|
116 |
|
117 | function _inheritsLoose(subClass, superClass) {
|
118 | subClass.prototype = Object.create(superClass.prototype);
|
119 | subClass.prototype.constructor = subClass;
|
120 | subClass.__proto__ = superClass;
|
121 | }
|
122 |
|
123 | function _objectWithoutPropertiesLoose(source, excluded) {
|
124 | if (source == null) return {};
|
125 | var target = {};
|
126 | var sourceKeys = Object.keys(source);
|
127 | var key, i;
|
128 |
|
129 | for (i = 0; i < sourceKeys.length; i++) {
|
130 | key = sourceKeys[i];
|
131 | if (excluded.indexOf(key) >= 0) continue;
|
132 | target[key] = source[key];
|
133 | }
|
134 |
|
135 | return target;
|
136 | }
|
137 |
|
138 | function _objectWithoutProperties(source, excluded) {
|
139 | if (source == null) return {};
|
140 |
|
141 | var target = _objectWithoutPropertiesLoose(source, excluded);
|
142 |
|
143 | var key, i;
|
144 |
|
145 | if (Object.getOwnPropertySymbols) {
|
146 | var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
147 |
|
148 | for (i = 0; i < sourceSymbolKeys.length; i++) {
|
149 | key = sourceSymbolKeys[i];
|
150 | if (excluded.indexOf(key) >= 0) continue;
|
151 | if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
152 | target[key] = source[key];
|
153 | }
|
154 | }
|
155 |
|
156 | return target;
|
157 | }
|
158 |
|
159 | function _assertThisInitialized(self) {
|
160 | if (self === void 0) {
|
161 | throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
162 | }
|
163 |
|
164 | return self;
|
165 | }
|
166 |
|
167 | function _toArray(arr) {
|
168 | return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest();
|
169 | }
|
170 |
|
171 | function _toConsumableArray(arr) {
|
172 | return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
|
173 | }
|
174 |
|
175 | function _arrayWithoutHoles(arr) {
|
176 | if (Array.isArray(arr)) {
|
177 | for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
|
178 |
|
179 | return arr2;
|
180 | }
|
181 | }
|
182 |
|
183 | function _arrayWithHoles(arr) {
|
184 | if (Array.isArray(arr)) return arr;
|
185 | }
|
186 |
|
187 | function _iterableToArray(iter) {
|
188 | if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
|
189 | }
|
190 |
|
191 | function _nonIterableSpread() {
|
192 | throw new TypeError("Invalid attempt to spread non-iterable instance");
|
193 | }
|
194 |
|
195 | function _nonIterableRest() {
|
196 | throw new TypeError("Invalid attempt to destructure non-iterable instance");
|
197 | }
|
198 |
|
199 | function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
|
200 | var desc = {};
|
201 | Object['ke' + 'ys'](descriptor).forEach(function (key) {
|
202 | desc[key] = descriptor[key];
|
203 | });
|
204 | desc.enumerable = !!desc.enumerable;
|
205 | desc.configurable = !!desc.configurable;
|
206 |
|
207 | if ('value' in desc || desc.initializer) {
|
208 | desc.writable = true;
|
209 | }
|
210 |
|
211 | desc = decorators.slice().reverse().reduce(function (desc, decorator) {
|
212 | return decorator(target, property, desc) || desc;
|
213 | }, desc);
|
214 |
|
215 | if (context && desc.initializer !== void 0) {
|
216 | desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
|
217 | desc.initializer = undefined;
|
218 | }
|
219 |
|
220 | if (desc.initializer === void 0) {
|
221 | Object['define' + 'Property'](target, property, desc);
|
222 | desc = null;
|
223 | }
|
224 |
|
225 | return desc;
|
226 | }
|
227 |
|
228 | var commonjsGlobal = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
229 |
|
230 | function commonjsRequire () {
|
231 | throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
|
232 | }
|
233 |
|
234 | function createCommonjsModule(fn, module) {
|
235 | return module = { exports: {} }, fn(module, module.exports), module.exports;
|
236 | }
|
237 |
|
238 | var Storage =
|
239 |
|
240 | function () {
|
241 | function Storage() {}
|
242 |
|
243 | var _proto = Storage.prototype;
|
244 |
|
245 | _proto.getItem = function getItem(key) {
|
246 | return wx.getStorageSync(key);
|
247 | };
|
248 |
|
249 | _proto.setItem = function setItem(key, value) {
|
250 | return wx.setStorageSync(key, value);
|
251 | };
|
252 |
|
253 | _proto.removeItem = function removeItem(key) {
|
254 | return this.setItem(key, '');
|
255 | };
|
256 |
|
257 | _proto.clear = function clear() {
|
258 | return wx.clearStorageSync();
|
259 | };
|
260 |
|
261 | return Storage;
|
262 | }();
|
263 |
|
264 | var localstorage = new Storage();
|
265 |
|
266 | |
267 |
|
268 |
|
269 |
|
270 |
|
271 |
|
272 | var getOwnPropertySymbols = Object.getOwnPropertySymbols;
|
273 | var hasOwnProperty = Object.prototype.hasOwnProperty;
|
274 | var propIsEnumerable = Object.prototype.propertyIsEnumerable;
|
275 |
|
276 | function toObject(val) {
|
277 | if (val === null || val === undefined) {
|
278 | throw new TypeError('Object.assign cannot be called with null or undefined');
|
279 | }
|
280 |
|
281 | return Object(val);
|
282 | }
|
283 |
|
284 | function shouldUseNative() {
|
285 | try {
|
286 | if (!Object.assign) {
|
287 | return false;
|
288 | }
|
289 |
|
290 |
|
291 |
|
292 |
|
293 | var test1 = new String('abc');
|
294 | test1[5] = 'de';
|
295 | if (Object.getOwnPropertyNames(test1)[0] === '5') {
|
296 | return false;
|
297 | }
|
298 |
|
299 |
|
300 | var test2 = {};
|
301 | for (var i = 0; i < 10; i++) {
|
302 | test2['_' + String.fromCharCode(i)] = i;
|
303 | }
|
304 | var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
|
305 | return test2[n];
|
306 | });
|
307 | if (order2.join('') !== '0123456789') {
|
308 | return false;
|
309 | }
|
310 |
|
311 |
|
312 | var test3 = {};
|
313 | 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
|
314 | test3[letter] = letter;
|
315 | });
|
316 | if (Object.keys(Object.assign({}, test3)).join('') !==
|
317 | 'abcdefghijklmnopqrst') {
|
318 | return false;
|
319 | }
|
320 |
|
321 | return true;
|
322 | } catch (err) {
|
323 |
|
324 | return false;
|
325 | }
|
326 | }
|
327 |
|
328 | var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
|
329 | var from;
|
330 | var to = toObject(target);
|
331 | var symbols;
|
332 |
|
333 | for (var s = 1; s < arguments.length; s++) {
|
334 | from = Object(arguments[s]);
|
335 |
|
336 | for (var key in from) {
|
337 | if (hasOwnProperty.call(from, key)) {
|
338 | to[key] = from[key];
|
339 | }
|
340 | }
|
341 |
|
342 | if (getOwnPropertySymbols) {
|
343 | symbols = getOwnPropertySymbols(from);
|
344 | for (var i = 0; i < symbols.length; i++) {
|
345 | if (propIsEnumerable.call(from, symbols[i])) {
|
346 | to[symbols[i]] = from[symbols[i]];
|
347 | }
|
348 | }
|
349 | }
|
350 | }
|
351 |
|
352 | return to;
|
353 | };
|
354 |
|
355 | var commons = createCommonjsModule(function (module, exports) {
|
356 |
|
357 | |
358 |
|
359 |
|
360 |
|
361 |
|
362 |
|
363 |
|
364 | var createUniqueKey = exports.createUniqueKey = (typeof Symbol !== "undefined" ?
|
365 | Symbol :
|
366 | function createUniqueKey(name) {
|
367 | return "[[" + name + "_" + Math.random().toFixed(8).slice(2) + "]]";
|
368 | });
|
369 |
|
370 | |
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 | exports.LISTENERS = createUniqueKey("listeners");
|
377 |
|
378 | |
379 |
|
380 |
|
381 |
|
382 |
|
383 |
|
384 | exports.CAPTURE = 1;
|
385 |
|
386 | |
387 |
|
388 |
|
389 |
|
390 |
|
391 |
|
392 | exports.BUBBLE = 2;
|
393 |
|
394 | |
395 |
|
396 |
|
397 |
|
398 |
|
399 |
|
400 | exports.ATTRIBUTE = 3;
|
401 |
|
402 | |
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 | |
411 |
|
412 |
|
413 |
|
414 |
|
415 |
|
416 |
|
417 | exports.newNode = function newNode(listener, kind) {
|
418 | return {listener: listener, kind: kind, next: null};
|
419 | };
|
420 | });
|
421 | var commons_1 = commons.createUniqueKey;
|
422 | var commons_2 = commons.LISTENERS;
|
423 | var commons_3 = commons.CAPTURE;
|
424 | var commons_4 = commons.BUBBLE;
|
425 | var commons_5 = commons.ATTRIBUTE;
|
426 | var commons_6 = commons.newNode;
|
427 |
|
428 |
|
429 |
|
430 |
|
431 |
|
432 |
|
433 | var LISTENERS = commons.LISTENERS;
|
434 | var ATTRIBUTE = commons.ATTRIBUTE;
|
435 | var newNode = commons.newNode;
|
436 |
|
437 |
|
438 |
|
439 |
|
440 |
|
441 | |
442 |
|
443 |
|
444 |
|
445 |
|
446 |
|
447 |
|
448 | function getAttributeListener(eventTarget, type) {
|
449 | var node = eventTarget[LISTENERS][type];
|
450 | while (node != null) {
|
451 | if (node.kind === ATTRIBUTE) {
|
452 | return node.listener;
|
453 | }
|
454 | node = node.next;
|
455 | }
|
456 | return null;
|
457 | }
|
458 |
|
459 | |
460 |
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 | function setAttributeListener(eventTarget, type, listener) {
|
468 | if (typeof listener !== "function" && typeof listener !== "object") {
|
469 | listener = null;
|
470 | }
|
471 |
|
472 | var prev = null;
|
473 | var node = eventTarget[LISTENERS][type];
|
474 | while (node != null) {
|
475 | if (node.kind === ATTRIBUTE) {
|
476 |
|
477 | if (prev == null) {
|
478 | eventTarget[LISTENERS][type] = node.next;
|
479 | }
|
480 | else {
|
481 | prev.next = node.next;
|
482 | }
|
483 | }
|
484 | else {
|
485 | prev = node;
|
486 | }
|
487 |
|
488 | node = node.next;
|
489 | }
|
490 |
|
491 |
|
492 | if (listener != null) {
|
493 | if (prev == null) {
|
494 | eventTarget[LISTENERS][type] = newNode(listener, ATTRIBUTE);
|
495 | }
|
496 | else {
|
497 | prev.next = newNode(listener, ATTRIBUTE);
|
498 | }
|
499 | }
|
500 | }
|
501 |
|
502 |
|
503 |
|
504 |
|
505 |
|
506 | |
507 |
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 | var defineCustomEventTarget = function(EventTargetBase, types) {
|
514 | function EventTarget() {
|
515 | EventTargetBase.call(this);
|
516 | }
|
517 |
|
518 | var descripter = {
|
519 | constructor: {
|
520 | value: EventTarget,
|
521 | configurable: true,
|
522 | writable: true
|
523 | }
|
524 | };
|
525 |
|
526 | types.forEach(function(type) {
|
527 | descripter["on" + type] = {
|
528 | get: function() { return getAttributeListener(this, type); },
|
529 | set: function(listener) { setAttributeListener(this, type, listener); },
|
530 | configurable: true,
|
531 | enumerable: true
|
532 | };
|
533 | });
|
534 |
|
535 | EventTarget.prototype = Object.create(EventTargetBase.prototype, descripter);
|
536 |
|
537 | return EventTarget;
|
538 | };
|
539 |
|
540 | var customEventTarget = {
|
541 | defineCustomEventTarget: defineCustomEventTarget
|
542 | };
|
543 |
|
544 |
|
545 |
|
546 |
|
547 |
|
548 | var createUniqueKey = commons.createUniqueKey;
|
549 |
|
550 |
|
551 |
|
552 |
|
553 |
|
554 | |
555 |
|
556 |
|
557 |
|
558 |
|
559 |
|
560 | var STOP_IMMEDIATE_PROPAGATION_FLAG =
|
561 | createUniqueKey("stop_immediate_propagation_flag");
|
562 |
|
563 | |
564 |
|
565 |
|
566 |
|
567 |
|
568 |
|
569 | var CANCELED_FLAG = createUniqueKey("canceled_flag");
|
570 |
|
571 | |
572 |
|
573 |
|
574 |
|
575 |
|
576 |
|
577 | var ORIGINAL_EVENT = createUniqueKey("original_event");
|
578 |
|
579 | |
580 |
|
581 |
|
582 |
|
583 |
|
584 |
|
585 | var wrapperPrototypeDefinition = Object.freeze({
|
586 | stopPropagation: Object.freeze({
|
587 | value: function stopPropagation() {
|
588 | var e = this[ORIGINAL_EVENT];
|
589 | if (typeof e.stopPropagation === "function") {
|
590 | e.stopPropagation();
|
591 | }
|
592 | },
|
593 | writable: true,
|
594 | configurable: true
|
595 | }),
|
596 |
|
597 | stopImmediatePropagation: Object.freeze({
|
598 | value: function stopImmediatePropagation() {
|
599 | this[STOP_IMMEDIATE_PROPAGATION_FLAG] = true;
|
600 |
|
601 | var e = this[ORIGINAL_EVENT];
|
602 | if (typeof e.stopImmediatePropagation === "function") {
|
603 | e.stopImmediatePropagation();
|
604 | }
|
605 | },
|
606 | writable: true,
|
607 | configurable: true
|
608 | }),
|
609 |
|
610 | preventDefault: Object.freeze({
|
611 | value: function preventDefault() {
|
612 | if (this.cancelable === true) {
|
613 | this[CANCELED_FLAG] = true;
|
614 | }
|
615 |
|
616 | var e = this[ORIGINAL_EVENT];
|
617 | if (typeof e.preventDefault === "function") {
|
618 | e.preventDefault();
|
619 | }
|
620 | },
|
621 | writable: true,
|
622 | configurable: true
|
623 | }),
|
624 |
|
625 | defaultPrevented: Object.freeze({
|
626 | get: function defaultPrevented() { return this[CANCELED_FLAG]; },
|
627 | enumerable: true,
|
628 | configurable: true
|
629 | })
|
630 | });
|
631 |
|
632 |
|
633 |
|
634 |
|
635 |
|
636 | var STOP_IMMEDIATE_PROPAGATION_FLAG_1 = STOP_IMMEDIATE_PROPAGATION_FLAG;
|
637 |
|
638 | |
639 |
|
640 |
|
641 |
|
642 |
|
643 |
|
644 |
|
645 |
|
646 |
|
647 |
|
648 |
|
649 | var createEventWrapper = function createEventWrapper(event, eventTarget) {
|
650 | var timeStamp = (
|
651 | typeof event.timeStamp === "number" ? event.timeStamp : Date.now()
|
652 | );
|
653 | var propertyDefinition = {
|
654 | type: {value: event.type, enumerable: true},
|
655 | target: {value: eventTarget, enumerable: true},
|
656 | currentTarget: {value: eventTarget, enumerable: true},
|
657 | eventPhase: {value: 2, enumerable: true},
|
658 | bubbles: {value: Boolean(event.bubbles), enumerable: true},
|
659 | cancelable: {value: Boolean(event.cancelable), enumerable: true},
|
660 | timeStamp: {value: timeStamp, enumerable: true},
|
661 | isTrusted: {value: false, enumerable: true}
|
662 | };
|
663 | propertyDefinition[STOP_IMMEDIATE_PROPAGATION_FLAG] = {value: false, writable: true};
|
664 | propertyDefinition[CANCELED_FLAG] = {value: false, writable: true};
|
665 | propertyDefinition[ORIGINAL_EVENT] = {value: event};
|
666 |
|
667 |
|
668 | if (typeof event.detail !== "undefined") {
|
669 | propertyDefinition.detail = {value: event.detail, enumerable: true};
|
670 | }
|
671 |
|
672 | return Object.create(
|
673 | Object.create(event, wrapperPrototypeDefinition),
|
674 | propertyDefinition
|
675 | );
|
676 | };
|
677 |
|
678 | var eventWrapper = {
|
679 | STOP_IMMEDIATE_PROPAGATION_FLAG: STOP_IMMEDIATE_PROPAGATION_FLAG_1,
|
680 | createEventWrapper: createEventWrapper
|
681 | };
|
682 |
|
683 | var eventTarget = createCommonjsModule(function (module) {
|
684 |
|
685 |
|
686 |
|
687 |
|
688 |
|
689 |
|
690 |
|
691 |
|
692 | var LISTENERS = commons.LISTENERS;
|
693 | var CAPTURE = commons.CAPTURE;
|
694 | var BUBBLE = commons.BUBBLE;
|
695 | var ATTRIBUTE = commons.ATTRIBUTE;
|
696 | var newNode = commons.newNode;
|
697 | var defineCustomEventTarget = customEventTarget.defineCustomEventTarget;
|
698 | var createEventWrapper = eventWrapper.createEventWrapper;
|
699 | var STOP_IMMEDIATE_PROPAGATION_FLAG =
|
700 | eventWrapper.STOP_IMMEDIATE_PROPAGATION_FLAG;
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 | |
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 | var HAS_EVENTTARGET_INTERFACE = (
|
713 | typeof window !== "undefined" &&
|
714 | typeof window.EventTarget !== "undefined"
|
715 | );
|
716 |
|
717 |
|
718 |
|
719 |
|
720 |
|
721 | |
722 |
|
723 |
|
724 |
|
725 |
|
726 |
|
727 | var EventTarget = module.exports = function EventTarget() {
|
728 | if (this instanceof EventTarget) {
|
729 |
|
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 | Object.defineProperty(this, LISTENERS, {value: Object.create(null)});
|
739 | }
|
740 | else if (arguments.length === 1 && Array.isArray(arguments[0])) {
|
741 | return defineCustomEventTarget(EventTarget, arguments[0]);
|
742 | }
|
743 | else if (arguments.length > 0) {
|
744 | var types = Array(arguments.length);
|
745 | for (var i = 0; i < arguments.length; ++i) {
|
746 | types[i] = arguments[i];
|
747 | }
|
748 |
|
749 |
|
750 |
|
751 |
|
752 |
|
753 |
|
754 | return defineCustomEventTarget(EventTarget, types);
|
755 | }
|
756 | else {
|
757 | throw new TypeError("Cannot call a class as a function");
|
758 | }
|
759 | };
|
760 |
|
761 | EventTarget.prototype = Object.create(
|
762 | (HAS_EVENTTARGET_INTERFACE ? window.EventTarget : Object).prototype,
|
763 | {
|
764 | constructor: {
|
765 | value: EventTarget,
|
766 | writable: true,
|
767 | configurable: true
|
768 | },
|
769 |
|
770 | addEventListener: {
|
771 | value: function addEventListener(type, listener, capture) {
|
772 | if (listener == null) {
|
773 | return false;
|
774 | }
|
775 | if (typeof listener !== "function" && typeof listener !== "object") {
|
776 | throw new TypeError("\"listener\" is not an object.");
|
777 | }
|
778 |
|
779 | var kind = (capture ? CAPTURE : BUBBLE);
|
780 | var node = this[LISTENERS][type];
|
781 | if (node == null) {
|
782 | this[LISTENERS][type] = newNode(listener, kind);
|
783 | return true;
|
784 | }
|
785 |
|
786 | var prev = null;
|
787 | while (node != null) {
|
788 | if (node.listener === listener && node.kind === kind) {
|
789 |
|
790 | return false;
|
791 | }
|
792 | prev = node;
|
793 | node = node.next;
|
794 | }
|
795 |
|
796 | prev.next = newNode(listener, kind);
|
797 | return true;
|
798 | },
|
799 | configurable: true,
|
800 | writable: true
|
801 | },
|
802 |
|
803 | removeEventListener: {
|
804 | value: function removeEventListener(type, listener, capture) {
|
805 | if (listener == null) {
|
806 | return false;
|
807 | }
|
808 |
|
809 | var kind = (capture ? CAPTURE : BUBBLE);
|
810 | var prev = null;
|
811 | var node = this[LISTENERS][type];
|
812 | while (node != null) {
|
813 | if (node.listener === listener && node.kind === kind) {
|
814 | if (prev == null) {
|
815 | this[LISTENERS][type] = node.next;
|
816 | }
|
817 | else {
|
818 | prev.next = node.next;
|
819 | }
|
820 | return true;
|
821 | }
|
822 |
|
823 | prev = node;
|
824 | node = node.next;
|
825 | }
|
826 |
|
827 | return false;
|
828 | },
|
829 | configurable: true,
|
830 | writable: true
|
831 | },
|
832 |
|
833 | dispatchEvent: {
|
834 | value: function dispatchEvent(event) {
|
835 |
|
836 | var node = this[LISTENERS][event.type];
|
837 | if (node == null) {
|
838 | return true;
|
839 | }
|
840 |
|
841 |
|
842 | var wrapped = createEventWrapper(event, this);
|
843 |
|
844 |
|
845 |
|
846 | while (node != null) {
|
847 | if (typeof node.listener === "function") {
|
848 | node.listener.call(this, wrapped);
|
849 | }
|
850 | else if (node.kind !== ATTRIBUTE && typeof node.listener.handleEvent === "function") {
|
851 | node.listener.handleEvent(wrapped);
|
852 | }
|
853 |
|
854 | if (wrapped[STOP_IMMEDIATE_PROPAGATION_FLAG]) {
|
855 | break;
|
856 | }
|
857 | node = node.next;
|
858 | }
|
859 |
|
860 | return !wrapped.defaultPrevented;
|
861 | },
|
862 | configurable: true,
|
863 | writable: true
|
864 | }
|
865 | }
|
866 | );
|
867 | });
|
868 |
|
869 | var FormData$1 =
|
870 |
|
871 | function () {
|
872 | function FormData() {
|
873 | this._entries = [];
|
874 | }
|
875 |
|
876 | var _proto = FormData.prototype;
|
877 |
|
878 | _proto.append = function append(name, value) {
|
879 | if (typeof name !== 'string') {
|
880 | throw new TypeError('FormData name must be a string');
|
881 | }
|
882 |
|
883 | if (typeof value !== 'string') {
|
884 | if (_typeof(value) !== 'object' || typeof value.uri !== 'string') {
|
885 | throw new TypeError('FormData value must be a string or { uri: tempFilePath }');
|
886 | }
|
887 | }
|
888 |
|
889 | this._entries.push([name, value]);
|
890 | };
|
891 |
|
892 | _proto.set = function set(name, value) {
|
893 | var entry = this.get(name);
|
894 |
|
895 | if (entry) {
|
896 | entry[1] = value;
|
897 | } else {
|
898 | this.append(name, value);
|
899 | }
|
900 | };
|
901 |
|
902 | _proto.delete = function _delete(name) {
|
903 | this._entries = this._entries.filter(function (entry) {
|
904 | return entry[0] !== name;
|
905 | });
|
906 | };
|
907 |
|
908 | _proto.entries = function entries() {
|
909 | return this._entries;
|
910 | };
|
911 |
|
912 | _proto.get = function get(name) {
|
913 | return this._entries.find(function (entry) {
|
914 | return entry[0] === name;
|
915 | });
|
916 | };
|
917 |
|
918 | _proto.getAll = function getAll(name) {
|
919 | return this._entries.filter(function (entry) {
|
920 | return entry[0] === name;
|
921 | });
|
922 | };
|
923 |
|
924 | _proto.has = function has(name) {
|
925 | return this._entries.some(function (entry) {
|
926 | return entry[0] === name;
|
927 | });
|
928 | };
|
929 |
|
930 | _proto.keys = function keys() {
|
931 | return this._entries.map(function (entry) {
|
932 | return entry[0];
|
933 | });
|
934 | };
|
935 |
|
936 | _proto.values = function values() {
|
937 | return this._entries.map(function (entry) {
|
938 | return entry[1];
|
939 | });
|
940 | };
|
941 |
|
942 | return FormData;
|
943 | }();
|
944 |
|
945 | var formdata = FormData$1;
|
946 |
|
947 | var UNSENT = 0;
|
948 | var OPENED = 1;
|
949 | var HEADERS_RECEIVED = 2;
|
950 | var LOADING = 3;
|
951 | var DONE = 4;
|
952 | var REQUEST_EVENTS = ['abort', 'error', 'load', 'loadstart', 'progress', 'timeout', 'loadend', 'readystatechange'];
|
953 | var REQUEST_UPLOAD_EVENTS = ['abort', 'error', 'load', 'loadstart', 'progress', 'timeout', 'loadend'];
|
954 |
|
955 | function successCallback(response) {
|
956 | this.status = response.statusCode;
|
957 | this.statusText = response.statusCode;
|
958 |
|
959 | if (response.header) {
|
960 | this._responseHeaders = Object.keys(response.header).reduce(function (headers, key) {
|
961 | headers[key.toLowerCase()] = response.header[key];
|
962 | return headers;
|
963 | }, {});
|
964 | }
|
965 |
|
966 | var text = response.data;
|
967 |
|
968 | if (typeof text !== 'string') {
|
969 | text = JSON.stringify(text);
|
970 | }
|
971 |
|
972 | this.responseText = this.response = text;
|
973 | this.readyState = DONE;
|
974 | this.dispatchEvent({
|
975 | type: 'readystatechange'
|
976 | });
|
977 | }
|
978 |
|
979 | var XMLHttpRequestUpload =
|
980 |
|
981 | function (_EventTarget) {
|
982 | _inheritsLoose(XMLHttpRequestUpload, _EventTarget);
|
983 |
|
984 | function XMLHttpRequestUpload() {
|
985 | return _EventTarget.apply(this, arguments) || this;
|
986 | }
|
987 |
|
988 | return XMLHttpRequestUpload;
|
989 | }(eventTarget(REQUEST_UPLOAD_EVENTS));
|
990 |
|
991 | var XMLHttpRequest$1 =
|
992 |
|
993 | function (_EventTarget2) {
|
994 | _inheritsLoose(XMLHttpRequest, _EventTarget2);
|
995 |
|
996 | function XMLHttpRequest() {
|
997 | var _this;
|
998 |
|
999 | _this = _EventTarget2.call(this) || this;
|
1000 | _this.readyState = UNSENT;
|
1001 | _this._headers = {};
|
1002 | _this.upload = new XMLHttpRequestUpload();
|
1003 | return _this;
|
1004 | }
|
1005 |
|
1006 | var _proto = XMLHttpRequest.prototype;
|
1007 |
|
1008 | _proto.abort = function abort() {
|
1009 |
|
1010 | if (!this._request || this._request.abort) {
|
1011 | this.status = 0;
|
1012 | this.readyState = DONE;
|
1013 | return this._request.abort();
|
1014 | }
|
1015 |
|
1016 | throw new Error('该版本基础库不支持 abort request');
|
1017 | };
|
1018 |
|
1019 | _proto.getAllResponseHeaders = function getAllResponseHeaders() {
|
1020 | var _this2 = this;
|
1021 |
|
1022 | return this._responseHeaders ? Object.keys(this._responseHeaders).map(function (key) {
|
1023 | return "".concat(key, ": ").concat(_this2._responseHeaders[key]);
|
1024 | }).join('\r\n') : '';
|
1025 | };
|
1026 |
|
1027 | _proto.getResponseHeader = function getResponseHeader(key) {
|
1028 | var lowserCasedKey = key.toLowerCase();
|
1029 |
|
1030 | if (this._responseHeaders && this._responseHeaders[lowserCasedKey]) {
|
1031 | return this._responseHeaders[lowserCasedKey];
|
1032 | }
|
1033 |
|
1034 | return null;
|
1035 | };
|
1036 |
|
1037 | _proto.overrideMimeType = function overrideMimeType() {
|
1038 | throw new Error('not supported in weapp');
|
1039 | };
|
1040 |
|
1041 | _proto.open = function open(method, url) {
|
1042 | var async = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
1043 |
|
1044 | if (this.readyState !== UNSENT) {
|
1045 | throw new Error('request is already opened');
|
1046 | }
|
1047 |
|
1048 | if (!async) {
|
1049 | throw new Error('sync request is not supported');
|
1050 | }
|
1051 |
|
1052 | this._method = method;
|
1053 | this._url = url;
|
1054 | this.readyState = OPENED;
|
1055 | this.dispatchEvent({
|
1056 | type: 'readystatechange'
|
1057 | });
|
1058 | };
|
1059 |
|
1060 | _proto.setRequestHeader = function setRequestHeader(header, value) {
|
1061 | if (this.readyState !== OPENED) {
|
1062 | throw new Error('request is not opened');
|
1063 | }
|
1064 |
|
1065 | this._headers[header.toLowerCase()] = value;
|
1066 | };
|
1067 |
|
1068 | _proto.send = function send(data) {
|
1069 | var _this3 = this;
|
1070 |
|
1071 | if (this.readyState !== OPENED) {
|
1072 | throw new Error('request is not opened');
|
1073 | }
|
1074 |
|
1075 | if (data instanceof formdata) {
|
1076 | var entries = data.entries();
|
1077 | var blobs = entries.filter(function (entry) {
|
1078 | return typeof entry[1] !== 'string';
|
1079 | });
|
1080 |
|
1081 | if (blobs.length === 0) {
|
1082 | throw new Error('Must specify a Blob field in FormData');
|
1083 | }
|
1084 |
|
1085 | if (blobs.length > 1) {
|
1086 | console.warn('Only the first Blob will be send in Weapp');
|
1087 | }
|
1088 |
|
1089 | var restData = entries.filter(function (entry) {
|
1090 | return typeof entry[1] === 'string';
|
1091 | }).reduce(function (result, entry) {
|
1092 | return objectAssign(result, _defineProperty({}, entry[0], entry[1]));
|
1093 | }, {});
|
1094 | this._request = wx.uploadFile({
|
1095 | url: this._url,
|
1096 | name: blobs[0][0],
|
1097 | filePath: blobs[0][1].uri,
|
1098 | formData: restData,
|
1099 | header: this._headers,
|
1100 | success: successCallback.bind(this),
|
1101 | fail: function fail(error) {
|
1102 | _this3.status = 0;
|
1103 | _this3.readyState = DONE;
|
1104 |
|
1105 | _this3.dispatchEvent({
|
1106 | type: 'readystatechange'
|
1107 | });
|
1108 |
|
1109 | _this3.dispatchEvent({
|
1110 | type: 'error'
|
1111 | });
|
1112 | }
|
1113 | });
|
1114 |
|
1115 | if (this._request && this._request.onProgressUpdate) {
|
1116 | this._request.onProgressUpdate(function (_ref) {
|
1117 | var totalBytesSent = _ref.totalBytesSent,
|
1118 | totalBytesExpectedToSend = _ref.totalBytesExpectedToSend;
|
1119 |
|
1120 | _this3.upload.dispatchEvent({
|
1121 | type: 'progress',
|
1122 | loaded: totalBytesSent,
|
1123 | total: totalBytesExpectedToSend
|
1124 | });
|
1125 | });
|
1126 | }
|
1127 | } else {
|
1128 | this._request = wx.request({
|
1129 | url: this._url,
|
1130 | data: data || '',
|
1131 |
|
1132 | method: this._method.toUpperCase(),
|
1133 | header: this._headers,
|
1134 | success: successCallback.bind(this),
|
1135 | fail: function fail(error) {
|
1136 | _this3.status = 0;
|
1137 | _this3.readyState = DONE;
|
1138 |
|
1139 | _this3.dispatchEvent({
|
1140 | type: 'readystatechange'
|
1141 | });
|
1142 |
|
1143 | _this3.dispatchEvent({
|
1144 | type: 'error'
|
1145 | });
|
1146 | }
|
1147 | });
|
1148 | }
|
1149 | };
|
1150 |
|
1151 | return XMLHttpRequest;
|
1152 | }(eventTarget(REQUEST_EVENTS));
|
1153 |
|
1154 | objectAssign(XMLHttpRequest$1, {
|
1155 | UNSENT: UNSENT,
|
1156 | OPENED: OPENED,
|
1157 | HEADERS_RECEIVED: HEADERS_RECEIVED,
|
1158 | LOADING: LOADING,
|
1159 | DONE: DONE
|
1160 | });
|
1161 | var xmlhttprequest = XMLHttpRequest$1;
|
1162 |
|
1163 | var CONNECTING = 0;
|
1164 | var OPEN = 1;
|
1165 | var CLOSING = 2;
|
1166 | var CLOSED = 3;
|
1167 | var EVENTS = ['open', 'error', 'message', 'close'];
|
1168 |
|
1169 | var WebSocket$1 =
|
1170 |
|
1171 | function (_EventTarget) {
|
1172 | _inheritsLoose(WebSocket, _EventTarget);
|
1173 |
|
1174 | function WebSocket(url, protocal) {
|
1175 | var _this;
|
1176 |
|
1177 | if (!url) {
|
1178 | throw new TypeError('Failed to construct \'WebSocket\': url required');
|
1179 | }
|
1180 |
|
1181 | if (protocal && !(wx.canIUse && wx.canIUse('connectSocket.object.protocols'))) {
|
1182 | throw new Error('subprotocal not supported in weapp');
|
1183 | }
|
1184 |
|
1185 | _this = _EventTarget.call(this) || this;
|
1186 | _this._url = url;
|
1187 | _this._protocal = protocal || '';
|
1188 |
|
1189 | _this._readyState = CONNECTING;
|
1190 |
|
1191 | var errorHandler = function errorHandler(event) {
|
1192 | _this._readyState = CLOSED;
|
1193 |
|
1194 | _this.dispatchEvent({
|
1195 | type: 'error',
|
1196 | message: event.errMsg
|
1197 | });
|
1198 | };
|
1199 |
|
1200 | var socketTask = wx.connectSocket({
|
1201 | url: url,
|
1202 | protocals: _this._protocal,
|
1203 | fail: function fail(error) {
|
1204 | return setTimeout(function () {
|
1205 | return errorHandler(error);
|
1206 | }, 0);
|
1207 | }
|
1208 | });
|
1209 | _this._socketTask = socketTask;
|
1210 | socketTask.onOpen(function (event) {
|
1211 | _this._readyState = OPEN;
|
1212 |
|
1213 | _this.dispatchEvent({
|
1214 | type: 'open'
|
1215 | });
|
1216 | });
|
1217 | socketTask.onError(errorHandler);
|
1218 | socketTask.onMessage(function (event) {
|
1219 | var data = event.data,
|
1220 | origin = event.origin,
|
1221 | ports = event.ports,
|
1222 | source = event.source;
|
1223 |
|
1224 | _this.dispatchEvent({
|
1225 | data: data,
|
1226 | origin: origin,
|
1227 | ports: ports,
|
1228 | source: source,
|
1229 | type: 'message'
|
1230 | });
|
1231 | });
|
1232 | socketTask.onClose(function (event) {
|
1233 | _this._readyState = CLOSED;
|
1234 | var code = event.code,
|
1235 | reason = event.reason,
|
1236 | wasClean = event.wasClean;
|
1237 |
|
1238 | _this.dispatchEvent({
|
1239 | code: code,
|
1240 | reason: reason,
|
1241 | wasClean: wasClean,
|
1242 | type: 'close'
|
1243 | });
|
1244 | });
|
1245 | return _this;
|
1246 | }
|
1247 |
|
1248 | var _proto = WebSocket.prototype;
|
1249 |
|
1250 | _proto.close = function close() {
|
1251 | if (this.readyState === CLOSED) return;
|
1252 |
|
1253 | if (this.readyState === CONNECTING) {
|
1254 | console.warn('close WebSocket which is connecting might not work');
|
1255 | }
|
1256 |
|
1257 | this._socketTask.close();
|
1258 | };
|
1259 |
|
1260 | _proto.send = function send(data) {
|
1261 | if (this.readyState !== OPEN) {
|
1262 | throw new Error('INVALID_STATE_ERR');
|
1263 | }
|
1264 |
|
1265 | if (!(typeof data === 'string' || data instanceof ArrayBuffer)) {
|
1266 | throw new TypeError('only String/ArrayBuffer supported');
|
1267 | }
|
1268 |
|
1269 | this._socketTask.send({
|
1270 | data: data
|
1271 | });
|
1272 | };
|
1273 |
|
1274 | _createClass(WebSocket, [{
|
1275 | key: "url",
|
1276 | get: function get() {
|
1277 | return this._url;
|
1278 | }
|
1279 | }, {
|
1280 | key: "protocal",
|
1281 | get: function get() {
|
1282 | return this._protocal;
|
1283 | }
|
1284 | }, {
|
1285 | key: "readyState",
|
1286 | get: function get() {
|
1287 | return this._readyState;
|
1288 | }
|
1289 | }]);
|
1290 |
|
1291 | return WebSocket;
|
1292 | }(eventTarget(EVENTS));
|
1293 |
|
1294 | objectAssign(WebSocket$1, {
|
1295 | CONNECTING: CONNECTING,
|
1296 | OPEN: OPEN,
|
1297 | CLOSING: CLOSING,
|
1298 | CLOSED: CLOSED
|
1299 | });
|
1300 | var websocket = WebSocket$1;
|
1301 |
|
1302 | var polyfill = function polyfill(target) {
|
1303 | if (!wx.onNetworkStatusChange) return;
|
1304 | if (target.__onlineOfflinePolyfilled) return;
|
1305 | target.__onlineOfflinePolyfilled = true;
|
1306 | var internalEventTarget = new eventTarget();
|
1307 |
|
1308 | if (!target.dispatchEvent) {
|
1309 | target.addEventListener = internalEventTarget.addEventListener.bind(internalEventTarget);
|
1310 | target.removeEventListener = internalEventTarget.removeEventListener.bind(internalEventTarget);
|
1311 | target.dispatchEvent = internalEventTarget.dispatchEvent.bind(internalEventTarget);
|
1312 |
|
1313 |
|
1314 | if (typeof postMessage == 'function' && !target.importScripts) {
|
1315 | target.importScripts = function () {
|
1316 | throw new Error('mocked');
|
1317 | };
|
1318 | }
|
1319 | }
|
1320 |
|
1321 | wx.getNetworkType({
|
1322 | success: function success(_ref) {
|
1323 | var networkType = _ref.networkType;
|
1324 | target.onLine = networkType !== 'none';
|
1325 | wx.onNetworkStatusChange(function (_ref2) {
|
1326 | var isConnected = _ref2.isConnected;
|
1327 | if (target.onLine === isConnected) return;
|
1328 | target.onLine = isConnected;
|
1329 | target.dispatchEvent({
|
1330 | type: isConnected ? 'online' : 'offline'
|
1331 | });
|
1332 | });
|
1333 | }
|
1334 | });
|
1335 | };
|
1336 |
|
1337 | var onlineOfflineEvents = {
|
1338 | polyfill: polyfill
|
1339 | };
|
1340 |
|
1341 | var navigator$1 = {};
|
1342 |
|
1343 | var weappPolyfill = {
|
1344 | polyfill: function polyfill() {
|
1345 | var target = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : commonjsGlobal || window;
|
1346 |
|
1347 | if (_typeof(target) !== 'object') {
|
1348 | throw new Error('polyfill target is not an Object');
|
1349 | }
|
1350 |
|
1351 | var polyfills = {
|
1352 | localStorage: localstorage,
|
1353 | XMLHttpRequest: xmlhttprequest,
|
1354 | FormData: formdata,
|
1355 | WebSocket: websocket,
|
1356 | Object: Object,
|
1357 | navigator: navigator$1
|
1358 | };
|
1359 |
|
1360 | for (var k in polyfills) {
|
1361 | if (!target[k]) target[k] = polyfills[k];
|
1362 | }
|
1363 |
|
1364 | onlineOfflineEvents.polyfill(target);
|
1365 |
|
1366 | target.navigator.product = 'ReactNative';
|
1367 | },
|
1368 | localStorage: localstorage,
|
1369 | XMLHttpRequest: xmlhttprequest,
|
1370 | FormData: formdata,
|
1371 | WebSocket: websocket
|
1372 | };
|
1373 |
|
1374 | var polyfill$1 = weappPolyfill.polyfill;
|
1375 |
|
1376 | try {
|
1377 | polyfill$1();
|
1378 | } catch (e) {}
|
1379 |
|
1380 | try {
|
1381 | polyfill$1(GameGlobal);
|
1382 | } catch (e) {}
|
1383 |
|
1384 | try {
|
1385 | window = window || {};
|
1386 | polyfill$1(window);
|
1387 | } catch (e) {}
|
1388 |
|
1389 | try {
|
1390 | localStorage = localStorage || localstorage;
|
1391 | } catch (e) {}
|
1392 |
|
1393 | try {
|
1394 | XMLHttpRequest = XMLHttpRequest || xmlhttprequest;
|
1395 | } catch (e) {}
|
1396 |
|
1397 | try {
|
1398 | FormData = FormData || formdata;
|
1399 | } catch (e) {}
|
1400 |
|
1401 | try {
|
1402 | WebSocket = WebSocket || websocket;
|
1403 | } catch (e) {}
|
1404 |
|
1405 | try {
|
1406 | navigator = navigator || navigator$1;
|
1407 | } catch (e) {}
|
1408 |
|
1409 |
|
1410 |
|
1411 | var long_1 = createCommonjsModule(function (module) {
|
1412 | |
1413 |
|
1414 |
|
1415 |
|
1416 |
|
1417 |
|
1418 |
|
1419 |
|
1420 |
|
1421 |
|
1422 |
|
1423 |
|
1424 |
|
1425 |
|
1426 |
|
1427 |
|
1428 |
|
1429 | |
1430 |
|
1431 |
|
1432 |
|
1433 |
|
1434 | (function(global, factory) {
|
1435 |
|
1436 | if (typeof commonjsRequire === 'function' && 'object' === "object" && module && module["exports"])
|
1437 | module["exports"] = factory();
|
1438 | else
|
1439 | (global["dcodeIO"] = global["dcodeIO"] || {})["Long"] = factory();
|
1440 |
|
1441 | })(commonjsGlobal, function() {
|
1442 |
|
1443 | |
1444 |
|
1445 |
|
1446 |
|
1447 |
|
1448 |
|
1449 |
|
1450 |
|
1451 |
|
1452 |
|
1453 | function Long(low, high, unsigned) {
|
1454 |
|
1455 | |
1456 |
|
1457 |
|
1458 |
|
1459 | this.low = low | 0;
|
1460 |
|
1461 | |
1462 |
|
1463 |
|
1464 |
|
1465 | this.high = high | 0;
|
1466 |
|
1467 | |
1468 |
|
1469 |
|
1470 |
|
1471 | this.unsigned = !!unsigned;
|
1472 | }
|
1473 |
|
1474 |
|
1475 |
|
1476 |
|
1477 |
|
1478 |
|
1479 |
|
1480 |
|
1481 |
|
1482 |
|
1483 |
|
1484 |
|
1485 |
|
1486 |
|
1487 |
|
1488 |
|
1489 |
|
1490 |
|
1491 | |
1492 |
|
1493 |
|
1494 |
|
1495 |
|
1496 |
|
1497 | Long.prototype.__isLong__;
|
1498 |
|
1499 | Object.defineProperty(Long.prototype, "__isLong__", {
|
1500 | value: true,
|
1501 | enumerable: false,
|
1502 | configurable: false
|
1503 | });
|
1504 |
|
1505 | |
1506 |
|
1507 |
|
1508 |
|
1509 |
|
1510 |
|
1511 | function isLong(obj) {
|
1512 | return (obj && obj["__isLong__"]) === true;
|
1513 | }
|
1514 |
|
1515 | |
1516 |
|
1517 |
|
1518 |
|
1519 |
|
1520 |
|
1521 | Long.isLong = isLong;
|
1522 |
|
1523 | |
1524 |
|
1525 |
|
1526 |
|
1527 |
|
1528 | var INT_CACHE = {};
|
1529 |
|
1530 | |
1531 |
|
1532 |
|
1533 |
|
1534 |
|
1535 | var UINT_CACHE = {};
|
1536 |
|
1537 | |
1538 |
|
1539 |
|
1540 |
|
1541 |
|
1542 |
|
1543 | function fromInt(value, unsigned) {
|
1544 | var obj, cachedObj, cache;
|
1545 | if (unsigned) {
|
1546 | value >>>= 0;
|
1547 | if (cache = (0 <= value && value < 256)) {
|
1548 | cachedObj = UINT_CACHE[value];
|
1549 | if (cachedObj)
|
1550 | return cachedObj;
|
1551 | }
|
1552 | obj = fromBits(value, (value | 0) < 0 ? -1 : 0, true);
|
1553 | if (cache)
|
1554 | UINT_CACHE[value] = obj;
|
1555 | return obj;
|
1556 | } else {
|
1557 | value |= 0;
|
1558 | if (cache = (-128 <= value && value < 128)) {
|
1559 | cachedObj = INT_CACHE[value];
|
1560 | if (cachedObj)
|
1561 | return cachedObj;
|
1562 | }
|
1563 | obj = fromBits(value, value < 0 ? -1 : 0, false);
|
1564 | if (cache)
|
1565 | INT_CACHE[value] = obj;
|
1566 | return obj;
|
1567 | }
|
1568 | }
|
1569 |
|
1570 | |
1571 |
|
1572 |
|
1573 |
|
1574 |
|
1575 |
|
1576 |
|
1577 | Long.fromInt = fromInt;
|
1578 |
|
1579 | |
1580 |
|
1581 |
|
1582 |
|
1583 |
|
1584 |
|
1585 | function fromNumber(value, unsigned) {
|
1586 | if (isNaN(value) || !isFinite(value))
|
1587 | return unsigned ? UZERO : ZERO;
|
1588 | if (unsigned) {
|
1589 | if (value < 0)
|
1590 | return UZERO;
|
1591 | if (value >= TWO_PWR_64_DBL)
|
1592 | return MAX_UNSIGNED_VALUE;
|
1593 | } else {
|
1594 | if (value <= -TWO_PWR_63_DBL)
|
1595 | return MIN_VALUE;
|
1596 | if (value + 1 >= TWO_PWR_63_DBL)
|
1597 | return MAX_VALUE;
|
1598 | }
|
1599 | if (value < 0)
|
1600 | return fromNumber(-value, unsigned).neg();
|
1601 | return fromBits((value % TWO_PWR_32_DBL) | 0, (value / TWO_PWR_32_DBL) | 0, unsigned);
|
1602 | }
|
1603 |
|
1604 | |
1605 |
|
1606 |
|
1607 |
|
1608 |
|
1609 |
|
1610 |
|
1611 | Long.fromNumber = fromNumber;
|
1612 |
|
1613 | |
1614 |
|
1615 |
|
1616 |
|
1617 |
|
1618 |
|
1619 |
|
1620 | function fromBits(lowBits, highBits, unsigned) {
|
1621 | return new Long(lowBits, highBits, unsigned);
|
1622 | }
|
1623 |
|
1624 | |
1625 |
|
1626 |
|
1627 |
|
1628 |
|
1629 |
|
1630 |
|
1631 |
|
1632 |
|
1633 | Long.fromBits = fromBits;
|
1634 |
|
1635 | |
1636 |
|
1637 |
|
1638 |
|
1639 |
|
1640 |
|
1641 |
|
1642 | var pow_dbl = Math.pow;
|
1643 |
|
1644 | |
1645 |
|
1646 |
|
1647 |
|
1648 |
|
1649 |
|
1650 |
|
1651 | function fromString(str, unsigned, radix) {
|
1652 | if (str.length === 0)
|
1653 | throw Error('empty string');
|
1654 | if (str === "NaN" || str === "Infinity" || str === "+Infinity" || str === "-Infinity")
|
1655 | return ZERO;
|
1656 | if (typeof unsigned === 'number') {
|
1657 |
|
1658 | radix = unsigned,
|
1659 | unsigned = false;
|
1660 | } else {
|
1661 | unsigned = !! unsigned;
|
1662 | }
|
1663 | radix = radix || 10;
|
1664 | if (radix < 2 || 36 < radix)
|
1665 | throw RangeError('radix');
|
1666 |
|
1667 | var p;
|
1668 | if ((p = str.indexOf('-')) > 0)
|
1669 | throw Error('interior hyphen');
|
1670 | else if (p === 0) {
|
1671 | return fromString(str.substring(1), unsigned, radix).neg();
|
1672 | }
|
1673 |
|
1674 |
|
1675 |
|
1676 | var radixToPower = fromNumber(pow_dbl(radix, 8));
|
1677 |
|
1678 | var result = ZERO;
|
1679 | for (var i = 0; i < str.length; i += 8) {
|
1680 | var size = Math.min(8, str.length - i),
|
1681 | value = parseInt(str.substring(i, i + size), radix);
|
1682 | if (size < 8) {
|
1683 | var power = fromNumber(pow_dbl(radix, size));
|
1684 | result = result.mul(power).add(fromNumber(value));
|
1685 | } else {
|
1686 | result = result.mul(radixToPower);
|
1687 | result = result.add(fromNumber(value));
|
1688 | }
|
1689 | }
|
1690 | result.unsigned = unsigned;
|
1691 | return result;
|
1692 | }
|
1693 |
|
1694 | |
1695 |
|
1696 |
|
1697 |
|
1698 |
|
1699 |
|
1700 |
|
1701 |
|
1702 | Long.fromString = fromString;
|
1703 |
|
1704 | |
1705 |
|
1706 |
|
1707 |
|
1708 |
|
1709 |
|
1710 | function fromValue(val) {
|
1711 | if (val instanceof Long)
|
1712 | return val;
|
1713 | if (typeof val === 'number')
|
1714 | return fromNumber(val);
|
1715 | if (typeof val === 'string')
|
1716 | return fromString(val);
|
1717 |
|
1718 | return fromBits(val.low, val.high, val.unsigned);
|
1719 | }
|
1720 |
|
1721 | |
1722 |
|
1723 |
|
1724 |
|
1725 |
|
1726 |
|
1727 | Long.fromValue = fromValue;
|
1728 |
|
1729 |
|
1730 |
|
1731 |
|
1732 | |
1733 |
|
1734 |
|
1735 |
|
1736 |
|
1737 | var TWO_PWR_16_DBL = 1 << 16;
|
1738 |
|
1739 | |
1740 |
|
1741 |
|
1742 |
|
1743 |
|
1744 | var TWO_PWR_24_DBL = 1 << 24;
|
1745 |
|
1746 | |
1747 |
|
1748 |
|
1749 |
|
1750 |
|
1751 | var TWO_PWR_32_DBL = TWO_PWR_16_DBL * TWO_PWR_16_DBL;
|
1752 |
|
1753 | |
1754 |
|
1755 |
|
1756 |
|
1757 |
|
1758 | var TWO_PWR_64_DBL = TWO_PWR_32_DBL * TWO_PWR_32_DBL;
|
1759 |
|
1760 | |
1761 |
|
1762 |
|
1763 |
|
1764 |
|
1765 | var TWO_PWR_63_DBL = TWO_PWR_64_DBL / 2;
|
1766 |
|
1767 | |
1768 |
|
1769 |
|
1770 |
|
1771 |
|
1772 | var TWO_PWR_24 = fromInt(TWO_PWR_24_DBL);
|
1773 |
|
1774 | |
1775 |
|
1776 |
|
1777 |
|
1778 | var ZERO = fromInt(0);
|
1779 |
|
1780 | |
1781 |
|
1782 |
|
1783 |
|
1784 | Long.ZERO = ZERO;
|
1785 |
|
1786 | |
1787 |
|
1788 |
|
1789 |
|
1790 | var UZERO = fromInt(0, true);
|
1791 |
|
1792 | |
1793 |
|
1794 |
|
1795 |
|
1796 | Long.UZERO = UZERO;
|
1797 |
|
1798 | |
1799 |
|
1800 |
|
1801 |
|
1802 | var ONE = fromInt(1);
|
1803 |
|
1804 | |
1805 |
|
1806 |
|
1807 |
|
1808 | Long.ONE = ONE;
|
1809 |
|
1810 | |
1811 |
|
1812 |
|
1813 |
|
1814 | var UONE = fromInt(1, true);
|
1815 |
|
1816 | |
1817 |
|
1818 |
|
1819 |
|
1820 | Long.UONE = UONE;
|
1821 |
|
1822 | |
1823 |
|
1824 |
|
1825 |
|
1826 | var NEG_ONE = fromInt(-1);
|
1827 |
|
1828 | |
1829 |
|
1830 |
|
1831 |
|
1832 | Long.NEG_ONE = NEG_ONE;
|
1833 |
|
1834 | |
1835 |
|
1836 |
|
1837 |
|
1838 | var MAX_VALUE = fromBits(0xFFFFFFFF|0, 0x7FFFFFFF|0, false);
|
1839 |
|
1840 | |
1841 |
|
1842 |
|
1843 |
|
1844 | Long.MAX_VALUE = MAX_VALUE;
|
1845 |
|
1846 | |
1847 |
|
1848 |
|
1849 |
|
1850 | var MAX_UNSIGNED_VALUE = fromBits(0xFFFFFFFF|0, 0xFFFFFFFF|0, true);
|
1851 |
|
1852 | |
1853 |
|
1854 |
|
1855 |
|
1856 | Long.MAX_UNSIGNED_VALUE = MAX_UNSIGNED_VALUE;
|
1857 |
|
1858 | |
1859 |
|
1860 |
|
1861 |
|
1862 | var MIN_VALUE = fromBits(0, 0x80000000|0, false);
|
1863 |
|
1864 | |
1865 |
|
1866 |
|
1867 |
|
1868 | Long.MIN_VALUE = MIN_VALUE;
|
1869 |
|
1870 | |
1871 |
|
1872 |
|
1873 |
|
1874 | var LongPrototype = Long.prototype;
|
1875 |
|
1876 | |
1877 |
|
1878 |
|
1879 |
|
1880 | LongPrototype.toInt = function toInt() {
|
1881 | return this.unsigned ? this.low >>> 0 : this.low;
|
1882 | };
|
1883 |
|
1884 | |
1885 |
|
1886 |
|
1887 |
|
1888 | LongPrototype.toNumber = function toNumber() {
|
1889 | if (this.unsigned)
|
1890 | return ((this.high >>> 0) * TWO_PWR_32_DBL) + (this.low >>> 0);
|
1891 | return this.high * TWO_PWR_32_DBL + (this.low >>> 0);
|
1892 | };
|
1893 |
|
1894 | |
1895 |
|
1896 |
|
1897 |
|
1898 |
|
1899 |
|
1900 |
|
1901 | LongPrototype.toString = function toString(radix) {
|
1902 | radix = radix || 10;
|
1903 | if (radix < 2 || 36 < radix)
|
1904 | throw RangeError('radix');
|
1905 | if (this.isZero())
|
1906 | return '0';
|
1907 | if (this.isNegative()) {
|
1908 | if (this.eq(MIN_VALUE)) {
|
1909 |
|
1910 |
|
1911 | var radixLong = fromNumber(radix),
|
1912 | div = this.div(radixLong),
|
1913 | rem1 = div.mul(radixLong).sub(this);
|
1914 | return div.toString(radix) + rem1.toInt().toString(radix);
|
1915 | } else
|
1916 | return '-' + this.neg().toString(radix);
|
1917 | }
|
1918 |
|
1919 |
|
1920 |
|
1921 | var radixToPower = fromNumber(pow_dbl(radix, 6), this.unsigned),
|
1922 | rem = this;
|
1923 | var result = '';
|
1924 | while (true) {
|
1925 | var remDiv = rem.div(radixToPower),
|
1926 | intval = rem.sub(remDiv.mul(radixToPower)).toInt() >>> 0,
|
1927 | digits = intval.toString(radix);
|
1928 | rem = remDiv;
|
1929 | if (rem.isZero())
|
1930 | return digits + result;
|
1931 | else {
|
1932 | while (digits.length < 6)
|
1933 | digits = '0' + digits;
|
1934 | result = '' + digits + result;
|
1935 | }
|
1936 | }
|
1937 | };
|
1938 |
|
1939 | |
1940 |
|
1941 |
|
1942 |
|
1943 | LongPrototype.getHighBits = function getHighBits() {
|
1944 | return this.high;
|
1945 | };
|
1946 |
|
1947 | |
1948 |
|
1949 |
|
1950 |
|
1951 | LongPrototype.getHighBitsUnsigned = function getHighBitsUnsigned() {
|
1952 | return this.high >>> 0;
|
1953 | };
|
1954 |
|
1955 | |
1956 |
|
1957 |
|
1958 |
|
1959 | LongPrototype.getLowBits = function getLowBits() {
|
1960 | return this.low;
|
1961 | };
|
1962 |
|
1963 | |
1964 |
|
1965 |
|
1966 |
|
1967 | LongPrototype.getLowBitsUnsigned = function getLowBitsUnsigned() {
|
1968 | return this.low >>> 0;
|
1969 | };
|
1970 |
|
1971 | |
1972 |
|
1973 |
|
1974 |
|
1975 | LongPrototype.getNumBitsAbs = function getNumBitsAbs() {
|
1976 | if (this.isNegative())
|
1977 | return this.eq(MIN_VALUE) ? 64 : this.neg().getNumBitsAbs();
|
1978 | var val = this.high != 0 ? this.high : this.low;
|
1979 | for (var bit = 31; bit > 0; bit--)
|
1980 | if ((val & (1 << bit)) != 0)
|
1981 | break;
|
1982 | return this.high != 0 ? bit + 33 : bit + 1;
|
1983 | };
|
1984 |
|
1985 | |
1986 |
|
1987 |
|
1988 |
|
1989 | LongPrototype.isZero = function isZero() {
|
1990 | return this.high === 0 && this.low === 0;
|
1991 | };
|
1992 |
|
1993 | |
1994 |
|
1995 |
|
1996 |
|
1997 | LongPrototype.isNegative = function isNegative() {
|
1998 | return !this.unsigned && this.high < 0;
|
1999 | };
|
2000 |
|
2001 | |
2002 |
|
2003 |
|
2004 |
|
2005 | LongPrototype.isPositive = function isPositive() {
|
2006 | return this.unsigned || this.high >= 0;
|
2007 | };
|
2008 |
|
2009 | |
2010 |
|
2011 |
|
2012 |
|
2013 | LongPrototype.isOdd = function isOdd() {
|
2014 | return (this.low & 1) === 1;
|
2015 | };
|
2016 |
|
2017 | |
2018 |
|
2019 |
|
2020 |
|
2021 | LongPrototype.isEven = function isEven() {
|
2022 | return (this.low & 1) === 0;
|
2023 | };
|
2024 |
|
2025 | |
2026 |
|
2027 |
|
2028 |
|
2029 |
|
2030 | LongPrototype.equals = function equals(other) {
|
2031 | if (!isLong(other))
|
2032 | other = fromValue(other);
|
2033 | if (this.unsigned !== other.unsigned && (this.high >>> 31) === 1 && (other.high >>> 31) === 1)
|
2034 | return false;
|
2035 | return this.high === other.high && this.low === other.low;
|
2036 | };
|
2037 |
|
2038 | |
2039 |
|
2040 |
|
2041 |
|
2042 |
|
2043 |
|
2044 | LongPrototype.eq = LongPrototype.equals;
|
2045 |
|
2046 | |
2047 |
|
2048 |
|
2049 |
|
2050 |
|
2051 | LongPrototype.notEquals = function notEquals(other) {
|
2052 | return !this.eq( other);
|
2053 | };
|
2054 |
|
2055 | |
2056 |
|
2057 |
|
2058 |
|
2059 |
|
2060 |
|
2061 | LongPrototype.neq = LongPrototype.notEquals;
|
2062 |
|
2063 | |
2064 |
|
2065 |
|
2066 |
|
2067 |
|
2068 | LongPrototype.lessThan = function lessThan(other) {
|
2069 | return this.comp( other) < 0;
|
2070 | };
|
2071 |
|
2072 | |
2073 |
|
2074 |
|
2075 |
|
2076 |
|
2077 |
|
2078 | LongPrototype.lt = LongPrototype.lessThan;
|
2079 |
|
2080 | |
2081 |
|
2082 |
|
2083 |
|
2084 |
|
2085 | LongPrototype.lessThanOrEqual = function lessThanOrEqual(other) {
|
2086 | return this.comp( other) <= 0;
|
2087 | };
|
2088 |
|
2089 | |
2090 |
|
2091 |
|
2092 |
|
2093 |
|
2094 |
|
2095 | LongPrototype.lte = LongPrototype.lessThanOrEqual;
|
2096 |
|
2097 | |
2098 |
|
2099 |
|
2100 |
|
2101 |
|
2102 | LongPrototype.greaterThan = function greaterThan(other) {
|
2103 | return this.comp( other) > 0;
|
2104 | };
|
2105 |
|
2106 | |
2107 |
|
2108 |
|
2109 |
|
2110 |
|
2111 |
|
2112 | LongPrototype.gt = LongPrototype.greaterThan;
|
2113 |
|
2114 | |
2115 |
|
2116 |
|
2117 |
|
2118 |
|
2119 | LongPrototype.greaterThanOrEqual = function greaterThanOrEqual(other) {
|
2120 | return this.comp( other) >= 0;
|
2121 | };
|
2122 |
|
2123 | |
2124 |
|
2125 |
|
2126 |
|
2127 |
|
2128 |
|
2129 | LongPrototype.gte = LongPrototype.greaterThanOrEqual;
|
2130 |
|
2131 | |
2132 |
|
2133 |
|
2134 |
|
2135 |
|
2136 |
|
2137 | LongPrototype.compare = function compare(other) {
|
2138 | if (!isLong(other))
|
2139 | other = fromValue(other);
|
2140 | if (this.eq(other))
|
2141 | return 0;
|
2142 | var thisNeg = this.isNegative(),
|
2143 | otherNeg = other.isNegative();
|
2144 | if (thisNeg && !otherNeg)
|
2145 | return -1;
|
2146 | if (!thisNeg && otherNeg)
|
2147 | return 1;
|
2148 |
|
2149 | if (!this.unsigned)
|
2150 | return this.sub(other).isNegative() ? -1 : 1;
|
2151 |
|
2152 | return (other.high >>> 0) > (this.high >>> 0) || (other.high === this.high && (other.low >>> 0) > (this.low >>> 0)) ? -1 : 1;
|
2153 | };
|
2154 |
|
2155 | |
2156 |
|
2157 |
|
2158 |
|
2159 |
|
2160 |
|
2161 |
|
2162 | LongPrototype.comp = LongPrototype.compare;
|
2163 |
|
2164 | |
2165 |
|
2166 |
|
2167 |
|
2168 | LongPrototype.negate = function negate() {
|
2169 | if (!this.unsigned && this.eq(MIN_VALUE))
|
2170 | return MIN_VALUE;
|
2171 | return this.not().add(ONE);
|
2172 | };
|
2173 |
|
2174 | |
2175 |
|
2176 |
|
2177 |
|
2178 |
|
2179 | LongPrototype.neg = LongPrototype.negate;
|
2180 |
|
2181 | |
2182 |
|
2183 |
|
2184 |
|
2185 |
|
2186 | LongPrototype.add = function add(addend) {
|
2187 | if (!isLong(addend))
|
2188 | addend = fromValue(addend);
|
2189 |
|
2190 |
|
2191 |
|
2192 | var a48 = this.high >>> 16;
|
2193 | var a32 = this.high & 0xFFFF;
|
2194 | var a16 = this.low >>> 16;
|
2195 | var a00 = this.low & 0xFFFF;
|
2196 |
|
2197 | var b48 = addend.high >>> 16;
|
2198 | var b32 = addend.high & 0xFFFF;
|
2199 | var b16 = addend.low >>> 16;
|
2200 | var b00 = addend.low & 0xFFFF;
|
2201 |
|
2202 | var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
|
2203 | c00 += a00 + b00;
|
2204 | c16 += c00 >>> 16;
|
2205 | c00 &= 0xFFFF;
|
2206 | c16 += a16 + b16;
|
2207 | c32 += c16 >>> 16;
|
2208 | c16 &= 0xFFFF;
|
2209 | c32 += a32 + b32;
|
2210 | c48 += c32 >>> 16;
|
2211 | c32 &= 0xFFFF;
|
2212 | c48 += a48 + b48;
|
2213 | c48 &= 0xFFFF;
|
2214 | return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
|
2215 | };
|
2216 |
|
2217 | |
2218 |
|
2219 |
|
2220 |
|
2221 |
|
2222 | LongPrototype.subtract = function subtract(subtrahend) {
|
2223 | if (!isLong(subtrahend))
|
2224 | subtrahend = fromValue(subtrahend);
|
2225 | return this.add(subtrahend.neg());
|
2226 | };
|
2227 |
|
2228 | |
2229 |
|
2230 |
|
2231 |
|
2232 |
|
2233 |
|
2234 | LongPrototype.sub = LongPrototype.subtract;
|
2235 |
|
2236 | |
2237 |
|
2238 |
|
2239 |
|
2240 |
|
2241 | LongPrototype.multiply = function multiply(multiplier) {
|
2242 | if (this.isZero())
|
2243 | return ZERO;
|
2244 | if (!isLong(multiplier))
|
2245 | multiplier = fromValue(multiplier);
|
2246 | if (multiplier.isZero())
|
2247 | return ZERO;
|
2248 | if (this.eq(MIN_VALUE))
|
2249 | return multiplier.isOdd() ? MIN_VALUE : ZERO;
|
2250 | if (multiplier.eq(MIN_VALUE))
|
2251 | return this.isOdd() ? MIN_VALUE : ZERO;
|
2252 |
|
2253 | if (this.isNegative()) {
|
2254 | if (multiplier.isNegative())
|
2255 | return this.neg().mul(multiplier.neg());
|
2256 | else
|
2257 | return this.neg().mul(multiplier).neg();
|
2258 | } else if (multiplier.isNegative())
|
2259 | return this.mul(multiplier.neg()).neg();
|
2260 |
|
2261 |
|
2262 | if (this.lt(TWO_PWR_24) && multiplier.lt(TWO_PWR_24))
|
2263 | return fromNumber(this.toNumber() * multiplier.toNumber(), this.unsigned);
|
2264 |
|
2265 |
|
2266 |
|
2267 |
|
2268 | var a48 = this.high >>> 16;
|
2269 | var a32 = this.high & 0xFFFF;
|
2270 | var a16 = this.low >>> 16;
|
2271 | var a00 = this.low & 0xFFFF;
|
2272 |
|
2273 | var b48 = multiplier.high >>> 16;
|
2274 | var b32 = multiplier.high & 0xFFFF;
|
2275 | var b16 = multiplier.low >>> 16;
|
2276 | var b00 = multiplier.low & 0xFFFF;
|
2277 |
|
2278 | var c48 = 0, c32 = 0, c16 = 0, c00 = 0;
|
2279 | c00 += a00 * b00;
|
2280 | c16 += c00 >>> 16;
|
2281 | c00 &= 0xFFFF;
|
2282 | c16 += a16 * b00;
|
2283 | c32 += c16 >>> 16;
|
2284 | c16 &= 0xFFFF;
|
2285 | c16 += a00 * b16;
|
2286 | c32 += c16 >>> 16;
|
2287 | c16 &= 0xFFFF;
|
2288 | c32 += a32 * b00;
|
2289 | c48 += c32 >>> 16;
|
2290 | c32 &= 0xFFFF;
|
2291 | c32 += a16 * b16;
|
2292 | c48 += c32 >>> 16;
|
2293 | c32 &= 0xFFFF;
|
2294 | c32 += a00 * b32;
|
2295 | c48 += c32 >>> 16;
|
2296 | c32 &= 0xFFFF;
|
2297 | c48 += a48 * b00 + a32 * b16 + a16 * b32 + a00 * b48;
|
2298 | c48 &= 0xFFFF;
|
2299 | return fromBits((c16 << 16) | c00, (c48 << 16) | c32, this.unsigned);
|
2300 | };
|
2301 |
|
2302 | |
2303 |
|
2304 |
|
2305 |
|
2306 |
|
2307 |
|
2308 | LongPrototype.mul = LongPrototype.multiply;
|
2309 |
|
2310 | |
2311 |
|
2312 |
|
2313 |
|
2314 |
|
2315 |
|
2316 | LongPrototype.divide = function divide(divisor) {
|
2317 | if (!isLong(divisor))
|
2318 | divisor = fromValue(divisor);
|
2319 | if (divisor.isZero())
|
2320 | throw Error('division by zero');
|
2321 | if (this.isZero())
|
2322 | return this.unsigned ? UZERO : ZERO;
|
2323 | var approx, rem, res;
|
2324 | if (!this.unsigned) {
|
2325 |
|
2326 |
|
2327 | if (this.eq(MIN_VALUE)) {
|
2328 | if (divisor.eq(ONE) || divisor.eq(NEG_ONE))
|
2329 | return MIN_VALUE;
|
2330 | else if (divisor.eq(MIN_VALUE))
|
2331 | return ONE;
|
2332 | else {
|
2333 |
|
2334 | var halfThis = this.shr(1);
|
2335 | approx = halfThis.div(divisor).shl(1);
|
2336 | if (approx.eq(ZERO)) {
|
2337 | return divisor.isNegative() ? ONE : NEG_ONE;
|
2338 | } else {
|
2339 | rem = this.sub(divisor.mul(approx));
|
2340 | res = approx.add(rem.div(divisor));
|
2341 | return res;
|
2342 | }
|
2343 | }
|
2344 | } else if (divisor.eq(MIN_VALUE))
|
2345 | return this.unsigned ? UZERO : ZERO;
|
2346 | if (this.isNegative()) {
|
2347 | if (divisor.isNegative())
|
2348 | return this.neg().div(divisor.neg());
|
2349 | return this.neg().div(divisor).neg();
|
2350 | } else if (divisor.isNegative())
|
2351 | return this.div(divisor.neg()).neg();
|
2352 | res = ZERO;
|
2353 | } else {
|
2354 |
|
2355 |
|
2356 | if (!divisor.unsigned)
|
2357 | divisor = divisor.toUnsigned();
|
2358 | if (divisor.gt(this))
|
2359 | return UZERO;
|
2360 | if (divisor.gt(this.shru(1)))
|
2361 | return UONE;
|
2362 | res = UZERO;
|
2363 | }
|
2364 |
|
2365 |
|
2366 |
|
2367 |
|
2368 |
|
2369 |
|
2370 | rem = this;
|
2371 | while (rem.gte(divisor)) {
|
2372 |
|
2373 |
|
2374 | approx = Math.max(1, Math.floor(rem.toNumber() / divisor.toNumber()));
|
2375 |
|
2376 |
|
2377 |
|
2378 | var log2 = Math.ceil(Math.log(approx) / Math.LN2),
|
2379 | delta = (log2 <= 48) ? 1 : pow_dbl(2, log2 - 48),
|
2380 |
|
2381 |
|
2382 |
|
2383 | approxRes = fromNumber(approx),
|
2384 | approxRem = approxRes.mul(divisor);
|
2385 | while (approxRem.isNegative() || approxRem.gt(rem)) {
|
2386 | approx -= delta;
|
2387 | approxRes = fromNumber(approx, this.unsigned);
|
2388 | approxRem = approxRes.mul(divisor);
|
2389 | }
|
2390 |
|
2391 |
|
2392 |
|
2393 | if (approxRes.isZero())
|
2394 | approxRes = ONE;
|
2395 |
|
2396 | res = res.add(approxRes);
|
2397 | rem = rem.sub(approxRem);
|
2398 | }
|
2399 | return res;
|
2400 | };
|
2401 |
|
2402 | |
2403 |
|
2404 |
|
2405 |
|
2406 |
|
2407 |
|
2408 | LongPrototype.div = LongPrototype.divide;
|
2409 |
|
2410 | |
2411 |
|
2412 |
|
2413 |
|
2414 |
|
2415 | LongPrototype.modulo = function modulo(divisor) {
|
2416 | if (!isLong(divisor))
|
2417 | divisor = fromValue(divisor);
|
2418 | return this.sub(this.div(divisor).mul(divisor));
|
2419 | };
|
2420 |
|
2421 | |
2422 |
|
2423 |
|
2424 |
|
2425 |
|
2426 |
|
2427 | LongPrototype.mod = LongPrototype.modulo;
|
2428 |
|
2429 | |
2430 |
|
2431 |
|
2432 |
|
2433 | LongPrototype.not = function not() {
|
2434 | return fromBits(~this.low, ~this.high, this.unsigned);
|
2435 | };
|
2436 |
|
2437 | |
2438 |
|
2439 |
|
2440 |
|
2441 |
|
2442 | LongPrototype.and = function and(other) {
|
2443 | if (!isLong(other))
|
2444 | other = fromValue(other);
|
2445 | return fromBits(this.low & other.low, this.high & other.high, this.unsigned);
|
2446 | };
|
2447 |
|
2448 | |
2449 |
|
2450 |
|
2451 |
|
2452 |
|
2453 | LongPrototype.or = function or(other) {
|
2454 | if (!isLong(other))
|
2455 | other = fromValue(other);
|
2456 | return fromBits(this.low | other.low, this.high | other.high, this.unsigned);
|
2457 | };
|
2458 |
|
2459 | |
2460 |
|
2461 |
|
2462 |
|
2463 |
|
2464 | LongPrototype.xor = function xor(other) {
|
2465 | if (!isLong(other))
|
2466 | other = fromValue(other);
|
2467 | return fromBits(this.low ^ other.low, this.high ^ other.high, this.unsigned);
|
2468 | };
|
2469 |
|
2470 | |
2471 |
|
2472 |
|
2473 |
|
2474 |
|
2475 | LongPrototype.shiftLeft = function shiftLeft(numBits) {
|
2476 | if (isLong(numBits))
|
2477 | numBits = numBits.toInt();
|
2478 | if ((numBits &= 63) === 0)
|
2479 | return this;
|
2480 | else if (numBits < 32)
|
2481 | return fromBits(this.low << numBits, (this.high << numBits) | (this.low >>> (32 - numBits)), this.unsigned);
|
2482 | else
|
2483 | return fromBits(0, this.low << (numBits - 32), this.unsigned);
|
2484 | };
|
2485 |
|
2486 | |
2487 |
|
2488 |
|
2489 |
|
2490 |
|
2491 |
|
2492 | LongPrototype.shl = LongPrototype.shiftLeft;
|
2493 |
|
2494 | |
2495 |
|
2496 |
|
2497 |
|
2498 |
|
2499 | LongPrototype.shiftRight = function shiftRight(numBits) {
|
2500 | if (isLong(numBits))
|
2501 | numBits = numBits.toInt();
|
2502 | if ((numBits &= 63) === 0)
|
2503 | return this;
|
2504 | else if (numBits < 32)
|
2505 | return fromBits((this.low >>> numBits) | (this.high << (32 - numBits)), this.high >> numBits, this.unsigned);
|
2506 | else
|
2507 | return fromBits(this.high >> (numBits - 32), this.high >= 0 ? 0 : -1, this.unsigned);
|
2508 | };
|
2509 |
|
2510 | |
2511 |
|
2512 |
|
2513 |
|
2514 |
|
2515 |
|
2516 | LongPrototype.shr = LongPrototype.shiftRight;
|
2517 |
|
2518 | |
2519 |
|
2520 |
|
2521 |
|
2522 |
|
2523 | LongPrototype.shiftRightUnsigned = function shiftRightUnsigned(numBits) {
|
2524 | if (isLong(numBits))
|
2525 | numBits = numBits.toInt();
|
2526 | numBits &= 63;
|
2527 | if (numBits === 0)
|
2528 | return this;
|
2529 | else {
|
2530 | var high = this.high;
|
2531 | if (numBits < 32) {
|
2532 | var low = this.low;
|
2533 | return fromBits((low >>> numBits) | (high << (32 - numBits)), high >>> numBits, this.unsigned);
|
2534 | } else if (numBits === 32)
|
2535 | return fromBits(high, 0, this.unsigned);
|
2536 | else
|
2537 | return fromBits(high >>> (numBits - 32), 0, this.unsigned);
|
2538 | }
|
2539 | };
|
2540 |
|
2541 | |
2542 |
|
2543 |
|
2544 |
|
2545 |
|
2546 |
|
2547 | LongPrototype.shru = LongPrototype.shiftRightUnsigned;
|
2548 |
|
2549 | |
2550 |
|
2551 |
|
2552 |
|
2553 | LongPrototype.toSigned = function toSigned() {
|
2554 | if (!this.unsigned)
|
2555 | return this;
|
2556 | return fromBits(this.low, this.high, false);
|
2557 | };
|
2558 |
|
2559 | |
2560 |
|
2561 |
|
2562 |
|
2563 | LongPrototype.toUnsigned = function toUnsigned() {
|
2564 | if (this.unsigned)
|
2565 | return this;
|
2566 | return fromBits(this.low, this.high, true);
|
2567 | };
|
2568 |
|
2569 | |
2570 |
|
2571 |
|
2572 |
|
2573 |
|
2574 | LongPrototype.toBytes = function(le) {
|
2575 | return le ? this.toBytesLE() : this.toBytesBE();
|
2576 | };
|
2577 |
|
2578 | |
2579 |
|
2580 |
|
2581 |
|
2582 | LongPrototype.toBytesLE = function() {
|
2583 | var hi = this.high,
|
2584 | lo = this.low;
|
2585 | return [
|
2586 | lo & 0xff,
|
2587 | (lo >>> 8) & 0xff,
|
2588 | (lo >>> 16) & 0xff,
|
2589 | (lo >>> 24) & 0xff,
|
2590 | hi & 0xff,
|
2591 | (hi >>> 8) & 0xff,
|
2592 | (hi >>> 16) & 0xff,
|
2593 | (hi >>> 24) & 0xff
|
2594 | ];
|
2595 | };
|
2596 |
|
2597 | |
2598 |
|
2599 |
|
2600 |
|
2601 | LongPrototype.toBytesBE = function() {
|
2602 | var hi = this.high,
|
2603 | lo = this.low;
|
2604 | return [
|
2605 | (hi >>> 24) & 0xff,
|
2606 | (hi >>> 16) & 0xff,
|
2607 | (hi >>> 8) & 0xff,
|
2608 | hi & 0xff,
|
2609 | (lo >>> 24) & 0xff,
|
2610 | (lo >>> 16) & 0xff,
|
2611 | (lo >>> 8) & 0xff,
|
2612 | lo & 0xff
|
2613 | ];
|
2614 | };
|
2615 |
|
2616 | return Long;
|
2617 | });
|
2618 | });
|
2619 |
|
2620 | var bytebuffer = createCommonjsModule(function (module) {
|
2621 | |
2622 |
|
2623 |
|
2624 |
|
2625 |
|
2626 |
|
2627 |
|
2628 |
|
2629 |
|
2630 |
|
2631 |
|
2632 |
|
2633 |
|
2634 |
|
2635 |
|
2636 |
|
2637 | |
2638 |
|
2639 |
|
2640 |
|
2641 |
|
2642 |
|
2643 | (function(global, factory) {
|
2644 |
|
2645 | if (typeof commonjsRequire === 'function' && 'object' === "object" && module && module["exports"])
|
2646 | module['exports'] = (function() {
|
2647 | var Long; try { Long = long_1; } catch (e) {}
|
2648 | return factory(Long);
|
2649 | })();
|
2650 | else
|
2651 | (global["dcodeIO"] = global["dcodeIO"] || {})["ByteBuffer"] = factory(global["dcodeIO"]["Long"]);
|
2652 |
|
2653 | })(commonjsGlobal, function(Long) {
|
2654 |
|
2655 | |
2656 |
|
2657 |
|
2658 |
|
2659 |
|
2660 |
|
2661 |
|
2662 |
|
2663 |
|
2664 |
|
2665 |
|
2666 |
|
2667 | var ByteBuffer = function(capacity, littleEndian, noAssert) {
|
2668 | if (typeof capacity === 'undefined')
|
2669 | capacity = ByteBuffer.DEFAULT_CAPACITY;
|
2670 | if (typeof littleEndian === 'undefined')
|
2671 | littleEndian = ByteBuffer.DEFAULT_ENDIAN;
|
2672 | if (typeof noAssert === 'undefined')
|
2673 | noAssert = ByteBuffer.DEFAULT_NOASSERT;
|
2674 | if (!noAssert) {
|
2675 | capacity = capacity | 0;
|
2676 | if (capacity < 0)
|
2677 | throw RangeError("Illegal capacity");
|
2678 | littleEndian = !!littleEndian;
|
2679 | noAssert = !!noAssert;
|
2680 | }
|
2681 |
|
2682 | |
2683 |
|
2684 |
|
2685 |
|
2686 |
|
2687 | this.buffer = capacity === 0 ? EMPTY_BUFFER : new ArrayBuffer(capacity);
|
2688 |
|
2689 | |
2690 |
|
2691 |
|
2692 |
|
2693 |
|
2694 | this.view = capacity === 0 ? null : new Uint8Array(this.buffer);
|
2695 |
|
2696 | |
2697 |
|
2698 |
|
2699 |
|
2700 |
|
2701 |
|
2702 |
|
2703 | this.offset = 0;
|
2704 |
|
2705 | |
2706 |
|
2707 |
|
2708 |
|
2709 |
|
2710 |
|
2711 |
|
2712 | this.markedOffset = -1;
|
2713 |
|
2714 | |
2715 |
|
2716 |
|
2717 |
|
2718 |
|
2719 |
|
2720 |
|
2721 | this.limit = capacity;
|
2722 |
|
2723 | |
2724 |
|
2725 |
|
2726 |
|
2727 |
|
2728 | this.littleEndian = littleEndian;
|
2729 |
|
2730 | |
2731 |
|
2732 |
|
2733 |
|
2734 |
|
2735 | this.noAssert = noAssert;
|
2736 | };
|
2737 |
|
2738 | |
2739 |
|
2740 |
|
2741 |
|
2742 |
|
2743 |
|
2744 | ByteBuffer.VERSION = "5.0.1";
|
2745 |
|
2746 | |
2747 |
|
2748 |
|
2749 |
|
2750 |
|
2751 |
|
2752 | ByteBuffer.LITTLE_ENDIAN = true;
|
2753 |
|
2754 | |
2755 |
|
2756 |
|
2757 |
|
2758 |
|
2759 |
|
2760 | ByteBuffer.BIG_ENDIAN = false;
|
2761 |
|
2762 | |
2763 |
|
2764 |
|
2765 |
|
2766 |
|
2767 | ByteBuffer.DEFAULT_CAPACITY = 16;
|
2768 |
|
2769 | |
2770 |
|
2771 |
|
2772 |
|
2773 |
|
2774 | ByteBuffer.DEFAULT_ENDIAN = ByteBuffer.BIG_ENDIAN;
|
2775 |
|
2776 | |
2777 |
|
2778 |
|
2779 |
|
2780 |
|
2781 | ByteBuffer.DEFAULT_NOASSERT = false;
|
2782 |
|
2783 | |
2784 |
|
2785 |
|
2786 |
|
2787 |
|
2788 |
|
2789 |
|
2790 |
|
2791 | ByteBuffer.Long = Long || null;
|
2792 |
|
2793 | |
2794 |
|
2795 |
|
2796 |
|
2797 | var ByteBufferPrototype = ByteBuffer.prototype;
|
2798 |
|
2799 | |
2800 |
|
2801 |
|
2802 |
|
2803 |
|
2804 |
|
2805 |
|
2806 | ByteBufferPrototype.__isByteBuffer__;
|
2807 |
|
2808 | Object.defineProperty(ByteBufferPrototype, "__isByteBuffer__", {
|
2809 | value: true,
|
2810 | enumerable: false,
|
2811 | configurable: false
|
2812 | });
|
2813 |
|
2814 |
|
2815 |
|
2816 | |
2817 |
|
2818 |
|
2819 |
|
2820 | var EMPTY_BUFFER = new ArrayBuffer(0);
|
2821 |
|
2822 | |
2823 |
|
2824 |
|
2825 |
|
2826 |
|
2827 | var stringFromCharCode = String.fromCharCode;
|
2828 |
|
2829 | |
2830 |
|
2831 |
|
2832 |
|
2833 |
|
2834 |
|
2835 |
|
2836 |
|
2837 | function stringSource(s) {
|
2838 | var i=0; return function() {
|
2839 | return i < s.length ? s.charCodeAt(i++) : null;
|
2840 | };
|
2841 | }
|
2842 |
|
2843 | |
2844 |
|
2845 |
|
2846 |
|
2847 |
|
2848 |
|
2849 | function stringDestination() {
|
2850 | var cs = [], ps = []; return function() {
|
2851 | if (arguments.length === 0)
|
2852 | return ps.join('')+stringFromCharCode.apply(String, cs);
|
2853 | if (cs.length + arguments.length > 1024)
|
2854 | ps.push(stringFromCharCode.apply(String, cs)),
|
2855 | cs.length = 0;
|
2856 | Array.prototype.push.apply(cs, arguments);
|
2857 | };
|
2858 | }
|
2859 |
|
2860 | |
2861 |
|
2862 |
|
2863 |
|
2864 |
|
2865 | ByteBuffer.accessor = function() {
|
2866 | return Uint8Array;
|
2867 | };
|
2868 | |
2869 |
|
2870 |
|
2871 |
|
2872 |
|
2873 |
|
2874 |
|
2875 |
|
2876 |
|
2877 |
|
2878 | ByteBuffer.allocate = function(capacity, littleEndian, noAssert) {
|
2879 | return new ByteBuffer(capacity, littleEndian, noAssert);
|
2880 | };
|
2881 |
|
2882 | |
2883 |
|
2884 |
|
2885 |
|
2886 |
|
2887 |
|
2888 |
|
2889 |
|
2890 |
|
2891 |
|
2892 |
|
2893 |
|
2894 | ByteBuffer.concat = function(buffers, encoding, littleEndian, noAssert) {
|
2895 | if (typeof encoding === 'boolean' || typeof encoding !== 'string') {
|
2896 | noAssert = littleEndian;
|
2897 | littleEndian = encoding;
|
2898 | encoding = undefined;
|
2899 | }
|
2900 | var capacity = 0;
|
2901 | for (var i=0, k=buffers.length, length; i<k; ++i) {
|
2902 | if (!ByteBuffer.isByteBuffer(buffers[i]))
|
2903 | buffers[i] = ByteBuffer.wrap(buffers[i], encoding);
|
2904 | length = buffers[i].limit - buffers[i].offset;
|
2905 | if (length > 0) capacity += length;
|
2906 | }
|
2907 | if (capacity === 0)
|
2908 | return new ByteBuffer(0, littleEndian, noAssert);
|
2909 | var bb = new ByteBuffer(capacity, littleEndian, noAssert),
|
2910 | bi;
|
2911 | i=0; while (i<k) {
|
2912 | bi = buffers[i++];
|
2913 | length = bi.limit - bi.offset;
|
2914 | if (length <= 0) continue;
|
2915 | bb.view.set(bi.view.subarray(bi.offset, bi.limit), bb.offset);
|
2916 | bb.offset += length;
|
2917 | }
|
2918 | bb.limit = bb.offset;
|
2919 | bb.offset = 0;
|
2920 | return bb;
|
2921 | };
|
2922 |
|
2923 | |
2924 |
|
2925 |
|
2926 |
|
2927 |
|
2928 |
|
2929 | ByteBuffer.isByteBuffer = function(bb) {
|
2930 | return (bb && bb["__isByteBuffer__"]) === true;
|
2931 | };
|
2932 | |
2933 |
|
2934 |
|
2935 |
|
2936 |
|
2937 | ByteBuffer.type = function() {
|
2938 | return ArrayBuffer;
|
2939 | };
|
2940 | |
2941 |
|
2942 |
|
2943 |
|
2944 |
|
2945 |
|
2946 |
|
2947 |
|
2948 |
|
2949 |
|
2950 |
|
2951 |
|
2952 |
|
2953 | ByteBuffer.wrap = function(buffer, encoding, littleEndian, noAssert) {
|
2954 | if (typeof encoding !== 'string') {
|
2955 | noAssert = littleEndian;
|
2956 | littleEndian = encoding;
|
2957 | encoding = undefined;
|
2958 | }
|
2959 | if (typeof buffer === 'string') {
|
2960 | if (typeof encoding === 'undefined')
|
2961 | encoding = "utf8";
|
2962 | switch (encoding) {
|
2963 | case "base64":
|
2964 | return ByteBuffer.fromBase64(buffer, littleEndian);
|
2965 | case "hex":
|
2966 | return ByteBuffer.fromHex(buffer, littleEndian);
|
2967 | case "binary":
|
2968 | return ByteBuffer.fromBinary(buffer, littleEndian);
|
2969 | case "utf8":
|
2970 | return ByteBuffer.fromUTF8(buffer, littleEndian);
|
2971 | case "debug":
|
2972 | return ByteBuffer.fromDebug(buffer, littleEndian);
|
2973 | default:
|
2974 | throw Error("Unsupported encoding: "+encoding);
|
2975 | }
|
2976 | }
|
2977 | if (buffer === null || typeof buffer !== 'object')
|
2978 | throw TypeError("Illegal buffer");
|
2979 | var bb;
|
2980 | if (ByteBuffer.isByteBuffer(buffer)) {
|
2981 | bb = ByteBufferPrototype.clone.call(buffer);
|
2982 | bb.markedOffset = -1;
|
2983 | return bb;
|
2984 | }
|
2985 | if (buffer instanceof Uint8Array) {
|
2986 | bb = new ByteBuffer(0, littleEndian, noAssert);
|
2987 | if (buffer.length > 0) {
|
2988 | bb.buffer = buffer.buffer;
|
2989 | bb.offset = buffer.byteOffset;
|
2990 | bb.limit = buffer.byteOffset + buffer.byteLength;
|
2991 | bb.view = new Uint8Array(buffer.buffer);
|
2992 | }
|
2993 | } else if (buffer instanceof ArrayBuffer) {
|
2994 | bb = new ByteBuffer(0, littleEndian, noAssert);
|
2995 | if (buffer.byteLength > 0) {
|
2996 | bb.buffer = buffer;
|
2997 | bb.offset = 0;
|
2998 | bb.limit = buffer.byteLength;
|
2999 | bb.view = buffer.byteLength > 0 ? new Uint8Array(buffer) : null;
|
3000 | }
|
3001 | } else if (Object.prototype.toString.call(buffer) === "[object Array]") {
|
3002 | bb = new ByteBuffer(buffer.length, littleEndian, noAssert);
|
3003 | bb.limit = buffer.length;
|
3004 | for (var i=0; i<buffer.length; ++i)
|
3005 | bb.view[i] = buffer[i];
|
3006 | } else
|
3007 | throw TypeError("Illegal buffer");
|
3008 | return bb;
|
3009 | };
|
3010 |
|
3011 | |
3012 |
|
3013 |
|
3014 |
|
3015 |
|
3016 |
|
3017 |
|
3018 | ByteBufferPrototype.writeBitSet = function(value, offset) {
|
3019 | var relative = typeof offset === 'undefined';
|
3020 | if (relative) offset = this.offset;
|
3021 | if (!this.noAssert) {
|
3022 | if (!(value instanceof Array))
|
3023 | throw TypeError("Illegal BitSet: Not an array");
|
3024 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3025 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3026 | offset >>>= 0;
|
3027 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
3028 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
3029 | }
|
3030 |
|
3031 | var start = offset,
|
3032 | bits = value.length,
|
3033 | bytes = (bits >> 3),
|
3034 | bit = 0,
|
3035 | k;
|
3036 |
|
3037 | offset += this.writeVarint32(bits,offset);
|
3038 |
|
3039 | while(bytes--) {
|
3040 | k = (!!value[bit++] & 1) |
|
3041 | ((!!value[bit++] & 1) << 1) |
|
3042 | ((!!value[bit++] & 1) << 2) |
|
3043 | ((!!value[bit++] & 1) << 3) |
|
3044 | ((!!value[bit++] & 1) << 4) |
|
3045 | ((!!value[bit++] & 1) << 5) |
|
3046 | ((!!value[bit++] & 1) << 6) |
|
3047 | ((!!value[bit++] & 1) << 7);
|
3048 | this.writeByte(k,offset++);
|
3049 | }
|
3050 |
|
3051 | if(bit < bits) {
|
3052 | var m = 0; k = 0;
|
3053 | while(bit < bits) k = k | ((!!value[bit++] & 1) << (m++));
|
3054 | this.writeByte(k,offset++);
|
3055 | }
|
3056 |
|
3057 | if (relative) {
|
3058 | this.offset = offset;
|
3059 | return this;
|
3060 | }
|
3061 | return offset - start;
|
3062 | };
|
3063 |
|
3064 | |
3065 |
|
3066 |
|
3067 |
|
3068 |
|
3069 |
|
3070 | ByteBufferPrototype.readBitSet = function(offset) {
|
3071 | var relative = typeof offset === 'undefined';
|
3072 | if (relative) offset = this.offset;
|
3073 |
|
3074 | var ret = this.readVarint32(offset),
|
3075 | bits = ret.value,
|
3076 | bytes = (bits >> 3),
|
3077 | bit = 0,
|
3078 | value = [],
|
3079 | k;
|
3080 |
|
3081 | offset += ret.length;
|
3082 |
|
3083 | while(bytes--) {
|
3084 | k = this.readByte(offset++);
|
3085 | value[bit++] = !!(k & 0x01);
|
3086 | value[bit++] = !!(k & 0x02);
|
3087 | value[bit++] = !!(k & 0x04);
|
3088 | value[bit++] = !!(k & 0x08);
|
3089 | value[bit++] = !!(k & 0x10);
|
3090 | value[bit++] = !!(k & 0x20);
|
3091 | value[bit++] = !!(k & 0x40);
|
3092 | value[bit++] = !!(k & 0x80);
|
3093 | }
|
3094 |
|
3095 | if(bit < bits) {
|
3096 | var m = 0;
|
3097 | k = this.readByte(offset++);
|
3098 | while(bit < bits) value[bit++] = !!((k >> (m++)) & 1);
|
3099 | }
|
3100 |
|
3101 | if (relative) {
|
3102 | this.offset = offset;
|
3103 | }
|
3104 | return value;
|
3105 | };
|
3106 | |
3107 |
|
3108 |
|
3109 |
|
3110 |
|
3111 |
|
3112 |
|
3113 | ByteBufferPrototype.readBytes = function(length, offset) {
|
3114 | var relative = typeof offset === 'undefined';
|
3115 | if (relative) offset = this.offset;
|
3116 | if (!this.noAssert) {
|
3117 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3118 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3119 | offset >>>= 0;
|
3120 | if (offset < 0 || offset + length > this.buffer.byteLength)
|
3121 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+length+") <= "+this.buffer.byteLength);
|
3122 | }
|
3123 | var slice = this.slice(offset, offset + length);
|
3124 | if (relative) this.offset += length;
|
3125 | return slice;
|
3126 | };
|
3127 |
|
3128 | |
3129 |
|
3130 |
|
3131 |
|
3132 |
|
3133 |
|
3134 |
|
3135 |
|
3136 |
|
3137 |
|
3138 |
|
3139 | ByteBufferPrototype.writeBytes = ByteBufferPrototype.append;
|
3140 |
|
3141 |
|
3142 |
|
3143 | |
3144 |
|
3145 |
|
3146 |
|
3147 |
|
3148 |
|
3149 |
|
3150 | ByteBufferPrototype.writeInt8 = function(value, offset) {
|
3151 | var relative = typeof offset === 'undefined';
|
3152 | if (relative) offset = this.offset;
|
3153 | if (!this.noAssert) {
|
3154 | if (typeof value !== 'number' || value % 1 !== 0)
|
3155 | throw TypeError("Illegal value: "+value+" (not an integer)");
|
3156 | value |= 0;
|
3157 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3158 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3159 | offset >>>= 0;
|
3160 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
3161 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
3162 | }
|
3163 | offset += 1;
|
3164 | var capacity0 = this.buffer.byteLength;
|
3165 | if (offset > capacity0)
|
3166 | this.resize((capacity0 *= 2) > offset ? capacity0 : offset);
|
3167 | offset -= 1;
|
3168 | this.view[offset] = value;
|
3169 | if (relative) this.offset += 1;
|
3170 | return this;
|
3171 | };
|
3172 |
|
3173 | |
3174 |
|
3175 |
|
3176 |
|
3177 |
|
3178 |
|
3179 |
|
3180 |
|
3181 | ByteBufferPrototype.writeByte = ByteBufferPrototype.writeInt8;
|
3182 |
|
3183 | |
3184 |
|
3185 |
|
3186 |
|
3187 |
|
3188 |
|
3189 | ByteBufferPrototype.readInt8 = function(offset) {
|
3190 | var relative = typeof offset === 'undefined';
|
3191 | if (relative) offset = this.offset;
|
3192 | if (!this.noAssert) {
|
3193 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3194 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3195 | offset >>>= 0;
|
3196 | if (offset < 0 || offset + 1 > this.buffer.byteLength)
|
3197 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength);
|
3198 | }
|
3199 | var value = this.view[offset];
|
3200 | if ((value & 0x80) === 0x80) value = -(0xFF - value + 1);
|
3201 | if (relative) this.offset += 1;
|
3202 | return value;
|
3203 | };
|
3204 |
|
3205 | |
3206 |
|
3207 |
|
3208 |
|
3209 |
|
3210 |
|
3211 |
|
3212 | ByteBufferPrototype.readByte = ByteBufferPrototype.readInt8;
|
3213 |
|
3214 | |
3215 |
|
3216 |
|
3217 |
|
3218 |
|
3219 |
|
3220 |
|
3221 | ByteBufferPrototype.writeUint8 = function(value, offset) {
|
3222 | var relative = typeof offset === 'undefined';
|
3223 | if (relative) offset = this.offset;
|
3224 | if (!this.noAssert) {
|
3225 | if (typeof value !== 'number' || value % 1 !== 0)
|
3226 | throw TypeError("Illegal value: "+value+" (not an integer)");
|
3227 | value >>>= 0;
|
3228 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3229 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3230 | offset >>>= 0;
|
3231 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
3232 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
3233 | }
|
3234 | offset += 1;
|
3235 | var capacity1 = this.buffer.byteLength;
|
3236 | if (offset > capacity1)
|
3237 | this.resize((capacity1 *= 2) > offset ? capacity1 : offset);
|
3238 | offset -= 1;
|
3239 | this.view[offset] = value;
|
3240 | if (relative) this.offset += 1;
|
3241 | return this;
|
3242 | };
|
3243 |
|
3244 | |
3245 |
|
3246 |
|
3247 |
|
3248 |
|
3249 |
|
3250 |
|
3251 |
|
3252 | ByteBufferPrototype.writeUInt8 = ByteBufferPrototype.writeUint8;
|
3253 |
|
3254 | |
3255 |
|
3256 |
|
3257 |
|
3258 |
|
3259 |
|
3260 | ByteBufferPrototype.readUint8 = function(offset) {
|
3261 | var relative = typeof offset === 'undefined';
|
3262 | if (relative) offset = this.offset;
|
3263 | if (!this.noAssert) {
|
3264 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3265 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3266 | offset >>>= 0;
|
3267 | if (offset < 0 || offset + 1 > this.buffer.byteLength)
|
3268 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength);
|
3269 | }
|
3270 | var value = this.view[offset];
|
3271 | if (relative) this.offset += 1;
|
3272 | return value;
|
3273 | };
|
3274 |
|
3275 | |
3276 |
|
3277 |
|
3278 |
|
3279 |
|
3280 |
|
3281 |
|
3282 | ByteBufferPrototype.readUInt8 = ByteBufferPrototype.readUint8;
|
3283 |
|
3284 |
|
3285 |
|
3286 | |
3287 |
|
3288 |
|
3289 |
|
3290 |
|
3291 |
|
3292 |
|
3293 |
|
3294 | ByteBufferPrototype.writeInt16 = function(value, offset) {
|
3295 | var relative = typeof offset === 'undefined';
|
3296 | if (relative) offset = this.offset;
|
3297 | if (!this.noAssert) {
|
3298 | if (typeof value !== 'number' || value % 1 !== 0)
|
3299 | throw TypeError("Illegal value: "+value+" (not an integer)");
|
3300 | value |= 0;
|
3301 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3302 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3303 | offset >>>= 0;
|
3304 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
3305 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
3306 | }
|
3307 | offset += 2;
|
3308 | var capacity2 = this.buffer.byteLength;
|
3309 | if (offset > capacity2)
|
3310 | this.resize((capacity2 *= 2) > offset ? capacity2 : offset);
|
3311 | offset -= 2;
|
3312 | if (this.littleEndian) {
|
3313 | this.view[offset+1] = (value & 0xFF00) >>> 8;
|
3314 | this.view[offset ] = value & 0x00FF;
|
3315 | } else {
|
3316 | this.view[offset] = (value & 0xFF00) >>> 8;
|
3317 | this.view[offset+1] = value & 0x00FF;
|
3318 | }
|
3319 | if (relative) this.offset += 2;
|
3320 | return this;
|
3321 | };
|
3322 |
|
3323 | |
3324 |
|
3325 |
|
3326 |
|
3327 |
|
3328 |
|
3329 |
|
3330 |
|
3331 |
|
3332 | ByteBufferPrototype.writeShort = ByteBufferPrototype.writeInt16;
|
3333 |
|
3334 | |
3335 |
|
3336 |
|
3337 |
|
3338 |
|
3339 |
|
3340 |
|
3341 |
|
3342 | ByteBufferPrototype.readInt16 = function(offset) {
|
3343 | var relative = typeof offset === 'undefined';
|
3344 | if (relative) offset = this.offset;
|
3345 | if (!this.noAssert) {
|
3346 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3347 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3348 | offset >>>= 0;
|
3349 | if (offset < 0 || offset + 2 > this.buffer.byteLength)
|
3350 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+2+") <= "+this.buffer.byteLength);
|
3351 | }
|
3352 | var value = 0;
|
3353 | if (this.littleEndian) {
|
3354 | value = this.view[offset ];
|
3355 | value |= this.view[offset+1] << 8;
|
3356 | } else {
|
3357 | value = this.view[offset ] << 8;
|
3358 | value |= this.view[offset+1];
|
3359 | }
|
3360 | if ((value & 0x8000) === 0x8000) value = -(0xFFFF - value + 1);
|
3361 | if (relative) this.offset += 2;
|
3362 | return value;
|
3363 | };
|
3364 |
|
3365 | |
3366 |
|
3367 |
|
3368 |
|
3369 |
|
3370 |
|
3371 |
|
3372 |
|
3373 |
|
3374 | ByteBufferPrototype.readShort = ByteBufferPrototype.readInt16;
|
3375 |
|
3376 | |
3377 |
|
3378 |
|
3379 |
|
3380 |
|
3381 |
|
3382 |
|
3383 |
|
3384 | ByteBufferPrototype.writeUint16 = function(value, offset) {
|
3385 | var relative = typeof offset === 'undefined';
|
3386 | if (relative) offset = this.offset;
|
3387 | if (!this.noAssert) {
|
3388 | if (typeof value !== 'number' || value % 1 !== 0)
|
3389 | throw TypeError("Illegal value: "+value+" (not an integer)");
|
3390 | value >>>= 0;
|
3391 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3392 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3393 | offset >>>= 0;
|
3394 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
3395 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
3396 | }
|
3397 | offset += 2;
|
3398 | var capacity3 = this.buffer.byteLength;
|
3399 | if (offset > capacity3)
|
3400 | this.resize((capacity3 *= 2) > offset ? capacity3 : offset);
|
3401 | offset -= 2;
|
3402 | if (this.littleEndian) {
|
3403 | this.view[offset+1] = (value & 0xFF00) >>> 8;
|
3404 | this.view[offset ] = value & 0x00FF;
|
3405 | } else {
|
3406 | this.view[offset] = (value & 0xFF00) >>> 8;
|
3407 | this.view[offset+1] = value & 0x00FF;
|
3408 | }
|
3409 | if (relative) this.offset += 2;
|
3410 | return this;
|
3411 | };
|
3412 |
|
3413 | |
3414 |
|
3415 |
|
3416 |
|
3417 |
|
3418 |
|
3419 |
|
3420 |
|
3421 |
|
3422 | ByteBufferPrototype.writeUInt16 = ByteBufferPrototype.writeUint16;
|
3423 |
|
3424 | |
3425 |
|
3426 |
|
3427 |
|
3428 |
|
3429 |
|
3430 |
|
3431 |
|
3432 | ByteBufferPrototype.readUint16 = function(offset) {
|
3433 | var relative = typeof offset === 'undefined';
|
3434 | if (relative) offset = this.offset;
|
3435 | if (!this.noAssert) {
|
3436 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3437 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3438 | offset >>>= 0;
|
3439 | if (offset < 0 || offset + 2 > this.buffer.byteLength)
|
3440 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+2+") <= "+this.buffer.byteLength);
|
3441 | }
|
3442 | var value = 0;
|
3443 | if (this.littleEndian) {
|
3444 | value = this.view[offset ];
|
3445 | value |= this.view[offset+1] << 8;
|
3446 | } else {
|
3447 | value = this.view[offset ] << 8;
|
3448 | value |= this.view[offset+1];
|
3449 | }
|
3450 | if (relative) this.offset += 2;
|
3451 | return value;
|
3452 | };
|
3453 |
|
3454 | |
3455 |
|
3456 |
|
3457 |
|
3458 |
|
3459 |
|
3460 |
|
3461 |
|
3462 |
|
3463 | ByteBufferPrototype.readUInt16 = ByteBufferPrototype.readUint16;
|
3464 |
|
3465 |
|
3466 |
|
3467 | |
3468 |
|
3469 |
|
3470 |
|
3471 |
|
3472 |
|
3473 | ByteBufferPrototype.writeInt32 = function(value, offset) {
|
3474 | var relative = typeof offset === 'undefined';
|
3475 | if (relative) offset = this.offset;
|
3476 | if (!this.noAssert) {
|
3477 | if (typeof value !== 'number' || value % 1 !== 0)
|
3478 | throw TypeError("Illegal value: "+value+" (not an integer)");
|
3479 | value |= 0;
|
3480 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3481 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3482 | offset >>>= 0;
|
3483 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
3484 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
3485 | }
|
3486 | offset += 4;
|
3487 | var capacity4 = this.buffer.byteLength;
|
3488 | if (offset > capacity4)
|
3489 | this.resize((capacity4 *= 2) > offset ? capacity4 : offset);
|
3490 | offset -= 4;
|
3491 | if (this.littleEndian) {
|
3492 | this.view[offset+3] = (value >>> 24) & 0xFF;
|
3493 | this.view[offset+2] = (value >>> 16) & 0xFF;
|
3494 | this.view[offset+1] = (value >>> 8) & 0xFF;
|
3495 | this.view[offset ] = value & 0xFF;
|
3496 | } else {
|
3497 | this.view[offset ] = (value >>> 24) & 0xFF;
|
3498 | this.view[offset+1] = (value >>> 16) & 0xFF;
|
3499 | this.view[offset+2] = (value >>> 8) & 0xFF;
|
3500 | this.view[offset+3] = value & 0xFF;
|
3501 | }
|
3502 | if (relative) this.offset += 4;
|
3503 | return this;
|
3504 | };
|
3505 |
|
3506 | |
3507 |
|
3508 |
|
3509 |
|
3510 |
|
3511 |
|
3512 | ByteBufferPrototype.writeInt = ByteBufferPrototype.writeInt32;
|
3513 |
|
3514 | |
3515 |
|
3516 |
|
3517 |
|
3518 |
|
3519 |
|
3520 | ByteBufferPrototype.readInt32 = function(offset) {
|
3521 | var relative = typeof offset === 'undefined';
|
3522 | if (relative) offset = this.offset;
|
3523 | if (!this.noAssert) {
|
3524 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3525 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3526 | offset >>>= 0;
|
3527 | if (offset < 0 || offset + 4 > this.buffer.byteLength)
|
3528 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+4+") <= "+this.buffer.byteLength);
|
3529 | }
|
3530 | var value = 0;
|
3531 | if (this.littleEndian) {
|
3532 | value = this.view[offset+2] << 16;
|
3533 | value |= this.view[offset+1] << 8;
|
3534 | value |= this.view[offset ];
|
3535 | value += this.view[offset+3] << 24 >>> 0;
|
3536 | } else {
|
3537 | value = this.view[offset+1] << 16;
|
3538 | value |= this.view[offset+2] << 8;
|
3539 | value |= this.view[offset+3];
|
3540 | value += this.view[offset ] << 24 >>> 0;
|
3541 | }
|
3542 | value |= 0;
|
3543 | if (relative) this.offset += 4;
|
3544 | return value;
|
3545 | };
|
3546 |
|
3547 | |
3548 |
|
3549 |
|
3550 |
|
3551 |
|
3552 |
|
3553 | ByteBufferPrototype.readInt = ByteBufferPrototype.readInt32;
|
3554 |
|
3555 | |
3556 |
|
3557 |
|
3558 |
|
3559 |
|
3560 |
|
3561 | ByteBufferPrototype.writeUint32 = function(value, offset) {
|
3562 | var relative = typeof offset === 'undefined';
|
3563 | if (relative) offset = this.offset;
|
3564 | if (!this.noAssert) {
|
3565 | if (typeof value !== 'number' || value % 1 !== 0)
|
3566 | throw TypeError("Illegal value: "+value+" (not an integer)");
|
3567 | value >>>= 0;
|
3568 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3569 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3570 | offset >>>= 0;
|
3571 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
3572 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
3573 | }
|
3574 | offset += 4;
|
3575 | var capacity5 = this.buffer.byteLength;
|
3576 | if (offset > capacity5)
|
3577 | this.resize((capacity5 *= 2) > offset ? capacity5 : offset);
|
3578 | offset -= 4;
|
3579 | if (this.littleEndian) {
|
3580 | this.view[offset+3] = (value >>> 24) & 0xFF;
|
3581 | this.view[offset+2] = (value >>> 16) & 0xFF;
|
3582 | this.view[offset+1] = (value >>> 8) & 0xFF;
|
3583 | this.view[offset ] = value & 0xFF;
|
3584 | } else {
|
3585 | this.view[offset ] = (value >>> 24) & 0xFF;
|
3586 | this.view[offset+1] = (value >>> 16) & 0xFF;
|
3587 | this.view[offset+2] = (value >>> 8) & 0xFF;
|
3588 | this.view[offset+3] = value & 0xFF;
|
3589 | }
|
3590 | if (relative) this.offset += 4;
|
3591 | return this;
|
3592 | };
|
3593 |
|
3594 | |
3595 |
|
3596 |
|
3597 |
|
3598 |
|
3599 |
|
3600 |
|
3601 | ByteBufferPrototype.writeUInt32 = ByteBufferPrototype.writeUint32;
|
3602 |
|
3603 | |
3604 |
|
3605 |
|
3606 |
|
3607 |
|
3608 |
|
3609 | ByteBufferPrototype.readUint32 = function(offset) {
|
3610 | var relative = typeof offset === 'undefined';
|
3611 | if (relative) offset = this.offset;
|
3612 | if (!this.noAssert) {
|
3613 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3614 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3615 | offset >>>= 0;
|
3616 | if (offset < 0 || offset + 4 > this.buffer.byteLength)
|
3617 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+4+") <= "+this.buffer.byteLength);
|
3618 | }
|
3619 | var value = 0;
|
3620 | if (this.littleEndian) {
|
3621 | value = this.view[offset+2] << 16;
|
3622 | value |= this.view[offset+1] << 8;
|
3623 | value |= this.view[offset ];
|
3624 | value += this.view[offset+3] << 24 >>> 0;
|
3625 | } else {
|
3626 | value = this.view[offset+1] << 16;
|
3627 | value |= this.view[offset+2] << 8;
|
3628 | value |= this.view[offset+3];
|
3629 | value += this.view[offset ] << 24 >>> 0;
|
3630 | }
|
3631 | if (relative) this.offset += 4;
|
3632 | return value;
|
3633 | };
|
3634 |
|
3635 | |
3636 |
|
3637 |
|
3638 |
|
3639 |
|
3640 |
|
3641 |
|
3642 | ByteBufferPrototype.readUInt32 = ByteBufferPrototype.readUint32;
|
3643 |
|
3644 |
|
3645 |
|
3646 | if (Long) {
|
3647 |
|
3648 | |
3649 |
|
3650 |
|
3651 |
|
3652 |
|
3653 |
|
3654 |
|
3655 | ByteBufferPrototype.writeInt64 = function(value, offset) {
|
3656 | var relative = typeof offset === 'undefined';
|
3657 | if (relative) offset = this.offset;
|
3658 | if (!this.noAssert) {
|
3659 | if (typeof value === 'number')
|
3660 | value = Long.fromNumber(value);
|
3661 | else if (typeof value === 'string')
|
3662 | value = Long.fromString(value);
|
3663 | else if (!(value && value instanceof Long))
|
3664 | throw TypeError("Illegal value: "+value+" (not an integer or Long)");
|
3665 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3666 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3667 | offset >>>= 0;
|
3668 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
3669 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
3670 | }
|
3671 | if (typeof value === 'number')
|
3672 | value = Long.fromNumber(value);
|
3673 | else if (typeof value === 'string')
|
3674 | value = Long.fromString(value);
|
3675 | offset += 8;
|
3676 | var capacity6 = this.buffer.byteLength;
|
3677 | if (offset > capacity6)
|
3678 | this.resize((capacity6 *= 2) > offset ? capacity6 : offset);
|
3679 | offset -= 8;
|
3680 | var lo = value.low,
|
3681 | hi = value.high;
|
3682 | if (this.littleEndian) {
|
3683 | this.view[offset+3] = (lo >>> 24) & 0xFF;
|
3684 | this.view[offset+2] = (lo >>> 16) & 0xFF;
|
3685 | this.view[offset+1] = (lo >>> 8) & 0xFF;
|
3686 | this.view[offset ] = lo & 0xFF;
|
3687 | offset += 4;
|
3688 | this.view[offset+3] = (hi >>> 24) & 0xFF;
|
3689 | this.view[offset+2] = (hi >>> 16) & 0xFF;
|
3690 | this.view[offset+1] = (hi >>> 8) & 0xFF;
|
3691 | this.view[offset ] = hi & 0xFF;
|
3692 | } else {
|
3693 | this.view[offset ] = (hi >>> 24) & 0xFF;
|
3694 | this.view[offset+1] = (hi >>> 16) & 0xFF;
|
3695 | this.view[offset+2] = (hi >>> 8) & 0xFF;
|
3696 | this.view[offset+3] = hi & 0xFF;
|
3697 | offset += 4;
|
3698 | this.view[offset ] = (lo >>> 24) & 0xFF;
|
3699 | this.view[offset+1] = (lo >>> 16) & 0xFF;
|
3700 | this.view[offset+2] = (lo >>> 8) & 0xFF;
|
3701 | this.view[offset+3] = lo & 0xFF;
|
3702 | }
|
3703 | if (relative) this.offset += 8;
|
3704 | return this;
|
3705 | };
|
3706 |
|
3707 | |
3708 |
|
3709 |
|
3710 |
|
3711 |
|
3712 |
|
3713 |
|
3714 | ByteBufferPrototype.writeLong = ByteBufferPrototype.writeInt64;
|
3715 |
|
3716 | |
3717 |
|
3718 |
|
3719 |
|
3720 |
|
3721 |
|
3722 | ByteBufferPrototype.readInt64 = function(offset) {
|
3723 | var relative = typeof offset === 'undefined';
|
3724 | if (relative) offset = this.offset;
|
3725 | if (!this.noAssert) {
|
3726 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3727 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3728 | offset >>>= 0;
|
3729 | if (offset < 0 || offset + 8 > this.buffer.byteLength)
|
3730 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+8+") <= "+this.buffer.byteLength);
|
3731 | }
|
3732 | var lo = 0,
|
3733 | hi = 0;
|
3734 | if (this.littleEndian) {
|
3735 | lo = this.view[offset+2] << 16;
|
3736 | lo |= this.view[offset+1] << 8;
|
3737 | lo |= this.view[offset ];
|
3738 | lo += this.view[offset+3] << 24 >>> 0;
|
3739 | offset += 4;
|
3740 | hi = this.view[offset+2] << 16;
|
3741 | hi |= this.view[offset+1] << 8;
|
3742 | hi |= this.view[offset ];
|
3743 | hi += this.view[offset+3] << 24 >>> 0;
|
3744 | } else {
|
3745 | hi = this.view[offset+1] << 16;
|
3746 | hi |= this.view[offset+2] << 8;
|
3747 | hi |= this.view[offset+3];
|
3748 | hi += this.view[offset ] << 24 >>> 0;
|
3749 | offset += 4;
|
3750 | lo = this.view[offset+1] << 16;
|
3751 | lo |= this.view[offset+2] << 8;
|
3752 | lo |= this.view[offset+3];
|
3753 | lo += this.view[offset ] << 24 >>> 0;
|
3754 | }
|
3755 | var value = new Long(lo, hi, false);
|
3756 | if (relative) this.offset += 8;
|
3757 | return value;
|
3758 | };
|
3759 |
|
3760 | |
3761 |
|
3762 |
|
3763 |
|
3764 |
|
3765 |
|
3766 | ByteBufferPrototype.readLong = ByteBufferPrototype.readInt64;
|
3767 |
|
3768 | |
3769 |
|
3770 |
|
3771 |
|
3772 |
|
3773 |
|
3774 |
|
3775 | ByteBufferPrototype.writeUint64 = function(value, offset) {
|
3776 | var relative = typeof offset === 'undefined';
|
3777 | if (relative) offset = this.offset;
|
3778 | if (!this.noAssert) {
|
3779 | if (typeof value === 'number')
|
3780 | value = Long.fromNumber(value);
|
3781 | else if (typeof value === 'string')
|
3782 | value = Long.fromString(value);
|
3783 | else if (!(value && value instanceof Long))
|
3784 | throw TypeError("Illegal value: "+value+" (not an integer or Long)");
|
3785 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3786 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3787 | offset >>>= 0;
|
3788 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
3789 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
3790 | }
|
3791 | if (typeof value === 'number')
|
3792 | value = Long.fromNumber(value);
|
3793 | else if (typeof value === 'string')
|
3794 | value = Long.fromString(value);
|
3795 | offset += 8;
|
3796 | var capacity7 = this.buffer.byteLength;
|
3797 | if (offset > capacity7)
|
3798 | this.resize((capacity7 *= 2) > offset ? capacity7 : offset);
|
3799 | offset -= 8;
|
3800 | var lo = value.low,
|
3801 | hi = value.high;
|
3802 | if (this.littleEndian) {
|
3803 | this.view[offset+3] = (lo >>> 24) & 0xFF;
|
3804 | this.view[offset+2] = (lo >>> 16) & 0xFF;
|
3805 | this.view[offset+1] = (lo >>> 8) & 0xFF;
|
3806 | this.view[offset ] = lo & 0xFF;
|
3807 | offset += 4;
|
3808 | this.view[offset+3] = (hi >>> 24) & 0xFF;
|
3809 | this.view[offset+2] = (hi >>> 16) & 0xFF;
|
3810 | this.view[offset+1] = (hi >>> 8) & 0xFF;
|
3811 | this.view[offset ] = hi & 0xFF;
|
3812 | } else {
|
3813 | this.view[offset ] = (hi >>> 24) & 0xFF;
|
3814 | this.view[offset+1] = (hi >>> 16) & 0xFF;
|
3815 | this.view[offset+2] = (hi >>> 8) & 0xFF;
|
3816 | this.view[offset+3] = hi & 0xFF;
|
3817 | offset += 4;
|
3818 | this.view[offset ] = (lo >>> 24) & 0xFF;
|
3819 | this.view[offset+1] = (lo >>> 16) & 0xFF;
|
3820 | this.view[offset+2] = (lo >>> 8) & 0xFF;
|
3821 | this.view[offset+3] = lo & 0xFF;
|
3822 | }
|
3823 | if (relative) this.offset += 8;
|
3824 | return this;
|
3825 | };
|
3826 |
|
3827 | |
3828 |
|
3829 |
|
3830 |
|
3831 |
|
3832 |
|
3833 |
|
3834 |
|
3835 | ByteBufferPrototype.writeUInt64 = ByteBufferPrototype.writeUint64;
|
3836 |
|
3837 | |
3838 |
|
3839 |
|
3840 |
|
3841 |
|
3842 |
|
3843 | ByteBufferPrototype.readUint64 = function(offset) {
|
3844 | var relative = typeof offset === 'undefined';
|
3845 | if (relative) offset = this.offset;
|
3846 | if (!this.noAssert) {
|
3847 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
3848 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
3849 | offset >>>= 0;
|
3850 | if (offset < 0 || offset + 8 > this.buffer.byteLength)
|
3851 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+8+") <= "+this.buffer.byteLength);
|
3852 | }
|
3853 | var lo = 0,
|
3854 | hi = 0;
|
3855 | if (this.littleEndian) {
|
3856 | lo = this.view[offset+2] << 16;
|
3857 | lo |= this.view[offset+1] << 8;
|
3858 | lo |= this.view[offset ];
|
3859 | lo += this.view[offset+3] << 24 >>> 0;
|
3860 | offset += 4;
|
3861 | hi = this.view[offset+2] << 16;
|
3862 | hi |= this.view[offset+1] << 8;
|
3863 | hi |= this.view[offset ];
|
3864 | hi += this.view[offset+3] << 24 >>> 0;
|
3865 | } else {
|
3866 | hi = this.view[offset+1] << 16;
|
3867 | hi |= this.view[offset+2] << 8;
|
3868 | hi |= this.view[offset+3];
|
3869 | hi += this.view[offset ] << 24 >>> 0;
|
3870 | offset += 4;
|
3871 | lo = this.view[offset+1] << 16;
|
3872 | lo |= this.view[offset+2] << 8;
|
3873 | lo |= this.view[offset+3];
|
3874 | lo += this.view[offset ] << 24 >>> 0;
|
3875 | }
|
3876 | var value = new Long(lo, hi, true);
|
3877 | if (relative) this.offset += 8;
|
3878 | return value;
|
3879 | };
|
3880 |
|
3881 | |
3882 |
|
3883 |
|
3884 |
|
3885 |
|
3886 |
|
3887 |
|
3888 | ByteBufferPrototype.readUInt64 = ByteBufferPrototype.readUint64;
|
3889 |
|
3890 | }
|
3891 |
|
3892 |
|
3893 |
|
3894 |
|
3895 | |
3896 |
|
3897 |
|
3898 |
|
3899 |
|
3900 |
|
3901 |
|
3902 |
|
3903 |
|
3904 |
|
3905 |
|
3906 |
|
3907 |
|
3908 |
|
3909 |
|
3910 |
|
3911 |
|
3912 |
|
3913 |
|
3914 |
|
3915 |
|
3916 |
|
3917 |
|
3918 |
|
3919 |
|
3920 |
|
3921 | |
3922 |
|
3923 |
|
3924 |
|
3925 |
|
3926 |
|
3927 |
|
3928 |
|
3929 |
|
3930 |
|
3931 | function ieee754_read(buffer, offset, isLE, mLen, nBytes) {
|
3932 | var e, m,
|
3933 | eLen = nBytes * 8 - mLen - 1,
|
3934 | eMax = (1 << eLen) - 1,
|
3935 | eBias = eMax >> 1,
|
3936 | nBits = -7,
|
3937 | i = isLE ? (nBytes - 1) : 0,
|
3938 | d = isLE ? -1 : 1,
|
3939 | s = buffer[offset + i];
|
3940 |
|
3941 | i += d;
|
3942 |
|
3943 | e = s & ((1 << (-nBits)) - 1);
|
3944 | s >>= (-nBits);
|
3945 | nBits += eLen;
|
3946 | for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
|
3947 |
|
3948 | m = e & ((1 << (-nBits)) - 1);
|
3949 | e >>= (-nBits);
|
3950 | nBits += mLen;
|
3951 | for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
|
3952 |
|
3953 | if (e === 0) {
|
3954 | e = 1 - eBias;
|
3955 | } else if (e === eMax) {
|
3956 | return m ? NaN : ((s ? -1 : 1) * Infinity);
|
3957 | } else {
|
3958 | m = m + Math.pow(2, mLen);
|
3959 | e = e - eBias;
|
3960 | }
|
3961 | return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
3962 | }
|
3963 |
|
3964 | |
3965 |
|
3966 |
|
3967 |
|
3968 |
|
3969 |
|
3970 |
|
3971 |
|
3972 |
|
3973 |
|
3974 | function ieee754_write(buffer, value, offset, isLE, mLen, nBytes) {
|
3975 | var e, m, c,
|
3976 | eLen = nBytes * 8 - mLen - 1,
|
3977 | eMax = (1 << eLen) - 1,
|
3978 | eBias = eMax >> 1,
|
3979 | rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0),
|
3980 | i = isLE ? 0 : (nBytes - 1),
|
3981 | d = isLE ? 1 : -1,
|
3982 | s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0;
|
3983 |
|
3984 | value = Math.abs(value);
|
3985 |
|
3986 | if (isNaN(value) || value === Infinity) {
|
3987 | m = isNaN(value) ? 1 : 0;
|
3988 | e = eMax;
|
3989 | } else {
|
3990 | e = Math.floor(Math.log(value) / Math.LN2);
|
3991 | if (value * (c = Math.pow(2, -e)) < 1) {
|
3992 | e--;
|
3993 | c *= 2;
|
3994 | }
|
3995 | if (e + eBias >= 1) {
|
3996 | value += rt / c;
|
3997 | } else {
|
3998 | value += rt * Math.pow(2, 1 - eBias);
|
3999 | }
|
4000 | if (value * c >= 2) {
|
4001 | e++;
|
4002 | c /= 2;
|
4003 | }
|
4004 |
|
4005 | if (e + eBias >= eMax) {
|
4006 | m = 0;
|
4007 | e = eMax;
|
4008 | } else if (e + eBias >= 1) {
|
4009 | m = (value * c - 1) * Math.pow(2, mLen);
|
4010 | e = e + eBias;
|
4011 | } else {
|
4012 | m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
|
4013 | e = 0;
|
4014 | }
|
4015 | }
|
4016 |
|
4017 | for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
|
4018 |
|
4019 | e = (e << mLen) | m;
|
4020 | eLen += mLen;
|
4021 | for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
|
4022 |
|
4023 | buffer[offset + i - d] |= s * 128;
|
4024 | }
|
4025 |
|
4026 | |
4027 |
|
4028 |
|
4029 |
|
4030 |
|
4031 |
|
4032 |
|
4033 | ByteBufferPrototype.writeFloat32 = function(value, offset) {
|
4034 | var relative = typeof offset === 'undefined';
|
4035 | if (relative) offset = this.offset;
|
4036 | if (!this.noAssert) {
|
4037 | if (typeof value !== 'number')
|
4038 | throw TypeError("Illegal value: "+value+" (not a number)");
|
4039 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4040 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4041 | offset >>>= 0;
|
4042 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
4043 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
4044 | }
|
4045 | offset += 4;
|
4046 | var capacity8 = this.buffer.byteLength;
|
4047 | if (offset > capacity8)
|
4048 | this.resize((capacity8 *= 2) > offset ? capacity8 : offset);
|
4049 | offset -= 4;
|
4050 | ieee754_write(this.view, value, offset, this.littleEndian, 23, 4);
|
4051 | if (relative) this.offset += 4;
|
4052 | return this;
|
4053 | };
|
4054 |
|
4055 | |
4056 |
|
4057 |
|
4058 |
|
4059 |
|
4060 |
|
4061 |
|
4062 |
|
4063 | ByteBufferPrototype.writeFloat = ByteBufferPrototype.writeFloat32;
|
4064 |
|
4065 | |
4066 |
|
4067 |
|
4068 |
|
4069 |
|
4070 |
|
4071 | ByteBufferPrototype.readFloat32 = function(offset) {
|
4072 | var relative = typeof offset === 'undefined';
|
4073 | if (relative) offset = this.offset;
|
4074 | if (!this.noAssert) {
|
4075 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4076 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4077 | offset >>>= 0;
|
4078 | if (offset < 0 || offset + 4 > this.buffer.byteLength)
|
4079 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+4+") <= "+this.buffer.byteLength);
|
4080 | }
|
4081 | var value = ieee754_read(this.view, offset, this.littleEndian, 23, 4);
|
4082 | if (relative) this.offset += 4;
|
4083 | return value;
|
4084 | };
|
4085 |
|
4086 | |
4087 |
|
4088 |
|
4089 |
|
4090 |
|
4091 |
|
4092 |
|
4093 | ByteBufferPrototype.readFloat = ByteBufferPrototype.readFloat32;
|
4094 |
|
4095 |
|
4096 |
|
4097 | |
4098 |
|
4099 |
|
4100 |
|
4101 |
|
4102 |
|
4103 |
|
4104 | ByteBufferPrototype.writeFloat64 = function(value, offset) {
|
4105 | var relative = typeof offset === 'undefined';
|
4106 | if (relative) offset = this.offset;
|
4107 | if (!this.noAssert) {
|
4108 | if (typeof value !== 'number')
|
4109 | throw TypeError("Illegal value: "+value+" (not a number)");
|
4110 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4111 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4112 | offset >>>= 0;
|
4113 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
4114 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
4115 | }
|
4116 | offset += 8;
|
4117 | var capacity9 = this.buffer.byteLength;
|
4118 | if (offset > capacity9)
|
4119 | this.resize((capacity9 *= 2) > offset ? capacity9 : offset);
|
4120 | offset -= 8;
|
4121 | ieee754_write(this.view, value, offset, this.littleEndian, 52, 8);
|
4122 | if (relative) this.offset += 8;
|
4123 | return this;
|
4124 | };
|
4125 |
|
4126 | |
4127 |
|
4128 |
|
4129 |
|
4130 |
|
4131 |
|
4132 |
|
4133 |
|
4134 | ByteBufferPrototype.writeDouble = ByteBufferPrototype.writeFloat64;
|
4135 |
|
4136 | |
4137 |
|
4138 |
|
4139 |
|
4140 |
|
4141 |
|
4142 | ByteBufferPrototype.readFloat64 = function(offset) {
|
4143 | var relative = typeof offset === 'undefined';
|
4144 | if (relative) offset = this.offset;
|
4145 | if (!this.noAssert) {
|
4146 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4147 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4148 | offset >>>= 0;
|
4149 | if (offset < 0 || offset + 8 > this.buffer.byteLength)
|
4150 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+8+") <= "+this.buffer.byteLength);
|
4151 | }
|
4152 | var value = ieee754_read(this.view, offset, this.littleEndian, 52, 8);
|
4153 | if (relative) this.offset += 8;
|
4154 | return value;
|
4155 | };
|
4156 |
|
4157 | |
4158 |
|
4159 |
|
4160 |
|
4161 |
|
4162 |
|
4163 |
|
4164 | ByteBufferPrototype.readDouble = ByteBufferPrototype.readFloat64;
|
4165 |
|
4166 |
|
4167 |
|
4168 |
|
4169 | |
4170 |
|
4171 |
|
4172 |
|
4173 |
|
4174 |
|
4175 | ByteBuffer.MAX_VARINT32_BYTES = 5;
|
4176 |
|
4177 | |
4178 |
|
4179 |
|
4180 |
|
4181 |
|
4182 |
|
4183 | ByteBuffer.calculateVarint32 = function(value) {
|
4184 |
|
4185 | value = value >>> 0;
|
4186 | if (value < 1 << 7 ) return 1;
|
4187 | else if (value < 1 << 14) return 2;
|
4188 | else if (value < 1 << 21) return 3;
|
4189 | else if (value < 1 << 28) return 4;
|
4190 | else return 5;
|
4191 | };
|
4192 |
|
4193 | |
4194 |
|
4195 |
|
4196 |
|
4197 |
|
4198 |
|
4199 | ByteBuffer.zigZagEncode32 = function(n) {
|
4200 | return (((n |= 0) << 1) ^ (n >> 31)) >>> 0;
|
4201 | };
|
4202 |
|
4203 | |
4204 |
|
4205 |
|
4206 |
|
4207 |
|
4208 |
|
4209 | ByteBuffer.zigZagDecode32 = function(n) {
|
4210 | return ((n >>> 1) ^ -(n & 1)) | 0;
|
4211 | };
|
4212 |
|
4213 | |
4214 |
|
4215 |
|
4216 |
|
4217 |
|
4218 |
|
4219 |
|
4220 |
|
4221 | ByteBufferPrototype.writeVarint32 = function(value, offset) {
|
4222 | var relative = typeof offset === 'undefined';
|
4223 | if (relative) offset = this.offset;
|
4224 | if (!this.noAssert) {
|
4225 | if (typeof value !== 'number' || value % 1 !== 0)
|
4226 | throw TypeError("Illegal value: "+value+" (not an integer)");
|
4227 | value |= 0;
|
4228 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4229 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4230 | offset >>>= 0;
|
4231 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
4232 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
4233 | }
|
4234 | var size = ByteBuffer.calculateVarint32(value),
|
4235 | b;
|
4236 | offset += size;
|
4237 | var capacity10 = this.buffer.byteLength;
|
4238 | if (offset > capacity10)
|
4239 | this.resize((capacity10 *= 2) > offset ? capacity10 : offset);
|
4240 | offset -= size;
|
4241 | value >>>= 0;
|
4242 | while (value >= 0x80) {
|
4243 | b = (value & 0x7f) | 0x80;
|
4244 | this.view[offset++] = b;
|
4245 | value >>>= 7;
|
4246 | }
|
4247 | this.view[offset++] = value;
|
4248 | if (relative) {
|
4249 | this.offset = offset;
|
4250 | return this;
|
4251 | }
|
4252 | return size;
|
4253 | };
|
4254 |
|
4255 | |
4256 |
|
4257 |
|
4258 |
|
4259 |
|
4260 |
|
4261 |
|
4262 |
|
4263 | ByteBufferPrototype.writeVarint32ZigZag = function(value, offset) {
|
4264 | return this.writeVarint32(ByteBuffer.zigZagEncode32(value), offset);
|
4265 | };
|
4266 |
|
4267 | |
4268 |
|
4269 |
|
4270 |
|
4271 |
|
4272 |
|
4273 |
|
4274 |
|
4275 |
|
4276 |
|
4277 | ByteBufferPrototype.readVarint32 = function(offset) {
|
4278 | var relative = typeof offset === 'undefined';
|
4279 | if (relative) offset = this.offset;
|
4280 | if (!this.noAssert) {
|
4281 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4282 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4283 | offset >>>= 0;
|
4284 | if (offset < 0 || offset + 1 > this.buffer.byteLength)
|
4285 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength);
|
4286 | }
|
4287 | var c = 0,
|
4288 | value = 0 >>> 0,
|
4289 | b;
|
4290 | do {
|
4291 | if (!this.noAssert && offset > this.limit) {
|
4292 | var err = Error("Truncated");
|
4293 | err['truncated'] = true;
|
4294 | throw err;
|
4295 | }
|
4296 | b = this.view[offset++];
|
4297 | if (c < 5)
|
4298 | value |= (b & 0x7f) << (7*c);
|
4299 | ++c;
|
4300 | } while ((b & 0x80) !== 0);
|
4301 | value |= 0;
|
4302 | if (relative) {
|
4303 | this.offset = offset;
|
4304 | return value;
|
4305 | }
|
4306 | return {
|
4307 | "value": value,
|
4308 | "length": c
|
4309 | };
|
4310 | };
|
4311 |
|
4312 | |
4313 |
|
4314 |
|
4315 |
|
4316 |
|
4317 |
|
4318 |
|
4319 |
|
4320 |
|
4321 | ByteBufferPrototype.readVarint32ZigZag = function(offset) {
|
4322 | var val = this.readVarint32(offset);
|
4323 | if (typeof val === 'object')
|
4324 | val["value"] = ByteBuffer.zigZagDecode32(val["value"]);
|
4325 | else
|
4326 | val = ByteBuffer.zigZagDecode32(val);
|
4327 | return val;
|
4328 | };
|
4329 |
|
4330 |
|
4331 |
|
4332 | if (Long) {
|
4333 |
|
4334 | |
4335 |
|
4336 |
|
4337 |
|
4338 |
|
4339 |
|
4340 | ByteBuffer.MAX_VARINT64_BYTES = 10;
|
4341 |
|
4342 | |
4343 |
|
4344 |
|
4345 |
|
4346 |
|
4347 |
|
4348 | ByteBuffer.calculateVarint64 = function(value) {
|
4349 | if (typeof value === 'number')
|
4350 | value = Long.fromNumber(value);
|
4351 | else if (typeof value === 'string')
|
4352 | value = Long.fromString(value);
|
4353 |
|
4354 | var part0 = value.toInt() >>> 0,
|
4355 | part1 = value.shiftRightUnsigned(28).toInt() >>> 0,
|
4356 | part2 = value.shiftRightUnsigned(56).toInt() >>> 0;
|
4357 | if (part2 == 0) {
|
4358 | if (part1 == 0) {
|
4359 | if (part0 < 1 << 14)
|
4360 | return part0 < 1 << 7 ? 1 : 2;
|
4361 | else
|
4362 | return part0 < 1 << 21 ? 3 : 4;
|
4363 | } else {
|
4364 | if (part1 < 1 << 14)
|
4365 | return part1 < 1 << 7 ? 5 : 6;
|
4366 | else
|
4367 | return part1 < 1 << 21 ? 7 : 8;
|
4368 | }
|
4369 | } else
|
4370 | return part2 < 1 << 7 ? 9 : 10;
|
4371 | };
|
4372 |
|
4373 | |
4374 |
|
4375 |
|
4376 |
|
4377 |
|
4378 |
|
4379 | ByteBuffer.zigZagEncode64 = function(value) {
|
4380 | if (typeof value === 'number')
|
4381 | value = Long.fromNumber(value, false);
|
4382 | else if (typeof value === 'string')
|
4383 | value = Long.fromString(value, false);
|
4384 | else if (value.unsigned !== false) value = value.toSigned();
|
4385 |
|
4386 | return value.shiftLeft(1).xor(value.shiftRight(63)).toUnsigned();
|
4387 | };
|
4388 |
|
4389 | |
4390 |
|
4391 |
|
4392 |
|
4393 |
|
4394 |
|
4395 | ByteBuffer.zigZagDecode64 = function(value) {
|
4396 | if (typeof value === 'number')
|
4397 | value = Long.fromNumber(value, false);
|
4398 | else if (typeof value === 'string')
|
4399 | value = Long.fromString(value, false);
|
4400 | else if (value.unsigned !== false) value = value.toSigned();
|
4401 |
|
4402 | return value.shiftRightUnsigned(1).xor(value.and(Long.ONE).toSigned().negate()).toSigned();
|
4403 | };
|
4404 |
|
4405 | |
4406 |
|
4407 |
|
4408 |
|
4409 |
|
4410 |
|
4411 |
|
4412 |
|
4413 | ByteBufferPrototype.writeVarint64 = function(value, offset) {
|
4414 | var relative = typeof offset === 'undefined';
|
4415 | if (relative) offset = this.offset;
|
4416 | if (!this.noAssert) {
|
4417 | if (typeof value === 'number')
|
4418 | value = Long.fromNumber(value);
|
4419 | else if (typeof value === 'string')
|
4420 | value = Long.fromString(value);
|
4421 | else if (!(value && value instanceof Long))
|
4422 | throw TypeError("Illegal value: "+value+" (not an integer or Long)");
|
4423 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4424 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4425 | offset >>>= 0;
|
4426 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
4427 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
4428 | }
|
4429 | if (typeof value === 'number')
|
4430 | value = Long.fromNumber(value, false);
|
4431 | else if (typeof value === 'string')
|
4432 | value = Long.fromString(value, false);
|
4433 | else if (value.unsigned !== false) value = value.toSigned();
|
4434 | var size = ByteBuffer.calculateVarint64(value),
|
4435 | part0 = value.toInt() >>> 0,
|
4436 | part1 = value.shiftRightUnsigned(28).toInt() >>> 0,
|
4437 | part2 = value.shiftRightUnsigned(56).toInt() >>> 0;
|
4438 | offset += size;
|
4439 | var capacity11 = this.buffer.byteLength;
|
4440 | if (offset > capacity11)
|
4441 | this.resize((capacity11 *= 2) > offset ? capacity11 : offset);
|
4442 | offset -= size;
|
4443 | switch (size) {
|
4444 | case 10: this.view[offset+9] = (part2 >>> 7) & 0x01;
|
4445 | case 9 : this.view[offset+8] = size !== 9 ? (part2 ) | 0x80 : (part2 ) & 0x7F;
|
4446 | case 8 : this.view[offset+7] = size !== 8 ? (part1 >>> 21) | 0x80 : (part1 >>> 21) & 0x7F;
|
4447 | case 7 : this.view[offset+6] = size !== 7 ? (part1 >>> 14) | 0x80 : (part1 >>> 14) & 0x7F;
|
4448 | case 6 : this.view[offset+5] = size !== 6 ? (part1 >>> 7) | 0x80 : (part1 >>> 7) & 0x7F;
|
4449 | case 5 : this.view[offset+4] = size !== 5 ? (part1 ) | 0x80 : (part1 ) & 0x7F;
|
4450 | case 4 : this.view[offset+3] = size !== 4 ? (part0 >>> 21) | 0x80 : (part0 >>> 21) & 0x7F;
|
4451 | case 3 : this.view[offset+2] = size !== 3 ? (part0 >>> 14) | 0x80 : (part0 >>> 14) & 0x7F;
|
4452 | case 2 : this.view[offset+1] = size !== 2 ? (part0 >>> 7) | 0x80 : (part0 >>> 7) & 0x7F;
|
4453 | case 1 : this.view[offset ] = size !== 1 ? (part0 ) | 0x80 : (part0 ) & 0x7F;
|
4454 | }
|
4455 | if (relative) {
|
4456 | this.offset += size;
|
4457 | return this;
|
4458 | } else {
|
4459 | return size;
|
4460 | }
|
4461 | };
|
4462 |
|
4463 | |
4464 |
|
4465 |
|
4466 |
|
4467 |
|
4468 |
|
4469 |
|
4470 |
|
4471 | ByteBufferPrototype.writeVarint64ZigZag = function(value, offset) {
|
4472 | return this.writeVarint64(ByteBuffer.zigZagEncode64(value), offset);
|
4473 | };
|
4474 |
|
4475 | |
4476 |
|
4477 |
|
4478 |
|
4479 |
|
4480 |
|
4481 |
|
4482 |
|
4483 |
|
4484 | ByteBufferPrototype.readVarint64 = function(offset) {
|
4485 | var relative = typeof offset === 'undefined';
|
4486 | if (relative) offset = this.offset;
|
4487 | if (!this.noAssert) {
|
4488 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4489 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4490 | offset >>>= 0;
|
4491 | if (offset < 0 || offset + 1 > this.buffer.byteLength)
|
4492 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength);
|
4493 | }
|
4494 |
|
4495 | var start = offset,
|
4496 | part0 = 0,
|
4497 | part1 = 0,
|
4498 | part2 = 0,
|
4499 | b = 0;
|
4500 | b = this.view[offset++]; part0 = (b & 0x7F) ; if ( b & 0x80 ) {
|
4501 | b = this.view[offset++]; part0 |= (b & 0x7F) << 7; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
4502 | b = this.view[offset++]; part0 |= (b & 0x7F) << 14; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
4503 | b = this.view[offset++]; part0 |= (b & 0x7F) << 21; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
4504 | b = this.view[offset++]; part1 = (b & 0x7F) ; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
4505 | b = this.view[offset++]; part1 |= (b & 0x7F) << 7; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
4506 | b = this.view[offset++]; part1 |= (b & 0x7F) << 14; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
4507 | b = this.view[offset++]; part1 |= (b & 0x7F) << 21; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
4508 | b = this.view[offset++]; part2 = (b & 0x7F) ; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
4509 | b = this.view[offset++]; part2 |= (b & 0x7F) << 7; if ((b & 0x80) || (this.noAssert && typeof b === 'undefined')) {
|
4510 | throw Error("Buffer overrun"); }}}}}}}}}}
|
4511 | var value = Long.fromBits(part0 | (part1 << 28), (part1 >>> 4) | (part2) << 24, false);
|
4512 | if (relative) {
|
4513 | this.offset = offset;
|
4514 | return value;
|
4515 | } else {
|
4516 | return {
|
4517 | 'value': value,
|
4518 | 'length': offset-start
|
4519 | };
|
4520 | }
|
4521 | };
|
4522 |
|
4523 | |
4524 |
|
4525 |
|
4526 |
|
4527 |
|
4528 |
|
4529 |
|
4530 |
|
4531 |
|
4532 | ByteBufferPrototype.readVarint64ZigZag = function(offset) {
|
4533 | var val = this.readVarint64(offset);
|
4534 | if (val && val['value'] instanceof Long)
|
4535 | val["value"] = ByteBuffer.zigZagDecode64(val["value"]);
|
4536 | else
|
4537 | val = ByteBuffer.zigZagDecode64(val);
|
4538 | return val;
|
4539 | };
|
4540 |
|
4541 | }
|
4542 |
|
4543 |
|
4544 |
|
4545 |
|
4546 | |
4547 |
|
4548 |
|
4549 |
|
4550 |
|
4551 |
|
4552 |
|
4553 |
|
4554 |
|
4555 | ByteBufferPrototype.writeCString = function(str, offset) {
|
4556 | var relative = typeof offset === 'undefined';
|
4557 | if (relative) offset = this.offset;
|
4558 | var i,
|
4559 | k = str.length;
|
4560 | if (!this.noAssert) {
|
4561 | if (typeof str !== 'string')
|
4562 | throw TypeError("Illegal str: Not a string");
|
4563 | for (i=0; i<k; ++i) {
|
4564 | if (str.charCodeAt(i) === 0)
|
4565 | throw RangeError("Illegal str: Contains NULL-characters");
|
4566 | }
|
4567 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4568 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4569 | offset >>>= 0;
|
4570 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
4571 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
4572 | }
|
4573 |
|
4574 | k = utfx.calculateUTF16asUTF8(stringSource(str))[1];
|
4575 | offset += k+1;
|
4576 | var capacity12 = this.buffer.byteLength;
|
4577 | if (offset > capacity12)
|
4578 | this.resize((capacity12 *= 2) > offset ? capacity12 : offset);
|
4579 | offset -= k+1;
|
4580 | utfx.encodeUTF16toUTF8(stringSource(str), function(b) {
|
4581 | this.view[offset++] = b;
|
4582 | }.bind(this));
|
4583 | this.view[offset++] = 0;
|
4584 | if (relative) {
|
4585 | this.offset = offset;
|
4586 | return this;
|
4587 | }
|
4588 | return k;
|
4589 | };
|
4590 |
|
4591 | |
4592 |
|
4593 |
|
4594 |
|
4595 |
|
4596 |
|
4597 |
|
4598 |
|
4599 |
|
4600 | ByteBufferPrototype.readCString = function(offset) {
|
4601 | var relative = typeof offset === 'undefined';
|
4602 | if (relative) offset = this.offset;
|
4603 | if (!this.noAssert) {
|
4604 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4605 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4606 | offset >>>= 0;
|
4607 | if (offset < 0 || offset + 1 > this.buffer.byteLength)
|
4608 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength);
|
4609 | }
|
4610 | var start = offset;
|
4611 |
|
4612 | var sd, b = -1;
|
4613 | utfx.decodeUTF8toUTF16(function() {
|
4614 | if (b === 0) return null;
|
4615 | if (offset >= this.limit)
|
4616 | throw RangeError("Illegal range: Truncated data, "+offset+" < "+this.limit);
|
4617 | b = this.view[offset++];
|
4618 | return b === 0 ? null : b;
|
4619 | }.bind(this), sd = stringDestination(), true);
|
4620 | if (relative) {
|
4621 | this.offset = offset;
|
4622 | return sd();
|
4623 | } else {
|
4624 | return {
|
4625 | "string": sd(),
|
4626 | "length": offset - start
|
4627 | };
|
4628 | }
|
4629 | };
|
4630 |
|
4631 |
|
4632 |
|
4633 | |
4634 |
|
4635 |
|
4636 |
|
4637 |
|
4638 |
|
4639 |
|
4640 |
|
4641 |
|
4642 | ByteBufferPrototype.writeIString = function(str, offset) {
|
4643 | var relative = typeof offset === 'undefined';
|
4644 | if (relative) offset = this.offset;
|
4645 | if (!this.noAssert) {
|
4646 | if (typeof str !== 'string')
|
4647 | throw TypeError("Illegal str: Not a string");
|
4648 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4649 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4650 | offset >>>= 0;
|
4651 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
4652 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
4653 | }
|
4654 | var start = offset,
|
4655 | k;
|
4656 | k = utfx.calculateUTF16asUTF8(stringSource(str), this.noAssert)[1];
|
4657 | offset += 4+k;
|
4658 | var capacity13 = this.buffer.byteLength;
|
4659 | if (offset > capacity13)
|
4660 | this.resize((capacity13 *= 2) > offset ? capacity13 : offset);
|
4661 | offset -= 4+k;
|
4662 | if (this.littleEndian) {
|
4663 | this.view[offset+3] = (k >>> 24) & 0xFF;
|
4664 | this.view[offset+2] = (k >>> 16) & 0xFF;
|
4665 | this.view[offset+1] = (k >>> 8) & 0xFF;
|
4666 | this.view[offset ] = k & 0xFF;
|
4667 | } else {
|
4668 | this.view[offset ] = (k >>> 24) & 0xFF;
|
4669 | this.view[offset+1] = (k >>> 16) & 0xFF;
|
4670 | this.view[offset+2] = (k >>> 8) & 0xFF;
|
4671 | this.view[offset+3] = k & 0xFF;
|
4672 | }
|
4673 | offset += 4;
|
4674 | utfx.encodeUTF16toUTF8(stringSource(str), function(b) {
|
4675 | this.view[offset++] = b;
|
4676 | }.bind(this));
|
4677 | if (offset !== start + 4 + k)
|
4678 | throw RangeError("Illegal range: Truncated data, "+offset+" == "+(offset+4+k));
|
4679 | if (relative) {
|
4680 | this.offset = offset;
|
4681 | return this;
|
4682 | }
|
4683 | return offset - start;
|
4684 | };
|
4685 |
|
4686 | |
4687 |
|
4688 |
|
4689 |
|
4690 |
|
4691 |
|
4692 |
|
4693 |
|
4694 |
|
4695 | ByteBufferPrototype.readIString = function(offset) {
|
4696 | var relative = typeof offset === 'undefined';
|
4697 | if (relative) offset = this.offset;
|
4698 | if (!this.noAssert) {
|
4699 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4700 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4701 | offset >>>= 0;
|
4702 | if (offset < 0 || offset + 4 > this.buffer.byteLength)
|
4703 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+4+") <= "+this.buffer.byteLength);
|
4704 | }
|
4705 | var start = offset;
|
4706 | var len = this.readUint32(offset);
|
4707 | var str = this.readUTF8String(len, ByteBuffer.METRICS_BYTES, offset += 4);
|
4708 | offset += str['length'];
|
4709 | if (relative) {
|
4710 | this.offset = offset;
|
4711 | return str['string'];
|
4712 | } else {
|
4713 | return {
|
4714 | 'string': str['string'],
|
4715 | 'length': offset - start
|
4716 | };
|
4717 | }
|
4718 | };
|
4719 |
|
4720 |
|
4721 |
|
4722 | |
4723 |
|
4724 |
|
4725 |
|
4726 |
|
4727 |
|
4728 | ByteBuffer.METRICS_CHARS = 'c';
|
4729 |
|
4730 | |
4731 |
|
4732 |
|
4733 |
|
4734 |
|
4735 |
|
4736 | ByteBuffer.METRICS_BYTES = 'b';
|
4737 |
|
4738 | |
4739 |
|
4740 |
|
4741 |
|
4742 |
|
4743 |
|
4744 |
|
4745 | ByteBufferPrototype.writeUTF8String = function(str, offset) {
|
4746 | var relative = typeof offset === 'undefined';
|
4747 | if (relative) offset = this.offset;
|
4748 | if (!this.noAssert) {
|
4749 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4750 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4751 | offset >>>= 0;
|
4752 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
4753 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
4754 | }
|
4755 | var k;
|
4756 | var start = offset;
|
4757 | k = utfx.calculateUTF16asUTF8(stringSource(str))[1];
|
4758 | offset += k;
|
4759 | var capacity14 = this.buffer.byteLength;
|
4760 | if (offset > capacity14)
|
4761 | this.resize((capacity14 *= 2) > offset ? capacity14 : offset);
|
4762 | offset -= k;
|
4763 | utfx.encodeUTF16toUTF8(stringSource(str), function(b) {
|
4764 | this.view[offset++] = b;
|
4765 | }.bind(this));
|
4766 | if (relative) {
|
4767 | this.offset = offset;
|
4768 | return this;
|
4769 | }
|
4770 | return offset - start;
|
4771 | };
|
4772 |
|
4773 | |
4774 |
|
4775 |
|
4776 |
|
4777 |
|
4778 |
|
4779 |
|
4780 |
|
4781 | ByteBufferPrototype.writeString = ByteBufferPrototype.writeUTF8String;
|
4782 |
|
4783 | |
4784 |
|
4785 |
|
4786 |
|
4787 |
|
4788 |
|
4789 |
|
4790 | ByteBuffer.calculateUTF8Chars = function(str) {
|
4791 | return utfx.calculateUTF16asUTF8(stringSource(str))[0];
|
4792 | };
|
4793 |
|
4794 | |
4795 |
|
4796 |
|
4797 |
|
4798 |
|
4799 |
|
4800 | ByteBuffer.calculateUTF8Bytes = function(str) {
|
4801 | return utfx.calculateUTF16asUTF8(stringSource(str))[1];
|
4802 | };
|
4803 |
|
4804 | |
4805 |
|
4806 |
|
4807 |
|
4808 |
|
4809 |
|
4810 |
|
4811 | ByteBuffer.calculateString = ByteBuffer.calculateUTF8Bytes;
|
4812 |
|
4813 | |
4814 |
|
4815 |
|
4816 |
|
4817 |
|
4818 |
|
4819 |
|
4820 |
|
4821 |
|
4822 |
|
4823 |
|
4824 | ByteBufferPrototype.readUTF8String = function(length, metrics, offset) {
|
4825 | if (typeof metrics === 'number') {
|
4826 | offset = metrics;
|
4827 | metrics = undefined;
|
4828 | }
|
4829 | var relative = typeof offset === 'undefined';
|
4830 | if (relative) offset = this.offset;
|
4831 | if (typeof metrics === 'undefined') metrics = ByteBuffer.METRICS_CHARS;
|
4832 | if (!this.noAssert) {
|
4833 | if (typeof length !== 'number' || length % 1 !== 0)
|
4834 | throw TypeError("Illegal length: "+length+" (not an integer)");
|
4835 | length |= 0;
|
4836 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4837 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4838 | offset >>>= 0;
|
4839 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
4840 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
4841 | }
|
4842 | var i = 0,
|
4843 | start = offset,
|
4844 | sd;
|
4845 | if (metrics === ByteBuffer.METRICS_CHARS) {
|
4846 | sd = stringDestination();
|
4847 | utfx.decodeUTF8(function() {
|
4848 | return i < length && offset < this.limit ? this.view[offset++] : null;
|
4849 | }.bind(this), function(cp) {
|
4850 | ++i; utfx.UTF8toUTF16(cp, sd);
|
4851 | });
|
4852 | if (i !== length)
|
4853 | throw RangeError("Illegal range: Truncated data, "+i+" == "+length);
|
4854 | if (relative) {
|
4855 | this.offset = offset;
|
4856 | return sd();
|
4857 | } else {
|
4858 | return {
|
4859 | "string": sd(),
|
4860 | "length": offset - start
|
4861 | };
|
4862 | }
|
4863 | } else if (metrics === ByteBuffer.METRICS_BYTES) {
|
4864 | if (!this.noAssert) {
|
4865 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4866 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4867 | offset >>>= 0;
|
4868 | if (offset < 0 || offset + length > this.buffer.byteLength)
|
4869 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+length+") <= "+this.buffer.byteLength);
|
4870 | }
|
4871 | var k = offset + length;
|
4872 | utfx.decodeUTF8toUTF16(function() {
|
4873 | return offset < k ? this.view[offset++] : null;
|
4874 | }.bind(this), sd = stringDestination(), this.noAssert);
|
4875 | if (offset !== k)
|
4876 | throw RangeError("Illegal range: Truncated data, "+offset+" == "+k);
|
4877 | if (relative) {
|
4878 | this.offset = offset;
|
4879 | return sd();
|
4880 | } else {
|
4881 | return {
|
4882 | 'string': sd(),
|
4883 | 'length': offset - start
|
4884 | };
|
4885 | }
|
4886 | } else
|
4887 | throw TypeError("Unsupported metrics: "+metrics);
|
4888 | };
|
4889 |
|
4890 | |
4891 |
|
4892 |
|
4893 |
|
4894 |
|
4895 |
|
4896 |
|
4897 |
|
4898 |
|
4899 |
|
4900 |
|
4901 |
|
4902 | ByteBufferPrototype.readString = ByteBufferPrototype.readUTF8String;
|
4903 |
|
4904 |
|
4905 |
|
4906 | |
4907 |
|
4908 |
|
4909 |
|
4910 |
|
4911 |
|
4912 |
|
4913 |
|
4914 |
|
4915 | ByteBufferPrototype.writeVString = function(str, offset) {
|
4916 | var relative = typeof offset === 'undefined';
|
4917 | if (relative) offset = this.offset;
|
4918 | if (!this.noAssert) {
|
4919 | if (typeof str !== 'string')
|
4920 | throw TypeError("Illegal str: Not a string");
|
4921 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4922 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4923 | offset >>>= 0;
|
4924 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
4925 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
4926 | }
|
4927 | var start = offset,
|
4928 | k, l;
|
4929 | k = utfx.calculateUTF16asUTF8(stringSource(str), this.noAssert)[1];
|
4930 | l = ByteBuffer.calculateVarint32(k);
|
4931 | offset += l+k;
|
4932 | var capacity15 = this.buffer.byteLength;
|
4933 | if (offset > capacity15)
|
4934 | this.resize((capacity15 *= 2) > offset ? capacity15 : offset);
|
4935 | offset -= l+k;
|
4936 | offset += this.writeVarint32(k, offset);
|
4937 | utfx.encodeUTF16toUTF8(stringSource(str), function(b) {
|
4938 | this.view[offset++] = b;
|
4939 | }.bind(this));
|
4940 | if (offset !== start+k+l)
|
4941 | throw RangeError("Illegal range: Truncated data, "+offset+" == "+(offset+k+l));
|
4942 | if (relative) {
|
4943 | this.offset = offset;
|
4944 | return this;
|
4945 | }
|
4946 | return offset - start;
|
4947 | };
|
4948 |
|
4949 | |
4950 |
|
4951 |
|
4952 |
|
4953 |
|
4954 |
|
4955 |
|
4956 |
|
4957 |
|
4958 | ByteBufferPrototype.readVString = function(offset) {
|
4959 | var relative = typeof offset === 'undefined';
|
4960 | if (relative) offset = this.offset;
|
4961 | if (!this.noAssert) {
|
4962 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
4963 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
4964 | offset >>>= 0;
|
4965 | if (offset < 0 || offset + 1 > this.buffer.byteLength)
|
4966 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+1+") <= "+this.buffer.byteLength);
|
4967 | }
|
4968 | var start = offset;
|
4969 | var len = this.readVarint32(offset);
|
4970 | var str = this.readUTF8String(len['value'], ByteBuffer.METRICS_BYTES, offset += len['length']);
|
4971 | offset += str['length'];
|
4972 | if (relative) {
|
4973 | this.offset = offset;
|
4974 | return str['string'];
|
4975 | } else {
|
4976 | return {
|
4977 | 'string': str['string'],
|
4978 | 'length': offset - start
|
4979 | };
|
4980 | }
|
4981 | };
|
4982 |
|
4983 |
|
4984 | |
4985 |
|
4986 |
|
4987 |
|
4988 |
|
4989 |
|
4990 |
|
4991 |
|
4992 |
|
4993 |
|
4994 |
|
4995 |
|
4996 |
|
4997 | ByteBufferPrototype.append = function(source, encoding, offset) {
|
4998 | if (typeof encoding === 'number' || typeof encoding !== 'string') {
|
4999 | offset = encoding;
|
5000 | encoding = undefined;
|
5001 | }
|
5002 | var relative = typeof offset === 'undefined';
|
5003 | if (relative) offset = this.offset;
|
5004 | if (!this.noAssert) {
|
5005 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
5006 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
5007 | offset >>>= 0;
|
5008 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
5009 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
5010 | }
|
5011 | if (!(source instanceof ByteBuffer))
|
5012 | source = ByteBuffer.wrap(source, encoding);
|
5013 | var length = source.limit - source.offset;
|
5014 | if (length <= 0) return this;
|
5015 | offset += length;
|
5016 | var capacity16 = this.buffer.byteLength;
|
5017 | if (offset > capacity16)
|
5018 | this.resize((capacity16 *= 2) > offset ? capacity16 : offset);
|
5019 | offset -= length;
|
5020 | this.view.set(source.view.subarray(source.offset, source.limit), offset);
|
5021 | source.offset += length;
|
5022 | if (relative) this.offset += length;
|
5023 | return this;
|
5024 | };
|
5025 |
|
5026 | |
5027 |
|
5028 |
|
5029 |
|
5030 |
|
5031 |
|
5032 |
|
5033 |
|
5034 |
|
5035 |
|
5036 | ByteBufferPrototype.appendTo = function(target, offset) {
|
5037 | target.append(this, offset);
|
5038 | return this;
|
5039 | };
|
5040 |
|
5041 | |
5042 |
|
5043 |
|
5044 |
|
5045 |
|
5046 |
|
5047 |
|
5048 | ByteBufferPrototype.assert = function(assert) {
|
5049 | this.noAssert = !assert;
|
5050 | return this;
|
5051 | };
|
5052 |
|
5053 | |
5054 |
|
5055 |
|
5056 |
|
5057 |
|
5058 | ByteBufferPrototype.capacity = function() {
|
5059 | return this.buffer.byteLength;
|
5060 | };
|
5061 | |
5062 |
|
5063 |
|
5064 |
|
5065 |
|
5066 |
|
5067 | ByteBufferPrototype.clear = function() {
|
5068 | this.offset = 0;
|
5069 | this.limit = this.buffer.byteLength;
|
5070 | this.markedOffset = -1;
|
5071 | return this;
|
5072 | };
|
5073 |
|
5074 | |
5075 |
|
5076 |
|
5077 |
|
5078 |
|
5079 |
|
5080 |
|
5081 | ByteBufferPrototype.clone = function(copy) {
|
5082 | var bb = new ByteBuffer(0, this.littleEndian, this.noAssert);
|
5083 | if (copy) {
|
5084 | bb.buffer = new ArrayBuffer(this.buffer.byteLength);
|
5085 | bb.view = new Uint8Array(bb.buffer);
|
5086 | } else {
|
5087 | bb.buffer = this.buffer;
|
5088 | bb.view = this.view;
|
5089 | }
|
5090 | bb.offset = this.offset;
|
5091 | bb.markedOffset = this.markedOffset;
|
5092 | bb.limit = this.limit;
|
5093 | return bb;
|
5094 | };
|
5095 |
|
5096 | |
5097 |
|
5098 |
|
5099 |
|
5100 |
|
5101 |
|
5102 |
|
5103 |
|
5104 |
|
5105 | ByteBufferPrototype.compact = function(begin, end) {
|
5106 | if (typeof begin === 'undefined') begin = this.offset;
|
5107 | if (typeof end === 'undefined') end = this.limit;
|
5108 | if (!this.noAssert) {
|
5109 | if (typeof begin !== 'number' || begin % 1 !== 0)
|
5110 | throw TypeError("Illegal begin: Not an integer");
|
5111 | begin >>>= 0;
|
5112 | if (typeof end !== 'number' || end % 1 !== 0)
|
5113 | throw TypeError("Illegal end: Not an integer");
|
5114 | end >>>= 0;
|
5115 | if (begin < 0 || begin > end || end > this.buffer.byteLength)
|
5116 | throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength);
|
5117 | }
|
5118 | if (begin === 0 && end === this.buffer.byteLength)
|
5119 | return this;
|
5120 | var len = end - begin;
|
5121 | if (len === 0) {
|
5122 | this.buffer = EMPTY_BUFFER;
|
5123 | this.view = null;
|
5124 | if (this.markedOffset >= 0) this.markedOffset -= begin;
|
5125 | this.offset = 0;
|
5126 | this.limit = 0;
|
5127 | return this;
|
5128 | }
|
5129 | var buffer = new ArrayBuffer(len);
|
5130 | var view = new Uint8Array(buffer);
|
5131 | view.set(this.view.subarray(begin, end));
|
5132 | this.buffer = buffer;
|
5133 | this.view = view;
|
5134 | if (this.markedOffset >= 0) this.markedOffset -= begin;
|
5135 | this.offset = 0;
|
5136 | this.limit = len;
|
5137 | return this;
|
5138 | };
|
5139 |
|
5140 | |
5141 |
|
5142 |
|
5143 |
|
5144 |
|
5145 |
|
5146 |
|
5147 |
|
5148 | ByteBufferPrototype.copy = function(begin, end) {
|
5149 | if (typeof begin === 'undefined') begin = this.offset;
|
5150 | if (typeof end === 'undefined') end = this.limit;
|
5151 | if (!this.noAssert) {
|
5152 | if (typeof begin !== 'number' || begin % 1 !== 0)
|
5153 | throw TypeError("Illegal begin: Not an integer");
|
5154 | begin >>>= 0;
|
5155 | if (typeof end !== 'number' || end % 1 !== 0)
|
5156 | throw TypeError("Illegal end: Not an integer");
|
5157 | end >>>= 0;
|
5158 | if (begin < 0 || begin > end || end > this.buffer.byteLength)
|
5159 | throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength);
|
5160 | }
|
5161 | if (begin === end)
|
5162 | return new ByteBuffer(0, this.littleEndian, this.noAssert);
|
5163 | var capacity = end - begin,
|
5164 | bb = new ByteBuffer(capacity, this.littleEndian, this.noAssert);
|
5165 | bb.offset = 0;
|
5166 | bb.limit = capacity;
|
5167 | if (bb.markedOffset >= 0) bb.markedOffset -= begin;
|
5168 | this.copyTo(bb, 0, begin, end);
|
5169 | return bb;
|
5170 | };
|
5171 |
|
5172 | |
5173 |
|
5174 |
|
5175 |
|
5176 |
|
5177 |
|
5178 |
|
5179 |
|
5180 |
|
5181 |
|
5182 |
|
5183 |
|
5184 | ByteBufferPrototype.copyTo = function(target, targetOffset, sourceOffset, sourceLimit) {
|
5185 | var relative,
|
5186 | targetRelative;
|
5187 | if (!this.noAssert) {
|
5188 | if (!ByteBuffer.isByteBuffer(target))
|
5189 | throw TypeError("Illegal target: Not a ByteBuffer");
|
5190 | }
|
5191 | targetOffset = (targetRelative = typeof targetOffset === 'undefined') ? target.offset : targetOffset | 0;
|
5192 | sourceOffset = (relative = typeof sourceOffset === 'undefined') ? this.offset : sourceOffset | 0;
|
5193 | sourceLimit = typeof sourceLimit === 'undefined' ? this.limit : sourceLimit | 0;
|
5194 |
|
5195 | if (targetOffset < 0 || targetOffset > target.buffer.byteLength)
|
5196 | throw RangeError("Illegal target range: 0 <= "+targetOffset+" <= "+target.buffer.byteLength);
|
5197 | if (sourceOffset < 0 || sourceLimit > this.buffer.byteLength)
|
5198 | throw RangeError("Illegal source range: 0 <= "+sourceOffset+" <= "+this.buffer.byteLength);
|
5199 |
|
5200 | var len = sourceLimit - sourceOffset;
|
5201 | if (len === 0)
|
5202 | return target;
|
5203 |
|
5204 | target.ensureCapacity(targetOffset + len);
|
5205 |
|
5206 | target.view.set(this.view.subarray(sourceOffset, sourceLimit), targetOffset);
|
5207 |
|
5208 | if (relative) this.offset += len;
|
5209 | if (targetRelative) target.offset += len;
|
5210 |
|
5211 | return this;
|
5212 | };
|
5213 |
|
5214 | |
5215 |
|
5216 |
|
5217 |
|
5218 |
|
5219 |
|
5220 |
|
5221 |
|
5222 | ByteBufferPrototype.ensureCapacity = function(capacity) {
|
5223 | var current = this.buffer.byteLength;
|
5224 | if (current < capacity)
|
5225 | return this.resize((current *= 2) > capacity ? current : capacity);
|
5226 | return this;
|
5227 | };
|
5228 |
|
5229 | |
5230 |
|
5231 |
|
5232 |
|
5233 |
|
5234 |
|
5235 |
|
5236 |
|
5237 |
|
5238 |
|
5239 |
|
5240 | ByteBufferPrototype.fill = function(value, begin, end) {
|
5241 | var relative = typeof begin === 'undefined';
|
5242 | if (relative) begin = this.offset;
|
5243 | if (typeof value === 'string' && value.length > 0)
|
5244 | value = value.charCodeAt(0);
|
5245 | if (typeof begin === 'undefined') begin = this.offset;
|
5246 | if (typeof end === 'undefined') end = this.limit;
|
5247 | if (!this.noAssert) {
|
5248 | if (typeof value !== 'number' || value % 1 !== 0)
|
5249 | throw TypeError("Illegal value: "+value+" (not an integer)");
|
5250 | value |= 0;
|
5251 | if (typeof begin !== 'number' || begin % 1 !== 0)
|
5252 | throw TypeError("Illegal begin: Not an integer");
|
5253 | begin >>>= 0;
|
5254 | if (typeof end !== 'number' || end % 1 !== 0)
|
5255 | throw TypeError("Illegal end: Not an integer");
|
5256 | end >>>= 0;
|
5257 | if (begin < 0 || begin > end || end > this.buffer.byteLength)
|
5258 | throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength);
|
5259 | }
|
5260 | if (begin >= end)
|
5261 | return this;
|
5262 | while (begin < end) this.view[begin++] = value;
|
5263 | if (relative) this.offset = begin;
|
5264 | return this;
|
5265 | };
|
5266 |
|
5267 | |
5268 |
|
5269 |
|
5270 |
|
5271 |
|
5272 |
|
5273 | ByteBufferPrototype.flip = function() {
|
5274 | this.limit = this.offset;
|
5275 | this.offset = 0;
|
5276 | return this;
|
5277 | };
|
5278 | |
5279 |
|
5280 |
|
5281 |
|
5282 |
|
5283 |
|
5284 |
|
5285 |
|
5286 |
|
5287 | ByteBufferPrototype.mark = function(offset) {
|
5288 | offset = typeof offset === 'undefined' ? this.offset : offset;
|
5289 | if (!this.noAssert) {
|
5290 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
5291 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
5292 | offset >>>= 0;
|
5293 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
5294 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
5295 | }
|
5296 | this.markedOffset = offset;
|
5297 | return this;
|
5298 | };
|
5299 | |
5300 |
|
5301 |
|
5302 |
|
5303 |
|
5304 |
|
5305 | ByteBufferPrototype.order = function(littleEndian) {
|
5306 | if (!this.noAssert) {
|
5307 | if (typeof littleEndian !== 'boolean')
|
5308 | throw TypeError("Illegal littleEndian: Not a boolean");
|
5309 | }
|
5310 | this.littleEndian = !!littleEndian;
|
5311 | return this;
|
5312 | };
|
5313 |
|
5314 | |
5315 |
|
5316 |
|
5317 |
|
5318 |
|
5319 |
|
5320 | ByteBufferPrototype.LE = function(littleEndian) {
|
5321 | this.littleEndian = typeof littleEndian !== 'undefined' ? !!littleEndian : true;
|
5322 | return this;
|
5323 | };
|
5324 |
|
5325 | |
5326 |
|
5327 |
|
5328 |
|
5329 |
|
5330 |
|
5331 | ByteBufferPrototype.BE = function(bigEndian) {
|
5332 | this.littleEndian = typeof bigEndian !== 'undefined' ? !bigEndian : false;
|
5333 | return this;
|
5334 | };
|
5335 | |
5336 |
|
5337 |
|
5338 |
|
5339 |
|
5340 |
|
5341 |
|
5342 |
|
5343 |
|
5344 |
|
5345 |
|
5346 |
|
5347 |
|
5348 |
|
5349 | ByteBufferPrototype.prepend = function(source, encoding, offset) {
|
5350 | if (typeof encoding === 'number' || typeof encoding !== 'string') {
|
5351 | offset = encoding;
|
5352 | encoding = undefined;
|
5353 | }
|
5354 | var relative = typeof offset === 'undefined';
|
5355 | if (relative) offset = this.offset;
|
5356 | if (!this.noAssert) {
|
5357 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
5358 | throw TypeError("Illegal offset: "+offset+" (not an integer)");
|
5359 | offset >>>= 0;
|
5360 | if (offset < 0 || offset + 0 > this.buffer.byteLength)
|
5361 | throw RangeError("Illegal offset: 0 <= "+offset+" (+"+0+") <= "+this.buffer.byteLength);
|
5362 | }
|
5363 | if (!(source instanceof ByteBuffer))
|
5364 | source = ByteBuffer.wrap(source, encoding);
|
5365 | var len = source.limit - source.offset;
|
5366 | if (len <= 0) return this;
|
5367 | var diff = len - offset;
|
5368 | if (diff > 0) {
|
5369 | var buffer = new ArrayBuffer(this.buffer.byteLength + diff);
|
5370 | var view = new Uint8Array(buffer);
|
5371 | view.set(this.view.subarray(offset, this.buffer.byteLength), len);
|
5372 | this.buffer = buffer;
|
5373 | this.view = view;
|
5374 | this.offset += diff;
|
5375 | if (this.markedOffset >= 0) this.markedOffset += diff;
|
5376 | this.limit += diff;
|
5377 | offset += diff;
|
5378 | } else {
|
5379 | var arrayView = new Uint8Array(this.buffer);
|
5380 | }
|
5381 | this.view.set(source.view.subarray(source.offset, source.limit), offset - len);
|
5382 |
|
5383 | source.offset = source.limit;
|
5384 | if (relative)
|
5385 | this.offset -= len;
|
5386 | return this;
|
5387 | };
|
5388 |
|
5389 | |
5390 |
|
5391 |
|
5392 |
|
5393 |
|
5394 |
|
5395 |
|
5396 |
|
5397 |
|
5398 |
|
5399 |
|
5400 | ByteBufferPrototype.prependTo = function(target, offset) {
|
5401 | target.prepend(this, offset);
|
5402 | return this;
|
5403 | };
|
5404 | |
5405 |
|
5406 |
|
5407 |
|
5408 |
|
5409 | ByteBufferPrototype.printDebug = function(out) {
|
5410 | if (typeof out !== 'function') out = console.log.bind(console);
|
5411 | out(
|
5412 | this.toString()+"\n"+
|
5413 | "-------------------------------------------------------------------\n"+
|
5414 | this.toDebug( true)
|
5415 | );
|
5416 | };
|
5417 |
|
5418 | |
5419 |
|
5420 |
|
5421 |
|
5422 |
|
5423 |
|
5424 | ByteBufferPrototype.remaining = function() {
|
5425 | return this.limit - this.offset;
|
5426 | };
|
5427 | |
5428 |
|
5429 |
|
5430 |
|
5431 |
|
5432 |
|
5433 |
|
5434 |
|
5435 | ByteBufferPrototype.reset = function() {
|
5436 | if (this.markedOffset >= 0) {
|
5437 | this.offset = this.markedOffset;
|
5438 | this.markedOffset = -1;
|
5439 | } else {
|
5440 | this.offset = 0;
|
5441 | }
|
5442 | return this;
|
5443 | };
|
5444 | |
5445 |
|
5446 |
|
5447 |
|
5448 |
|
5449 |
|
5450 |
|
5451 |
|
5452 |
|
5453 | ByteBufferPrototype.resize = function(capacity) {
|
5454 | if (!this.noAssert) {
|
5455 | if (typeof capacity !== 'number' || capacity % 1 !== 0)
|
5456 | throw TypeError("Illegal capacity: "+capacity+" (not an integer)");
|
5457 | capacity |= 0;
|
5458 | if (capacity < 0)
|
5459 | throw RangeError("Illegal capacity: 0 <= "+capacity);
|
5460 | }
|
5461 | if (this.buffer.byteLength < capacity) {
|
5462 | var buffer = new ArrayBuffer(capacity);
|
5463 | var view = new Uint8Array(buffer);
|
5464 | view.set(this.view);
|
5465 | this.buffer = buffer;
|
5466 | this.view = view;
|
5467 | }
|
5468 | return this;
|
5469 | };
|
5470 | |
5471 |
|
5472 |
|
5473 |
|
5474 |
|
5475 |
|
5476 |
|
5477 | ByteBufferPrototype.reverse = function(begin, end) {
|
5478 | if (typeof begin === 'undefined') begin = this.offset;
|
5479 | if (typeof end === 'undefined') end = this.limit;
|
5480 | if (!this.noAssert) {
|
5481 | if (typeof begin !== 'number' || begin % 1 !== 0)
|
5482 | throw TypeError("Illegal begin: Not an integer");
|
5483 | begin >>>= 0;
|
5484 | if (typeof end !== 'number' || end % 1 !== 0)
|
5485 | throw TypeError("Illegal end: Not an integer");
|
5486 | end >>>= 0;
|
5487 | if (begin < 0 || begin > end || end > this.buffer.byteLength)
|
5488 | throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength);
|
5489 | }
|
5490 | if (begin === end)
|
5491 | return this;
|
5492 | Array.prototype.reverse.call(this.view.subarray(begin, end));
|
5493 | return this;
|
5494 | };
|
5495 | |
5496 |
|
5497 |
|
5498 |
|
5499 |
|
5500 |
|
5501 | ByteBufferPrototype.skip = function(length) {
|
5502 | if (!this.noAssert) {
|
5503 | if (typeof length !== 'number' || length % 1 !== 0)
|
5504 | throw TypeError("Illegal length: "+length+" (not an integer)");
|
5505 | length |= 0;
|
5506 | }
|
5507 | var offset = this.offset + length;
|
5508 | if (!this.noAssert) {
|
5509 | if (offset < 0 || offset > this.buffer.byteLength)
|
5510 | throw RangeError("Illegal length: 0 <= "+this.offset+" + "+length+" <= "+this.buffer.byteLength);
|
5511 | }
|
5512 | this.offset = offset;
|
5513 | return this;
|
5514 | };
|
5515 |
|
5516 | |
5517 |
|
5518 |
|
5519 |
|
5520 |
|
5521 |
|
5522 |
|
5523 | ByteBufferPrototype.slice = function(begin, end) {
|
5524 | if (typeof begin === 'undefined') begin = this.offset;
|
5525 | if (typeof end === 'undefined') end = this.limit;
|
5526 | if (!this.noAssert) {
|
5527 | if (typeof begin !== 'number' || begin % 1 !== 0)
|
5528 | throw TypeError("Illegal begin: Not an integer");
|
5529 | begin >>>= 0;
|
5530 | if (typeof end !== 'number' || end % 1 !== 0)
|
5531 | throw TypeError("Illegal end: Not an integer");
|
5532 | end >>>= 0;
|
5533 | if (begin < 0 || begin > end || end > this.buffer.byteLength)
|
5534 | throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength);
|
5535 | }
|
5536 | var bb = this.clone();
|
5537 | bb.offset = begin;
|
5538 | bb.limit = end;
|
5539 | return bb;
|
5540 | };
|
5541 | |
5542 |
|
5543 |
|
5544 |
|
5545 |
|
5546 |
|
5547 |
|
5548 |
|
5549 | ByteBufferPrototype.toBuffer = function(forceCopy) {
|
5550 | var offset = this.offset,
|
5551 | limit = this.limit;
|
5552 | if (!this.noAssert) {
|
5553 | if (typeof offset !== 'number' || offset % 1 !== 0)
|
5554 | throw TypeError("Illegal offset: Not an integer");
|
5555 | offset >>>= 0;
|
5556 | if (typeof limit !== 'number' || limit % 1 !== 0)
|
5557 | throw TypeError("Illegal limit: Not an integer");
|
5558 | limit >>>= 0;
|
5559 | if (offset < 0 || offset > limit || limit > this.buffer.byteLength)
|
5560 | throw RangeError("Illegal range: 0 <= "+offset+" <= "+limit+" <= "+this.buffer.byteLength);
|
5561 | }
|
5562 |
|
5563 |
|
5564 | if (!forceCopy && offset === 0 && limit === this.buffer.byteLength)
|
5565 | return this.buffer;
|
5566 | if (offset === limit)
|
5567 | return EMPTY_BUFFER;
|
5568 | var buffer = new ArrayBuffer(limit - offset);
|
5569 | new Uint8Array(buffer).set(new Uint8Array(this.buffer).subarray(offset, limit), 0);
|
5570 | return buffer;
|
5571 | };
|
5572 |
|
5573 | |
5574 |
|
5575 |
|
5576 |
|
5577 |
|
5578 |
|
5579 |
|
5580 |
|
5581 |
|
5582 | ByteBufferPrototype.toArrayBuffer = ByteBufferPrototype.toBuffer;
|
5583 |
|
5584 | |
5585 |
|
5586 |
|
5587 |
|
5588 |
|
5589 |
|
5590 |
|
5591 |
|
5592 |
|
5593 |
|
5594 |
|
5595 | ByteBufferPrototype.toString = function(encoding, begin, end) {
|
5596 | if (typeof encoding === 'undefined')
|
5597 | return "ByteBufferAB(offset="+this.offset+",markedOffset="+this.markedOffset+",limit="+this.limit+",capacity="+this.capacity()+")";
|
5598 | if (typeof encoding === 'number')
|
5599 | encoding = "utf8",
|
5600 | begin = encoding,
|
5601 | end = begin;
|
5602 | switch (encoding) {
|
5603 | case "utf8":
|
5604 | return this.toUTF8(begin, end);
|
5605 | case "base64":
|
5606 | return this.toBase64(begin, end);
|
5607 | case "hex":
|
5608 | return this.toHex(begin, end);
|
5609 | case "binary":
|
5610 | return this.toBinary(begin, end);
|
5611 | case "debug":
|
5612 | return this.toDebug();
|
5613 | case "columns":
|
5614 | return this.toColumns();
|
5615 | default:
|
5616 | throw Error("Unsupported encoding: "+encoding);
|
5617 | }
|
5618 | };
|
5619 |
|
5620 |
|
5621 |
|
5622 | |
5623 |
|
5624 |
|
5625 |
|
5626 |
|
5627 | var lxiv = function() {
|
5628 |
|
5629 | |
5630 |
|
5631 |
|
5632 |
|
5633 |
|
5634 | var lxiv = {};
|
5635 |
|
5636 | |
5637 |
|
5638 |
|
5639 |
|
5640 |
|
5641 | var aout = [
|
5642 | 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
|
5643 | 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102,
|
5644 | 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118,
|
5645 | 119, 120, 121, 122, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 43, 47
|
5646 | ];
|
5647 |
|
5648 | |
5649 |
|
5650 |
|
5651 |
|
5652 |
|
5653 | var ain = [];
|
5654 | for (var i=0, k=aout.length; i<k; ++i)
|
5655 | ain[aout[i]] = i;
|
5656 |
|
5657 | |
5658 |
|
5659 |
|
5660 |
|
5661 |
|
5662 |
|
5663 |
|
5664 | lxiv.encode = function(src, dst) {
|
5665 | var b, t;
|
5666 | while ((b = src()) !== null) {
|
5667 | dst(aout[(b>>2)&0x3f]);
|
5668 | t = (b&0x3)<<4;
|
5669 | if ((b = src()) !== null) {
|
5670 | t |= (b>>4)&0xf;
|
5671 | dst(aout[(t|((b>>4)&0xf))&0x3f]);
|
5672 | t = (b&0xf)<<2;
|
5673 | if ((b = src()) !== null)
|
5674 | dst(aout[(t|((b>>6)&0x3))&0x3f]),
|
5675 | dst(aout[b&0x3f]);
|
5676 | else
|
5677 | dst(aout[t&0x3f]),
|
5678 | dst(61);
|
5679 | } else
|
5680 | dst(aout[t&0x3f]),
|
5681 | dst(61),
|
5682 | dst(61);
|
5683 | }
|
5684 | };
|
5685 |
|
5686 | |
5687 |
|
5688 |
|
5689 |
|
5690 |
|
5691 |
|
5692 |
|
5693 | lxiv.decode = function(src, dst) {
|
5694 | var c, t1, t2;
|
5695 | function fail(c) {
|
5696 | throw Error("Illegal character code: "+c);
|
5697 | }
|
5698 | while ((c = src()) !== null) {
|
5699 | t1 = ain[c];
|
5700 | if (typeof t1 === 'undefined') fail(c);
|
5701 | if ((c = src()) !== null) {
|
5702 | t2 = ain[c];
|
5703 | if (typeof t2 === 'undefined') fail(c);
|
5704 | dst((t1<<2)>>>0|(t2&0x30)>>4);
|
5705 | if ((c = src()) !== null) {
|
5706 | t1 = ain[c];
|
5707 | if (typeof t1 === 'undefined')
|
5708 | if (c === 61) break; else fail(c);
|
5709 | dst(((t2&0xf)<<4)>>>0|(t1&0x3c)>>2);
|
5710 | if ((c = src()) !== null) {
|
5711 | t2 = ain[c];
|
5712 | if (typeof t2 === 'undefined')
|
5713 | if (c === 61) break; else fail(c);
|
5714 | dst(((t1&0x3)<<6)>>>0|t2);
|
5715 | }
|
5716 | }
|
5717 | }
|
5718 | }
|
5719 | };
|
5720 |
|
5721 | |
5722 |
|
5723 |
|
5724 |
|
5725 |
|
5726 | lxiv.test = function(str) {
|
5727 | return /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(str);
|
5728 | };
|
5729 |
|
5730 | return lxiv;
|
5731 | }();
|
5732 |
|
5733 |
|
5734 |
|
5735 | |
5736 |
|
5737 |
|
5738 |
|
5739 |
|
5740 |
|
5741 |
|
5742 |
|
5743 | ByteBufferPrototype.toBase64 = function(begin, end) {
|
5744 | if (typeof begin === 'undefined')
|
5745 | begin = this.offset;
|
5746 | if (typeof end === 'undefined')
|
5747 | end = this.limit;
|
5748 | begin = begin | 0; end = end | 0;
|
5749 | if (begin < 0 || end > this.capacity || begin > end)
|
5750 | throw RangeError("begin, end");
|
5751 | var sd; lxiv.encode(function() {
|
5752 | return begin < end ? this.view[begin++] : null;
|
5753 | }.bind(this), sd = stringDestination());
|
5754 | return sd();
|
5755 | };
|
5756 |
|
5757 | |
5758 |
|
5759 |
|
5760 |
|
5761 |
|
5762 |
|
5763 |
|
5764 |
|
5765 | ByteBuffer.fromBase64 = function(str, littleEndian) {
|
5766 | if (typeof str !== 'string')
|
5767 | throw TypeError("str");
|
5768 | var bb = new ByteBuffer(str.length/4*3, littleEndian),
|
5769 | i = 0;
|
5770 | lxiv.decode(stringSource(str), function(b) {
|
5771 | bb.view[i++] = b;
|
5772 | });
|
5773 | bb.limit = i;
|
5774 | return bb;
|
5775 | };
|
5776 |
|
5777 | |
5778 |
|
5779 |
|
5780 |
|
5781 |
|
5782 |
|
5783 |
|
5784 | ByteBuffer.btoa = function(str) {
|
5785 | return ByteBuffer.fromBinary(str).toBase64();
|
5786 | };
|
5787 |
|
5788 | |
5789 |
|
5790 |
|
5791 |
|
5792 |
|
5793 |
|
5794 |
|
5795 | ByteBuffer.atob = function(b64) {
|
5796 | return ByteBuffer.fromBase64(b64).toBinary();
|
5797 | };
|
5798 |
|
5799 |
|
5800 |
|
5801 | |
5802 |
|
5803 |
|
5804 |
|
5805 |
|
5806 |
|
5807 |
|
5808 |
|
5809 | ByteBufferPrototype.toBinary = function(begin, end) {
|
5810 | if (typeof begin === 'undefined')
|
5811 | begin = this.offset;
|
5812 | if (typeof end === 'undefined')
|
5813 | end = this.limit;
|
5814 | begin |= 0; end |= 0;
|
5815 | if (begin < 0 || end > this.capacity() || begin > end)
|
5816 | throw RangeError("begin, end");
|
5817 | if (begin === end)
|
5818 | return "";
|
5819 | var chars = [],
|
5820 | parts = [];
|
5821 | while (begin < end) {
|
5822 | chars.push(this.view[begin++]);
|
5823 | if (chars.length >= 1024)
|
5824 | parts.push(String.fromCharCode.apply(String, chars)),
|
5825 | chars = [];
|
5826 | }
|
5827 | return parts.join('') + String.fromCharCode.apply(String, chars);
|
5828 | };
|
5829 |
|
5830 | |
5831 |
|
5832 |
|
5833 |
|
5834 |
|
5835 |
|
5836 |
|
5837 |
|
5838 | ByteBuffer.fromBinary = function(str, littleEndian) {
|
5839 | if (typeof str !== 'string')
|
5840 | throw TypeError("str");
|
5841 | var i = 0,
|
5842 | k = str.length,
|
5843 | charCode,
|
5844 | bb = new ByteBuffer(k, littleEndian);
|
5845 | while (i<k) {
|
5846 | charCode = str.charCodeAt(i);
|
5847 | if (charCode > 0xff)
|
5848 | throw RangeError("illegal char code: "+charCode);
|
5849 | bb.view[i++] = charCode;
|
5850 | }
|
5851 | bb.limit = k;
|
5852 | return bb;
|
5853 | };
|
5854 |
|
5855 |
|
5856 |
|
5857 | |
5858 |
|
5859 |
|
5860 |
|
5861 |
|
5862 |
|
5863 |
|
5864 |
|
5865 |
|
5866 |
|
5867 |
|
5868 |
|
5869 |
|
5870 |
|
5871 |
|
5872 |
|
5873 |
|
5874 | ByteBufferPrototype.toDebug = function(columns) {
|
5875 | var i = -1,
|
5876 | k = this.buffer.byteLength,
|
5877 | b,
|
5878 | hex = "",
|
5879 | asc = "",
|
5880 | out = "";
|
5881 | while (i<k) {
|
5882 | if (i !== -1) {
|
5883 | b = this.view[i];
|
5884 | if (b < 0x10) hex += "0"+b.toString(16).toUpperCase();
|
5885 | else hex += b.toString(16).toUpperCase();
|
5886 | if (columns)
|
5887 | asc += b > 32 && b < 127 ? String.fromCharCode(b) : '.';
|
5888 | }
|
5889 | ++i;
|
5890 | if (columns) {
|
5891 | if (i > 0 && i % 16 === 0 && i !== k) {
|
5892 | while (hex.length < 3*16+3) hex += " ";
|
5893 | out += hex+asc+"\n";
|
5894 | hex = asc = "";
|
5895 | }
|
5896 | }
|
5897 | if (i === this.offset && i === this.limit)
|
5898 | hex += i === this.markedOffset ? "!" : "|";
|
5899 | else if (i === this.offset)
|
5900 | hex += i === this.markedOffset ? "[" : "<";
|
5901 | else if (i === this.limit)
|
5902 | hex += i === this.markedOffset ? "]" : ">";
|
5903 | else
|
5904 | hex += i === this.markedOffset ? "'" : (columns || (i !== 0 && i !== k) ? " " : "");
|
5905 | }
|
5906 | if (columns && hex !== " ") {
|
5907 | while (hex.length < 3*16+3)
|
5908 | hex += " ";
|
5909 | out += hex + asc + "\n";
|
5910 | }
|
5911 | return columns ? out : hex;
|
5912 | };
|
5913 |
|
5914 | |
5915 |
|
5916 |
|
5917 |
|
5918 |
|
5919 |
|
5920 |
|
5921 |
|
5922 |
|
5923 |
|
5924 |
|
5925 | ByteBuffer.fromDebug = function(str, littleEndian, noAssert) {
|
5926 | var k = str.length,
|
5927 | bb = new ByteBuffer(((k+1)/3)|0, littleEndian, noAssert);
|
5928 | var i = 0, j = 0, ch, b,
|
5929 | rs = false,
|
5930 | ho = false, hm = false, hl = false,
|
5931 | fail = false;
|
5932 | while (i<k) {
|
5933 | switch (ch = str.charAt(i++)) {
|
5934 | case '!':
|
5935 | if (!noAssert) {
|
5936 | if (ho || hm || hl) {
|
5937 | fail = true;
|
5938 | break;
|
5939 | }
|
5940 | ho = hm = hl = true;
|
5941 | }
|
5942 | bb.offset = bb.markedOffset = bb.limit = j;
|
5943 | rs = false;
|
5944 | break;
|
5945 | case '|':
|
5946 | if (!noAssert) {
|
5947 | if (ho || hl) {
|
5948 | fail = true;
|
5949 | break;
|
5950 | }
|
5951 | ho = hl = true;
|
5952 | }
|
5953 | bb.offset = bb.limit = j;
|
5954 | rs = false;
|
5955 | break;
|
5956 | case '[':
|
5957 | if (!noAssert) {
|
5958 | if (ho || hm) {
|
5959 | fail = true;
|
5960 | break;
|
5961 | }
|
5962 | ho = hm = true;
|
5963 | }
|
5964 | bb.offset = bb.markedOffset = j;
|
5965 | rs = false;
|
5966 | break;
|
5967 | case '<':
|
5968 | if (!noAssert) {
|
5969 | if (ho) {
|
5970 | fail = true;
|
5971 | break;
|
5972 | }
|
5973 | ho = true;
|
5974 | }
|
5975 | bb.offset = j;
|
5976 | rs = false;
|
5977 | break;
|
5978 | case ']':
|
5979 | if (!noAssert) {
|
5980 | if (hl || hm) {
|
5981 | fail = true;
|
5982 | break;
|
5983 | }
|
5984 | hl = hm = true;
|
5985 | }
|
5986 | bb.limit = bb.markedOffset = j;
|
5987 | rs = false;
|
5988 | break;
|
5989 | case '>':
|
5990 | if (!noAssert) {
|
5991 | if (hl) {
|
5992 | fail = true;
|
5993 | break;
|
5994 | }
|
5995 | hl = true;
|
5996 | }
|
5997 | bb.limit = j;
|
5998 | rs = false;
|
5999 | break;
|
6000 | case "'":
|
6001 | if (!noAssert) {
|
6002 | if (hm) {
|
6003 | fail = true;
|
6004 | break;
|
6005 | }
|
6006 | hm = true;
|
6007 | }
|
6008 | bb.markedOffset = j;
|
6009 | rs = false;
|
6010 | break;
|
6011 | case ' ':
|
6012 | rs = false;
|
6013 | break;
|
6014 | default:
|
6015 | if (!noAssert) {
|
6016 | if (rs) {
|
6017 | fail = true;
|
6018 | break;
|
6019 | }
|
6020 | }
|
6021 | b = parseInt(ch+str.charAt(i++), 16);
|
6022 | if (!noAssert) {
|
6023 | if (isNaN(b) || b < 0 || b > 255)
|
6024 | throw TypeError("Illegal str: Not a debug encoded string");
|
6025 | }
|
6026 | bb.view[j++] = b;
|
6027 | rs = true;
|
6028 | }
|
6029 | if (fail)
|
6030 | throw TypeError("Illegal str: Invalid symbol at "+i);
|
6031 | }
|
6032 | if (!noAssert) {
|
6033 | if (!ho || !hl)
|
6034 | throw TypeError("Illegal str: Missing offset or limit");
|
6035 | if (j<bb.buffer.byteLength)
|
6036 | throw TypeError("Illegal str: Not a debug encoded string (is it hex?) "+j+" < "+k);
|
6037 | }
|
6038 | return bb;
|
6039 | };
|
6040 |
|
6041 |
|
6042 |
|
6043 | |
6044 |
|
6045 |
|
6046 |
|
6047 |
|
6048 |
|
6049 |
|
6050 | ByteBufferPrototype.toHex = function(begin, end) {
|
6051 | begin = typeof begin === 'undefined' ? this.offset : begin;
|
6052 | end = typeof end === 'undefined' ? this.limit : end;
|
6053 | if (!this.noAssert) {
|
6054 | if (typeof begin !== 'number' || begin % 1 !== 0)
|
6055 | throw TypeError("Illegal begin: Not an integer");
|
6056 | begin >>>= 0;
|
6057 | if (typeof end !== 'number' || end % 1 !== 0)
|
6058 | throw TypeError("Illegal end: Not an integer");
|
6059 | end >>>= 0;
|
6060 | if (begin < 0 || begin > end || end > this.buffer.byteLength)
|
6061 | throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength);
|
6062 | }
|
6063 | var out = new Array(end - begin),
|
6064 | b;
|
6065 | while (begin < end) {
|
6066 | b = this.view[begin++];
|
6067 | if (b < 0x10)
|
6068 | out.push("0", b.toString(16));
|
6069 | else out.push(b.toString(16));
|
6070 | }
|
6071 | return out.join('');
|
6072 | };
|
6073 |
|
6074 | |
6075 |
|
6076 |
|
6077 |
|
6078 |
|
6079 |
|
6080 |
|
6081 |
|
6082 |
|
6083 |
|
6084 | ByteBuffer.fromHex = function(str, littleEndian, noAssert) {
|
6085 | if (!noAssert) {
|
6086 | if (typeof str !== 'string')
|
6087 | throw TypeError("Illegal str: Not a string");
|
6088 | if (str.length % 2 !== 0)
|
6089 | throw TypeError("Illegal str: Length not a multiple of 2");
|
6090 | }
|
6091 | var k = str.length,
|
6092 | bb = new ByteBuffer((k / 2) | 0, littleEndian),
|
6093 | b;
|
6094 | for (var i=0, j=0; i<k; i+=2) {
|
6095 | b = parseInt(str.substring(i, i+2), 16);
|
6096 | if (!noAssert)
|
6097 | if (!isFinite(b) || b < 0 || b > 255)
|
6098 | throw TypeError("Illegal str: Contains non-hex characters");
|
6099 | bb.view[j++] = b;
|
6100 | }
|
6101 | bb.limit = j;
|
6102 | return bb;
|
6103 | };
|
6104 |
|
6105 |
|
6106 |
|
6107 | |
6108 |
|
6109 |
|
6110 |
|
6111 |
|
6112 | var utfx = function() {
|
6113 |
|
6114 | |
6115 |
|
6116 |
|
6117 |
|
6118 |
|
6119 | var utfx = {};
|
6120 |
|
6121 | |
6122 |
|
6123 |
|
6124 |
|
6125 |
|
6126 | utfx.MAX_CODEPOINT = 0x10FFFF;
|
6127 |
|
6128 | |
6129 |
|
6130 |
|
6131 |
|
6132 |
|
6133 |
|
6134 | utfx.encodeUTF8 = function(src, dst) {
|
6135 | var cp = null;
|
6136 | if (typeof src === 'number')
|
6137 | cp = src,
|
6138 | src = function() { return null; };
|
6139 | while (cp !== null || (cp = src()) !== null) {
|
6140 | if (cp < 0x80)
|
6141 | dst(cp&0x7F);
|
6142 | else if (cp < 0x800)
|
6143 | dst(((cp>>6)&0x1F)|0xC0),
|
6144 | dst((cp&0x3F)|0x80);
|
6145 | else if (cp < 0x10000)
|
6146 | dst(((cp>>12)&0x0F)|0xE0),
|
6147 | dst(((cp>>6)&0x3F)|0x80),
|
6148 | dst((cp&0x3F)|0x80);
|
6149 | else
|
6150 | dst(((cp>>18)&0x07)|0xF0),
|
6151 | dst(((cp>>12)&0x3F)|0x80),
|
6152 | dst(((cp>>6)&0x3F)|0x80),
|
6153 | dst((cp&0x3F)|0x80);
|
6154 | cp = null;
|
6155 | }
|
6156 | };
|
6157 |
|
6158 | |
6159 |
|
6160 |
|
6161 |
|
6162 |
|
6163 |
|
6164 |
|
6165 |
|
6166 |
|
6167 | utfx.decodeUTF8 = function(src, dst) {
|
6168 | var a, b, c, d, fail = function(b) {
|
6169 | b = b.slice(0, b.indexOf(null));
|
6170 | var err = Error(b.toString());
|
6171 | err.name = "TruncatedError";
|
6172 | err['bytes'] = b;
|
6173 | throw err;
|
6174 | };
|
6175 | while ((a = src()) !== null) {
|
6176 | if ((a&0x80) === 0)
|
6177 | dst(a);
|
6178 | else if ((a&0xE0) === 0xC0)
|
6179 | ((b = src()) === null) && fail([a, b]),
|
6180 | dst(((a&0x1F)<<6) | (b&0x3F));
|
6181 | else if ((a&0xF0) === 0xE0)
|
6182 | ((b=src()) === null || (c=src()) === null) && fail([a, b, c]),
|
6183 | dst(((a&0x0F)<<12) | ((b&0x3F)<<6) | (c&0x3F));
|
6184 | else if ((a&0xF8) === 0xF0)
|
6185 | ((b=src()) === null || (c=src()) === null || (d=src()) === null) && fail([a, b, c ,d]),
|
6186 | dst(((a&0x07)<<18) | ((b&0x3F)<<12) | ((c&0x3F)<<6) | (d&0x3F));
|
6187 | else throw RangeError("Illegal starting byte: "+a);
|
6188 | }
|
6189 | };
|
6190 |
|
6191 | |
6192 |
|
6193 |
|
6194 |
|
6195 |
|
6196 |
|
6197 |
|
6198 | utfx.UTF16toUTF8 = function(src, dst) {
|
6199 | var c1, c2 = null;
|
6200 | while (true) {
|
6201 | if ((c1 = c2 !== null ? c2 : src()) === null)
|
6202 | break;
|
6203 | if (c1 >= 0xD800 && c1 <= 0xDFFF) {
|
6204 | if ((c2 = src()) !== null) {
|
6205 | if (c2 >= 0xDC00 && c2 <= 0xDFFF) {
|
6206 | dst((c1-0xD800)*0x400+c2-0xDC00+0x10000);
|
6207 | c2 = null; continue;
|
6208 | }
|
6209 | }
|
6210 | }
|
6211 | dst(c1);
|
6212 | }
|
6213 | if (c2 !== null) dst(c2);
|
6214 | };
|
6215 |
|
6216 | |
6217 |
|
6218 |
|
6219 |
|
6220 |
|
6221 |
|
6222 |
|
6223 | utfx.UTF8toUTF16 = function(src, dst) {
|
6224 | var cp = null;
|
6225 | if (typeof src === 'number')
|
6226 | cp = src, src = function() { return null; };
|
6227 | while (cp !== null || (cp = src()) !== null) {
|
6228 | if (cp <= 0xFFFF)
|
6229 | dst(cp);
|
6230 | else
|
6231 | cp -= 0x10000,
|
6232 | dst((cp>>10)+0xD800),
|
6233 | dst((cp%0x400)+0xDC00);
|
6234 | cp = null;
|
6235 | }
|
6236 | };
|
6237 |
|
6238 | |
6239 |
|
6240 |
|
6241 |
|
6242 |
|
6243 |
|
6244 | utfx.encodeUTF16toUTF8 = function(src, dst) {
|
6245 | utfx.UTF16toUTF8(src, function(cp) {
|
6246 | utfx.encodeUTF8(cp, dst);
|
6247 | });
|
6248 | };
|
6249 |
|
6250 | |
6251 |
|
6252 |
|
6253 |
|
6254 |
|
6255 |
|
6256 |
|
6257 |
|
6258 | utfx.decodeUTF8toUTF16 = function(src, dst) {
|
6259 | utfx.decodeUTF8(src, function(cp) {
|
6260 | utfx.UTF8toUTF16(cp, dst);
|
6261 | });
|
6262 | };
|
6263 |
|
6264 | |
6265 |
|
6266 |
|
6267 |
|
6268 |
|
6269 | utfx.calculateCodePoint = function(cp) {
|
6270 | return (cp < 0x80) ? 1 : (cp < 0x800) ? 2 : (cp < 0x10000) ? 3 : 4;
|
6271 | };
|
6272 |
|
6273 | |
6274 |
|
6275 |
|
6276 |
|
6277 |
|
6278 |
|
6279 | utfx.calculateUTF8 = function(src) {
|
6280 | var cp, l=0;
|
6281 | while ((cp = src()) !== null)
|
6282 | l += (cp < 0x80) ? 1 : (cp < 0x800) ? 2 : (cp < 0x10000) ? 3 : 4;
|
6283 | return l;
|
6284 | };
|
6285 |
|
6286 | |
6287 |
|
6288 |
|
6289 |
|
6290 |
|
6291 |
|
6292 | utfx.calculateUTF16asUTF8 = function(src) {
|
6293 | var n=0, l=0;
|
6294 | utfx.UTF16toUTF8(src, function(cp) {
|
6295 | ++n; l += (cp < 0x80) ? 1 : (cp < 0x800) ? 2 : (cp < 0x10000) ? 3 : 4;
|
6296 | });
|
6297 | return [n,l];
|
6298 | };
|
6299 |
|
6300 | return utfx;
|
6301 | }();
|
6302 |
|
6303 |
|
6304 |
|
6305 | |
6306 |
|
6307 |
|
6308 |
|
6309 |
|
6310 |
|
6311 |
|
6312 | ByteBufferPrototype.toUTF8 = function(begin, end) {
|
6313 | if (typeof begin === 'undefined') begin = this.offset;
|
6314 | if (typeof end === 'undefined') end = this.limit;
|
6315 | if (!this.noAssert) {
|
6316 | if (typeof begin !== 'number' || begin % 1 !== 0)
|
6317 | throw TypeError("Illegal begin: Not an integer");
|
6318 | begin >>>= 0;
|
6319 | if (typeof end !== 'number' || end % 1 !== 0)
|
6320 | throw TypeError("Illegal end: Not an integer");
|
6321 | end >>>= 0;
|
6322 | if (begin < 0 || begin > end || end > this.buffer.byteLength)
|
6323 | throw RangeError("Illegal range: 0 <= "+begin+" <= "+end+" <= "+this.buffer.byteLength);
|
6324 | }
|
6325 | var sd; try {
|
6326 | utfx.decodeUTF8toUTF16(function() {
|
6327 | return begin < end ? this.view[begin++] : null;
|
6328 | }.bind(this), sd = stringDestination());
|
6329 | } catch (e) {
|
6330 | if (begin !== end)
|
6331 | throw RangeError("Illegal range: Truncated data, "+begin+" != "+end);
|
6332 | }
|
6333 | return sd();
|
6334 | };
|
6335 |
|
6336 | |
6337 |
|
6338 |
|
6339 |
|
6340 |
|
6341 |
|
6342 |
|
6343 |
|
6344 |
|
6345 |
|
6346 | ByteBuffer.fromUTF8 = function(str, littleEndian, noAssert) {
|
6347 | if (!noAssert)
|
6348 | if (typeof str !== 'string')
|
6349 | throw TypeError("Illegal str: Not a string");
|
6350 | var bb = new ByteBuffer(utfx.calculateUTF16asUTF8(stringSource(str), true)[1], littleEndian, noAssert),
|
6351 | i = 0;
|
6352 | utfx.encodeUTF16toUTF8(stringSource(str), function(b) {
|
6353 | bb.view[i++] = b;
|
6354 | });
|
6355 | bb.limit = i;
|
6356 | return bb;
|
6357 | };
|
6358 |
|
6359 | return ByteBuffer;
|
6360 | });
|
6361 | });
|
6362 |
|
6363 | var require$$2 = {};
|
6364 |
|
6365 | var protobufLight = createCommonjsModule(function (module) {
|
6366 | |
6367 |
|
6368 |
|
6369 |
|
6370 |
|
6371 |
|
6372 |
|
6373 |
|
6374 |
|
6375 |
|
6376 |
|
6377 |
|
6378 |
|
6379 |
|
6380 |
|
6381 |
|
6382 | |
6383 |
|
6384 |
|
6385 |
|
6386 |
|
6387 | (function(global, factory) {
|
6388 |
|
6389 | if (typeof commonjsRequire === "function" && 'object' === "object" && module && module["exports"])
|
6390 | module["exports"] = factory(bytebuffer, true);
|
6391 | else
|
6392 | (global["dcodeIO"] = global["dcodeIO"] || {})["ProtoBuf"] = factory(global["dcodeIO"]["ByteBuffer"]);
|
6393 |
|
6394 | })(commonjsGlobal, function(ByteBuffer, isCommonJS) {
|
6395 |
|
6396 | |
6397 |
|
6398 |
|
6399 |
|
6400 |
|
6401 |
|
6402 | var ProtoBuf = {};
|
6403 |
|
6404 | |
6405 |
|
6406 |
|
6407 |
|
6408 | ProtoBuf.ByteBuffer = ByteBuffer;
|
6409 |
|
6410 | |
6411 |
|
6412 |
|
6413 |
|
6414 | ProtoBuf.Long = ByteBuffer.Long || null;
|
6415 |
|
6416 | |
6417 |
|
6418 |
|
6419 |
|
6420 |
|
6421 |
|
6422 | ProtoBuf.VERSION = "5.0.3";
|
6423 |
|
6424 | |
6425 |
|
6426 |
|
6427 |
|
6428 |
|
6429 |
|
6430 | ProtoBuf.WIRE_TYPES = {};
|
6431 |
|
6432 | |
6433 |
|
6434 |
|
6435 |
|
6436 |
|
6437 | ProtoBuf.WIRE_TYPES.VARINT = 0;
|
6438 |
|
6439 | |
6440 |
|
6441 |
|
6442 |
|
6443 |
|
6444 |
|
6445 | ProtoBuf.WIRE_TYPES.BITS64 = 1;
|
6446 |
|
6447 | |
6448 |
|
6449 |
|
6450 |
|
6451 |
|
6452 |
|
6453 | ProtoBuf.WIRE_TYPES.LDELIM = 2;
|
6454 |
|
6455 | |
6456 |
|
6457 |
|
6458 |
|
6459 |
|
6460 |
|
6461 | ProtoBuf.WIRE_TYPES.STARTGROUP = 3;
|
6462 |
|
6463 | |
6464 |
|
6465 |
|
6466 |
|
6467 |
|
6468 |
|
6469 | ProtoBuf.WIRE_TYPES.ENDGROUP = 4;
|
6470 |
|
6471 | |
6472 |
|
6473 |
|
6474 |
|
6475 |
|
6476 |
|
6477 | ProtoBuf.WIRE_TYPES.BITS32 = 5;
|
6478 |
|
6479 | |
6480 |
|
6481 |
|
6482 |
|
6483 |
|
6484 |
|
6485 | ProtoBuf.PACKABLE_WIRE_TYPES = [
|
6486 | ProtoBuf.WIRE_TYPES.VARINT,
|
6487 | ProtoBuf.WIRE_TYPES.BITS64,
|
6488 | ProtoBuf.WIRE_TYPES.BITS32
|
6489 | ];
|
6490 |
|
6491 | |
6492 |
|
6493 |
|
6494 |
|
6495 |
|
6496 |
|
6497 |
|
6498 | ProtoBuf.TYPES = {
|
6499 |
|
6500 | "int32": {
|
6501 | name: "int32",
|
6502 | wireType: ProtoBuf.WIRE_TYPES.VARINT,
|
6503 | defaultValue: 0
|
6504 | },
|
6505 | "uint32": {
|
6506 | name: "uint32",
|
6507 | wireType: ProtoBuf.WIRE_TYPES.VARINT,
|
6508 | defaultValue: 0
|
6509 | },
|
6510 | "sint32": {
|
6511 | name: "sint32",
|
6512 | wireType: ProtoBuf.WIRE_TYPES.VARINT,
|
6513 | defaultValue: 0
|
6514 | },
|
6515 | "int64": {
|
6516 | name: "int64",
|
6517 | wireType: ProtoBuf.WIRE_TYPES.VARINT,
|
6518 | defaultValue: ProtoBuf.Long ? ProtoBuf.Long.ZERO : undefined
|
6519 | },
|
6520 | "uint64": {
|
6521 | name: "uint64",
|
6522 | wireType: ProtoBuf.WIRE_TYPES.VARINT,
|
6523 | defaultValue: ProtoBuf.Long ? ProtoBuf.Long.UZERO : undefined
|
6524 | },
|
6525 | "sint64": {
|
6526 | name: "sint64",
|
6527 | wireType: ProtoBuf.WIRE_TYPES.VARINT,
|
6528 | defaultValue: ProtoBuf.Long ? ProtoBuf.Long.ZERO : undefined
|
6529 | },
|
6530 | "bool": {
|
6531 | name: "bool",
|
6532 | wireType: ProtoBuf.WIRE_TYPES.VARINT,
|
6533 | defaultValue: false
|
6534 | },
|
6535 | "double": {
|
6536 | name: "double",
|
6537 | wireType: ProtoBuf.WIRE_TYPES.BITS64,
|
6538 | defaultValue: 0
|
6539 | },
|
6540 | "string": {
|
6541 | name: "string",
|
6542 | wireType: ProtoBuf.WIRE_TYPES.LDELIM,
|
6543 | defaultValue: ""
|
6544 | },
|
6545 | "bytes": {
|
6546 | name: "bytes",
|
6547 | wireType: ProtoBuf.WIRE_TYPES.LDELIM,
|
6548 | defaultValue: null
|
6549 | },
|
6550 | "fixed32": {
|
6551 | name: "fixed32",
|
6552 | wireType: ProtoBuf.WIRE_TYPES.BITS32,
|
6553 | defaultValue: 0
|
6554 | },
|
6555 | "sfixed32": {
|
6556 | name: "sfixed32",
|
6557 | wireType: ProtoBuf.WIRE_TYPES.BITS32,
|
6558 | defaultValue: 0
|
6559 | },
|
6560 | "fixed64": {
|
6561 | name: "fixed64",
|
6562 | wireType: ProtoBuf.WIRE_TYPES.BITS64,
|
6563 | defaultValue: ProtoBuf.Long ? ProtoBuf.Long.UZERO : undefined
|
6564 | },
|
6565 | "sfixed64": {
|
6566 | name: "sfixed64",
|
6567 | wireType: ProtoBuf.WIRE_TYPES.BITS64,
|
6568 | defaultValue: ProtoBuf.Long ? ProtoBuf.Long.ZERO : undefined
|
6569 | },
|
6570 | "float": {
|
6571 | name: "float",
|
6572 | wireType: ProtoBuf.WIRE_TYPES.BITS32,
|
6573 | defaultValue: 0
|
6574 | },
|
6575 | "enum": {
|
6576 | name: "enum",
|
6577 | wireType: ProtoBuf.WIRE_TYPES.VARINT,
|
6578 | defaultValue: 0
|
6579 | },
|
6580 | "message": {
|
6581 | name: "message",
|
6582 | wireType: ProtoBuf.WIRE_TYPES.LDELIM,
|
6583 | defaultValue: null
|
6584 | },
|
6585 | "group": {
|
6586 | name: "group",
|
6587 | wireType: ProtoBuf.WIRE_TYPES.STARTGROUP,
|
6588 | defaultValue: null
|
6589 | }
|
6590 | };
|
6591 |
|
6592 | |
6593 |
|
6594 |
|
6595 |
|
6596 |
|
6597 |
|
6598 | ProtoBuf.MAP_KEY_TYPES = [
|
6599 | ProtoBuf.TYPES["int32"],
|
6600 | ProtoBuf.TYPES["sint32"],
|
6601 | ProtoBuf.TYPES["sfixed32"],
|
6602 | ProtoBuf.TYPES["uint32"],
|
6603 | ProtoBuf.TYPES["fixed32"],
|
6604 | ProtoBuf.TYPES["int64"],
|
6605 | ProtoBuf.TYPES["sint64"],
|
6606 | ProtoBuf.TYPES["sfixed64"],
|
6607 | ProtoBuf.TYPES["uint64"],
|
6608 | ProtoBuf.TYPES["fixed64"],
|
6609 | ProtoBuf.TYPES["bool"],
|
6610 | ProtoBuf.TYPES["string"],
|
6611 | ProtoBuf.TYPES["bytes"]
|
6612 | ];
|
6613 |
|
6614 | |
6615 |
|
6616 |
|
6617 |
|
6618 |
|
6619 |
|
6620 | ProtoBuf.ID_MIN = 1;
|
6621 |
|
6622 | |
6623 |
|
6624 |
|
6625 |
|
6626 |
|
6627 |
|
6628 | ProtoBuf.ID_MAX = 0x1FFFFFFF;
|
6629 |
|
6630 | |
6631 |
|
6632 |
|
6633 |
|
6634 |
|
6635 |
|
6636 | ProtoBuf.convertFieldsToCamelCase = false;
|
6637 |
|
6638 | |
6639 |
|
6640 |
|
6641 |
|
6642 |
|
6643 |
|
6644 | ProtoBuf.populateAccessors = true;
|
6645 |
|
6646 | |
6647 |
|
6648 |
|
6649 |
|
6650 |
|
6651 |
|
6652 | ProtoBuf.populateDefaults = true;
|
6653 |
|
6654 | |
6655 |
|
6656 |
|
6657 |
|
6658 | ProtoBuf.Util = (function() {
|
6659 |
|
6660 | |
6661 |
|
6662 |
|
6663 |
|
6664 |
|
6665 | var Util = {};
|
6666 |
|
6667 | |
6668 |
|
6669 |
|
6670 |
|
6671 |
|
6672 |
|
6673 | Util.IS_NODE = !!(
|
6674 | typeof process === 'object' && process+'' === '[object process]' && !process['browser']
|
6675 | );
|
6676 |
|
6677 | |
6678 |
|
6679 |
|
6680 |
|
6681 |
|
6682 |
|
6683 | Util.XHR = function() {
|
6684 |
|
6685 | var XMLHttpFactories = [
|
6686 | function () {return new XMLHttpRequest()},
|
6687 | function () {return new ActiveXObject("Msxml2.XMLHTTP")},
|
6688 | function () {return new ActiveXObject("Msxml3.XMLHTTP")},
|
6689 | function () {return new ActiveXObject("Microsoft.XMLHTTP")}
|
6690 | ];
|
6691 |
|
6692 | var xhr = null;
|
6693 | for (var i=0;i<XMLHttpFactories.length;i++) {
|
6694 | try { xhr = XMLHttpFactories[i](); }
|
6695 | catch (e) { continue; }
|
6696 | break;
|
6697 | }
|
6698 | if (!xhr)
|
6699 | throw Error("XMLHttpRequest is not supported");
|
6700 | return xhr;
|
6701 | };
|
6702 |
|
6703 | |
6704 |
|
6705 |
|
6706 |
|
6707 |
|
6708 |
|
6709 |
|
6710 |
|
6711 | Util.fetch = function(path, callback) {
|
6712 | if (callback && typeof callback != 'function')
|
6713 | callback = null;
|
6714 | if (Util.IS_NODE) {
|
6715 | var fs = require$$2;
|
6716 | if (callback) {
|
6717 | fs.readFile(path, function(err, data) {
|
6718 | if (err)
|
6719 | callback(null);
|
6720 | else
|
6721 | callback(""+data);
|
6722 | });
|
6723 | } else
|
6724 | try {
|
6725 | return fs.readFileSync(path);
|
6726 | } catch (e) {
|
6727 | return null;
|
6728 | }
|
6729 | } else {
|
6730 | var xhr = Util.XHR();
|
6731 | xhr.open('GET', path, callback ? true : false);
|
6732 |
|
6733 | xhr.setRequestHeader('Accept', 'text/plain');
|
6734 | if (typeof xhr.overrideMimeType === 'function') xhr.overrideMimeType('text/plain');
|
6735 | if (callback) {
|
6736 | xhr.onreadystatechange = function() {
|
6737 | if (xhr.readyState != 4) return;
|
6738 | if ( xhr.status == 200 || (xhr.status == 0 && typeof xhr.responseText === 'string'))
|
6739 | callback(xhr.responseText);
|
6740 | else
|
6741 | callback(null);
|
6742 | };
|
6743 | if (xhr.readyState == 4)
|
6744 | return;
|
6745 | xhr.send(null);
|
6746 | } else {
|
6747 | xhr.send(null);
|
6748 | if ( xhr.status == 200 || (xhr.status == 0 && typeof xhr.responseText === 'string'))
|
6749 | return xhr.responseText;
|
6750 | return null;
|
6751 | }
|
6752 | }
|
6753 | };
|
6754 |
|
6755 | |
6756 |
|
6757 |
|
6758 |
|
6759 |
|
6760 |
|
6761 | Util.toCamelCase = function(str) {
|
6762 | return str.replace(/_([a-zA-Z])/g, function ($0, $1) {
|
6763 | return $1.toUpperCase();
|
6764 | });
|
6765 | };
|
6766 |
|
6767 | return Util;
|
6768 | })();
|
6769 |
|
6770 | |
6771 |
|
6772 |
|
6773 |
|
6774 |
|
6775 | ProtoBuf.Lang = {
|
6776 |
|
6777 |
|
6778 | DELIM: /[\s\{\}=;:\[\],'"\(\)<>]/g,
|
6779 |
|
6780 |
|
6781 | RULE: /^(?:required|optional|repeated|map)$/,
|
6782 |
|
6783 |
|
6784 | TYPE: /^(?:double|float|int32|uint32|sint32|int64|uint64|sint64|fixed32|sfixed32|fixed64|sfixed64|bool|string|bytes)$/,
|
6785 |
|
6786 |
|
6787 | NAME: /^[a-zA-Z_][a-zA-Z_0-9]*$/,
|
6788 |
|
6789 |
|
6790 | TYPEDEF: /^[a-zA-Z][a-zA-Z_0-9]*$/,
|
6791 |
|
6792 |
|
6793 | TYPEREF: /^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/,
|
6794 |
|
6795 |
|
6796 | FQTYPEREF: /^(?:\.[a-zA-Z_][a-zA-Z_0-9]*)+$/,
|
6797 |
|
6798 |
|
6799 | NUMBER: /^-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+|([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?)|inf|nan)$/,
|
6800 |
|
6801 |
|
6802 | NUMBER_DEC: /^(?:[1-9][0-9]*|0)$/,
|
6803 |
|
6804 |
|
6805 | NUMBER_HEX: /^0[xX][0-9a-fA-F]+$/,
|
6806 |
|
6807 |
|
6808 | NUMBER_OCT: /^0[0-7]+$/,
|
6809 |
|
6810 |
|
6811 | NUMBER_FLT: /^([0-9]*(\.[0-9]*)?([Ee][+-]?[0-9]+)?|inf|nan)$/,
|
6812 |
|
6813 |
|
6814 | BOOL: /^(?:true|false)$/i,
|
6815 |
|
6816 |
|
6817 | ID: /^(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/,
|
6818 |
|
6819 |
|
6820 | NEGID: /^\-?(?:[1-9][0-9]*|0|0[xX][0-9a-fA-F]+|0[0-7]+)$/,
|
6821 |
|
6822 |
|
6823 | WHITESPACE: /\s/,
|
6824 |
|
6825 |
|
6826 | STRING: /(?:"([^"\\]*(?:\\.[^"\\]*)*)")|(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g,
|
6827 |
|
6828 |
|
6829 | STRING_DQ: /(?:"([^"\\]*(?:\\.[^"\\]*)*)")/g,
|
6830 |
|
6831 |
|
6832 | STRING_SQ: /(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g
|
6833 | };
|
6834 |
|
6835 |
|
6836 | |
6837 |
|
6838 |
|
6839 |
|
6840 | ProtoBuf.Reflect = (function(ProtoBuf) {
|
6841 |
|
6842 | |
6843 |
|
6844 |
|
6845 |
|
6846 |
|
6847 | var Reflect = {};
|
6848 |
|
6849 | |
6850 |
|
6851 |
|
6852 |
|
6853 |
|
6854 |
|
6855 |
|
6856 |
|
6857 |
|
6858 | var T = function(builder, parent, name) {
|
6859 |
|
6860 | |
6861 |
|
6862 |
|
6863 |
|
6864 |
|
6865 | this.builder = builder;
|
6866 |
|
6867 | |
6868 |
|
6869 |
|
6870 |
|
6871 |
|
6872 | this.parent = parent;
|
6873 |
|
6874 | |
6875 |
|
6876 |
|
6877 |
|
6878 |
|
6879 | this.name = name;
|
6880 |
|
6881 | |
6882 |
|
6883 |
|
6884 |
|
6885 |
|
6886 | this.className;
|
6887 | };
|
6888 |
|
6889 | |
6890 |
|
6891 |
|
6892 |
|
6893 | var TPrototype = T.prototype;
|
6894 |
|
6895 | |
6896 |
|
6897 |
|
6898 |
|
6899 |
|
6900 | TPrototype.fqn = function() {
|
6901 | var name = this.name,
|
6902 | ptr = this;
|
6903 | do {
|
6904 | ptr = ptr.parent;
|
6905 | if (ptr == null)
|
6906 | break;
|
6907 | name = ptr.name+"."+name;
|
6908 | } while (true);
|
6909 | return name;
|
6910 | };
|
6911 |
|
6912 | |
6913 |
|
6914 |
|
6915 |
|
6916 |
|
6917 |
|
6918 | TPrototype.toString = function(includeClass) {
|
6919 | return (includeClass ? this.className + " " : "") + this.fqn();
|
6920 | };
|
6921 |
|
6922 | |
6923 |
|
6924 |
|
6925 |
|
6926 |
|
6927 | TPrototype.build = function() {
|
6928 | throw Error(this.toString(true)+" cannot be built directly");
|
6929 | };
|
6930 |
|
6931 | |
6932 |
|
6933 |
|
6934 |
|
6935 | Reflect.T = T;
|
6936 |
|
6937 | |
6938 |
|
6939 |
|
6940 |
|
6941 |
|
6942 |
|
6943 |
|
6944 |
|
6945 |
|
6946 |
|
6947 |
|
6948 | var Namespace = function(builder, parent, name, options, syntax) {
|
6949 | T.call(this, builder, parent, name);
|
6950 |
|
6951 | |
6952 |
|
6953 |
|
6954 | this.className = "Namespace";
|
6955 |
|
6956 | |
6957 |
|
6958 |
|
6959 |
|
6960 | this.children = [];
|
6961 |
|
6962 | |
6963 |
|
6964 |
|
6965 |
|
6966 | this.options = options || {};
|
6967 |
|
6968 | |
6969 |
|
6970 |
|
6971 |
|
6972 | this.syntax = syntax || "proto2";
|
6973 | };
|
6974 |
|
6975 | |
6976 |
|
6977 |
|
6978 |
|
6979 | var NamespacePrototype = Namespace.prototype = Object.create(T.prototype);
|
6980 |
|
6981 | |
6982 |
|
6983 |
|
6984 |
|
6985 |
|
6986 |
|
6987 | NamespacePrototype.getChildren = function(type) {
|
6988 | type = type || null;
|
6989 | if (type == null)
|
6990 | return this.children.slice();
|
6991 | var children = [];
|
6992 | for (var i=0, k=this.children.length; i<k; ++i)
|
6993 | if (this.children[i] instanceof type)
|
6994 | children.push(this.children[i]);
|
6995 | return children;
|
6996 | };
|
6997 |
|
6998 | |
6999 |
|
7000 |
|
7001 |
|
7002 |
|
7003 |
|
7004 | NamespacePrototype.addChild = function(child) {
|
7005 | var other;
|
7006 | if (other = this.getChild(child.name)) {
|
7007 |
|
7008 | if (other instanceof Message.Field && other.name !== other.originalName && this.getChild(other.originalName) === null)
|
7009 | other.name = other.originalName;
|
7010 | else if (child instanceof Message.Field && child.name !== child.originalName && this.getChild(child.originalName) === null)
|
7011 | child.name = child.originalName;
|
7012 | else
|
7013 | throw Error("Duplicate name in namespace "+this.toString(true)+": "+child.name);
|
7014 | }
|
7015 | this.children.push(child);
|
7016 | };
|
7017 |
|
7018 | |
7019 |
|
7020 |
|
7021 |
|
7022 |
|
7023 |
|
7024 | NamespacePrototype.getChild = function(nameOrId) {
|
7025 | var key = typeof nameOrId === 'number' ? 'id' : 'name';
|
7026 | for (var i=0, k=this.children.length; i<k; ++i)
|
7027 | if (this.children[i][key] === nameOrId)
|
7028 | return this.children[i];
|
7029 | return null;
|
7030 | };
|
7031 |
|
7032 | |
7033 |
|
7034 |
|
7035 |
|
7036 |
|
7037 |
|
7038 |
|
7039 | NamespacePrototype.resolve = function(qn, excludeNonNamespace) {
|
7040 | var part = typeof qn === 'string' ? qn.split(".") : qn,
|
7041 | ptr = this,
|
7042 | i = 0;
|
7043 | if (part[i] === "") {
|
7044 | while (ptr.parent !== null)
|
7045 | ptr = ptr.parent;
|
7046 | i++;
|
7047 | }
|
7048 | var child;
|
7049 | do {
|
7050 | do {
|
7051 | if (!(ptr instanceof Reflect.Namespace)) {
|
7052 | ptr = null;
|
7053 | break;
|
7054 | }
|
7055 | child = ptr.getChild(part[i]);
|
7056 | if (!child || !(child instanceof Reflect.T) || (excludeNonNamespace && !(child instanceof Reflect.Namespace))) {
|
7057 | ptr = null;
|
7058 | break;
|
7059 | }
|
7060 | ptr = child; i++;
|
7061 | } while (i < part.length);
|
7062 | if (ptr != null)
|
7063 | break;
|
7064 |
|
7065 | if (this.parent !== null)
|
7066 | return this.parent.resolve(qn, excludeNonNamespace);
|
7067 | } while (ptr != null);
|
7068 | return ptr;
|
7069 | };
|
7070 |
|
7071 | |
7072 |
|
7073 |
|
7074 |
|
7075 |
|
7076 |
|
7077 | NamespacePrototype.qn = function(t) {
|
7078 | var part = [], ptr = t;
|
7079 | do {
|
7080 | part.unshift(ptr.name);
|
7081 | ptr = ptr.parent;
|
7082 | } while (ptr !== null);
|
7083 | for (var len=1; len <= part.length; len++) {
|
7084 | var qn = part.slice(part.length-len);
|
7085 | if (t === this.resolve(qn, t instanceof Reflect.Namespace))
|
7086 | return qn.join(".");
|
7087 | }
|
7088 | return t.fqn();
|
7089 | };
|
7090 |
|
7091 | |
7092 |
|
7093 |
|
7094 |
|
7095 |
|
7096 | NamespacePrototype.build = function() {
|
7097 |
|
7098 | var ns = {};
|
7099 | var children = this.children;
|
7100 | for (var i=0, k=children.length, child; i<k; ++i) {
|
7101 | child = children[i];
|
7102 | if (child instanceof Namespace)
|
7103 | ns[child.name] = child.build();
|
7104 | }
|
7105 | if (Object.defineProperty)
|
7106 | Object.defineProperty(ns, "$options", { "value": this.buildOpt() });
|
7107 | return ns;
|
7108 | };
|
7109 |
|
7110 | |
7111 |
|
7112 |
|
7113 |
|
7114 | NamespacePrototype.buildOpt = function() {
|
7115 | var opt = {},
|
7116 | keys = Object.keys(this.options);
|
7117 | for (var i=0, k=keys.length; i<k; ++i) {
|
7118 | var key = keys[i],
|
7119 | val = this.options[keys[i]];
|
7120 |
|
7121 |
|
7122 |
|
7123 |
|
7124 | opt[key] = val;
|
7125 |
|
7126 | }
|
7127 | return opt;
|
7128 | };
|
7129 |
|
7130 | |
7131 |
|
7132 |
|
7133 |
|
7134 |
|
7135 | NamespacePrototype.getOption = function(name) {
|
7136 | if (typeof name === 'undefined')
|
7137 | return this.options;
|
7138 | return typeof this.options[name] !== 'undefined' ? this.options[name] : null;
|
7139 | };
|
7140 |
|
7141 | |
7142 |
|
7143 |
|
7144 |
|
7145 | Reflect.Namespace = Namespace;
|
7146 |
|
7147 | |
7148 |
|
7149 |
|
7150 |
|
7151 |
|
7152 |
|
7153 |
|
7154 |
|
7155 |
|
7156 |
|
7157 |
|
7158 |
|
7159 |
|
7160 |
|
7161 |
|
7162 |
|
7163 |
|
7164 |
|
7165 |
|
7166 |
|
7167 |
|
7168 | var Element = function(type, resolvedType, isMapKey, syntax, name) {
|
7169 |
|
7170 | |
7171 |
|
7172 |
|
7173 |
|
7174 | this.type = type;
|
7175 |
|
7176 | |
7177 |
|
7178 |
|
7179 |
|
7180 | this.resolvedType = resolvedType;
|
7181 |
|
7182 | |
7183 |
|
7184 |
|
7185 |
|
7186 | this.isMapKey = isMapKey;
|
7187 |
|
7188 | |
7189 |
|
7190 |
|
7191 |
|
7192 | this.syntax = syntax;
|
7193 |
|
7194 | |
7195 |
|
7196 |
|
7197 |
|
7198 | this.name = name;
|
7199 |
|
7200 | if (isMapKey && ProtoBuf.MAP_KEY_TYPES.indexOf(type) < 0)
|
7201 | throw Error("Invalid map key type: " + type.name);
|
7202 | };
|
7203 |
|
7204 | var ElementPrototype = Element.prototype;
|
7205 |
|
7206 | |
7207 |
|
7208 |
|
7209 |
|
7210 |
|
7211 |
|
7212 | function mkDefault(type) {
|
7213 | if (typeof type === 'string')
|
7214 | type = ProtoBuf.TYPES[type];
|
7215 | if (typeof type.defaultValue === 'undefined')
|
7216 | throw Error("default value for type "+type.name+" is not supported");
|
7217 | if (type == ProtoBuf.TYPES["bytes"])
|
7218 | return new ByteBuffer(0);
|
7219 | return type.defaultValue;
|
7220 | }
|
7221 |
|
7222 | |
7223 |
|
7224 |
|
7225 |
|
7226 |
|
7227 |
|
7228 | Element.defaultFieldValue = mkDefault;
|
7229 |
|
7230 | |
7231 |
|
7232 |
|
7233 |
|
7234 |
|
7235 |
|
7236 |
|
7237 |
|
7238 |
|
7239 | function mkLong(value, unsigned) {
|
7240 | if (value && typeof value.low === 'number' && typeof value.high === 'number' && typeof value.unsigned === 'boolean'
|
7241 | && value.low === value.low && value.high === value.high)
|
7242 | return new ProtoBuf.Long(value.low, value.high, typeof unsigned === 'undefined' ? value.unsigned : unsigned);
|
7243 | if (typeof value === 'string')
|
7244 | return ProtoBuf.Long.fromString(value, unsigned || false, 10);
|
7245 | if (typeof value === 'number')
|
7246 | return ProtoBuf.Long.fromNumber(value, unsigned || false);
|
7247 | throw Error("not convertible to Long");
|
7248 | }
|
7249 |
|
7250 | ElementPrototype.toString = function() {
|
7251 | return (this.name || '') + (this.isMapKey ? 'map' : 'value') + ' element';
|
7252 | };
|
7253 |
|
7254 | |
7255 |
|
7256 |
|
7257 |
|
7258 |
|
7259 |
|
7260 |
|
7261 |
|
7262 | ElementPrototype.verifyValue = function(value) {
|
7263 | var self = this;
|
7264 | function fail(val, msg) {
|
7265 | throw Error("Illegal value for "+self.toString(true)+" of type "+self.type.name+": "+val+" ("+msg+")");
|
7266 | }
|
7267 | switch (this.type) {
|
7268 |
|
7269 | case ProtoBuf.TYPES["int32"]:
|
7270 | case ProtoBuf.TYPES["sint32"]:
|
7271 | case ProtoBuf.TYPES["sfixed32"]:
|
7272 |
|
7273 | if (typeof value !== 'number' || (value === value && value % 1 !== 0))
|
7274 | fail(typeof value, "not an integer");
|
7275 | return value > 4294967295 ? value | 0 : value;
|
7276 |
|
7277 |
|
7278 | case ProtoBuf.TYPES["uint32"]:
|
7279 | case ProtoBuf.TYPES["fixed32"]:
|
7280 | if (typeof value !== 'number' || (value === value && value % 1 !== 0))
|
7281 | fail(typeof value, "not an integer");
|
7282 | return value < 0 ? value >>> 0 : value;
|
7283 |
|
7284 |
|
7285 | case ProtoBuf.TYPES["int64"]:
|
7286 | case ProtoBuf.TYPES["sint64"]:
|
7287 | case ProtoBuf.TYPES["sfixed64"]: {
|
7288 | if (ProtoBuf.Long)
|
7289 | try {
|
7290 | return mkLong(value, false);
|
7291 | } catch (e) {
|
7292 | fail(typeof value, e.message);
|
7293 | }
|
7294 | else
|
7295 | fail(typeof value, "requires Long.js");
|
7296 | }
|
7297 |
|
7298 |
|
7299 | case ProtoBuf.TYPES["uint64"]:
|
7300 | case ProtoBuf.TYPES["fixed64"]: {
|
7301 | if (ProtoBuf.Long)
|
7302 | try {
|
7303 | return mkLong(value, true);
|
7304 | } catch (e) {
|
7305 | fail(typeof value, e.message);
|
7306 | }
|
7307 | else
|
7308 | fail(typeof value, "requires Long.js");
|
7309 | }
|
7310 |
|
7311 |
|
7312 | case ProtoBuf.TYPES["bool"]:
|
7313 | if (typeof value !== 'boolean')
|
7314 | fail(typeof value, "not a boolean");
|
7315 | return value;
|
7316 |
|
7317 |
|
7318 | case ProtoBuf.TYPES["float"]:
|
7319 | case ProtoBuf.TYPES["double"]:
|
7320 | if (typeof value !== 'number')
|
7321 | fail(typeof value, "not a number");
|
7322 | return value;
|
7323 |
|
7324 |
|
7325 | case ProtoBuf.TYPES["string"]:
|
7326 | if (typeof value !== 'string' && !(value && value instanceof String))
|
7327 | fail(typeof value, "not a string");
|
7328 | return ""+value;
|
7329 |
|
7330 |
|
7331 | case ProtoBuf.TYPES["bytes"]:
|
7332 | if (ByteBuffer.isByteBuffer(value))
|
7333 | return value;
|
7334 | return ByteBuffer.wrap(value, "base64");
|
7335 |
|
7336 |
|
7337 | case ProtoBuf.TYPES["enum"]: {
|
7338 | var values = this.resolvedType.getChildren(ProtoBuf.Reflect.Enum.Value);
|
7339 | for (i=0; i<values.length; i++)
|
7340 | if (values[i].name == value)
|
7341 | return values[i].id;
|
7342 | else if (values[i].id == value)
|
7343 | return values[i].id;
|
7344 |
|
7345 | if (this.syntax === 'proto3') {
|
7346 |
|
7347 | if (typeof value !== 'number' || (value === value && value % 1 !== 0))
|
7348 | fail(typeof value, "not an integer");
|
7349 | if (value > 4294967295 || value < 0)
|
7350 | fail(typeof value, "not in range for uint32");
|
7351 | return value;
|
7352 | } else {
|
7353 |
|
7354 | fail(value, "not a valid enum value");
|
7355 | }
|
7356 | }
|
7357 |
|
7358 | case ProtoBuf.TYPES["group"]:
|
7359 | case ProtoBuf.TYPES["message"]: {
|
7360 | if (!value || typeof value !== 'object')
|
7361 | fail(typeof value, "object expected");
|
7362 | if (value instanceof this.resolvedType.clazz)
|
7363 | return value;
|
7364 | if (value instanceof ProtoBuf.Builder.Message) {
|
7365 |
|
7366 | var obj = {};
|
7367 | for (var i in value)
|
7368 | if (value.hasOwnProperty(i))
|
7369 | obj[i] = value[i];
|
7370 | value = obj;
|
7371 | }
|
7372 |
|
7373 | return new (this.resolvedType.clazz)(value);
|
7374 | }
|
7375 | }
|
7376 |
|
7377 |
|
7378 | throw Error("[INTERNAL] Illegal value for "+this.toString(true)+": "+value+" (undefined type "+this.type+")");
|
7379 | };
|
7380 |
|
7381 | |
7382 |
|
7383 |
|
7384 |
|
7385 |
|
7386 |
|
7387 |
|
7388 |
|
7389 | ElementPrototype.calculateLength = function(id, value) {
|
7390 | if (value === null) return 0;
|
7391 |
|
7392 | var n;
|
7393 | switch (this.type) {
|
7394 | case ProtoBuf.TYPES["int32"]:
|
7395 | return value < 0 ? ByteBuffer.calculateVarint64(value) : ByteBuffer.calculateVarint32(value);
|
7396 | case ProtoBuf.TYPES["uint32"]:
|
7397 | return ByteBuffer.calculateVarint32(value);
|
7398 | case ProtoBuf.TYPES["sint32"]:
|
7399 | return ByteBuffer.calculateVarint32(ByteBuffer.zigZagEncode32(value));
|
7400 | case ProtoBuf.TYPES["fixed32"]:
|
7401 | case ProtoBuf.TYPES["sfixed32"]:
|
7402 | case ProtoBuf.TYPES["float"]:
|
7403 | return 4;
|
7404 | case ProtoBuf.TYPES["int64"]:
|
7405 | case ProtoBuf.TYPES["uint64"]:
|
7406 | return ByteBuffer.calculateVarint64(value);
|
7407 | case ProtoBuf.TYPES["sint64"]:
|
7408 | return ByteBuffer.calculateVarint64(ByteBuffer.zigZagEncode64(value));
|
7409 | case ProtoBuf.TYPES["fixed64"]:
|
7410 | case ProtoBuf.TYPES["sfixed64"]:
|
7411 | return 8;
|
7412 | case ProtoBuf.TYPES["bool"]:
|
7413 | return 1;
|
7414 | case ProtoBuf.TYPES["enum"]:
|
7415 | return ByteBuffer.calculateVarint32(value);
|
7416 | case ProtoBuf.TYPES["double"]:
|
7417 | return 8;
|
7418 | case ProtoBuf.TYPES["string"]:
|
7419 | n = ByteBuffer.calculateUTF8Bytes(value);
|
7420 | return ByteBuffer.calculateVarint32(n) + n;
|
7421 | case ProtoBuf.TYPES["bytes"]:
|
7422 | if (value.remaining() < 0)
|
7423 | throw Error("Illegal value for "+this.toString(true)+": "+value.remaining()+" bytes remaining");
|
7424 | return ByteBuffer.calculateVarint32(value.remaining()) + value.remaining();
|
7425 | case ProtoBuf.TYPES["message"]:
|
7426 | n = this.resolvedType.calculate(value);
|
7427 | return ByteBuffer.calculateVarint32(n) + n;
|
7428 | case ProtoBuf.TYPES["group"]:
|
7429 | n = this.resolvedType.calculate(value);
|
7430 | return n + ByteBuffer.calculateVarint32((id << 3) | ProtoBuf.WIRE_TYPES.ENDGROUP);
|
7431 | }
|
7432 |
|
7433 | throw Error("[INTERNAL] Illegal value to encode in "+this.toString(true)+": "+value+" (unknown type)");
|
7434 | };
|
7435 |
|
7436 | |
7437 |
|
7438 |
|
7439 |
|
7440 |
|
7441 |
|
7442 |
|
7443 |
|
7444 |
|
7445 | ElementPrototype.encodeValue = function(id, value, buffer) {
|
7446 | if (value === null) return buffer;
|
7447 |
|
7448 |
|
7449 | switch (this.type) {
|
7450 |
|
7451 | case ProtoBuf.TYPES["int32"]:
|
7452 |
|
7453 |
|
7454 | if (value < 0)
|
7455 | buffer.writeVarint64(value);
|
7456 | else
|
7457 | buffer.writeVarint32(value);
|
7458 | break;
|
7459 |
|
7460 |
|
7461 | case ProtoBuf.TYPES["uint32"]:
|
7462 | buffer.writeVarint32(value);
|
7463 | break;
|
7464 |
|
7465 |
|
7466 | case ProtoBuf.TYPES["sint32"]:
|
7467 | buffer.writeVarint32ZigZag(value);
|
7468 | break;
|
7469 |
|
7470 |
|
7471 | case ProtoBuf.TYPES["fixed32"]:
|
7472 | buffer.writeUint32(value);
|
7473 | break;
|
7474 |
|
7475 |
|
7476 | case ProtoBuf.TYPES["sfixed32"]:
|
7477 | buffer.writeInt32(value);
|
7478 | break;
|
7479 |
|
7480 |
|
7481 | case ProtoBuf.TYPES["int64"]:
|
7482 | case ProtoBuf.TYPES["uint64"]:
|
7483 | buffer.writeVarint64(value);
|
7484 | break;
|
7485 |
|
7486 |
|
7487 | case ProtoBuf.TYPES["sint64"]:
|
7488 | buffer.writeVarint64ZigZag(value);
|
7489 | break;
|
7490 |
|
7491 |
|
7492 | case ProtoBuf.TYPES["fixed64"]:
|
7493 | buffer.writeUint64(value);
|
7494 | break;
|
7495 |
|
7496 |
|
7497 | case ProtoBuf.TYPES["sfixed64"]:
|
7498 | buffer.writeInt64(value);
|
7499 | break;
|
7500 |
|
7501 |
|
7502 | case ProtoBuf.TYPES["bool"]:
|
7503 | if (typeof value === 'string')
|
7504 | buffer.writeVarint32(value.toLowerCase() === 'false' ? 0 : !!value);
|
7505 | else
|
7506 | buffer.writeVarint32(value ? 1 : 0);
|
7507 | break;
|
7508 |
|
7509 |
|
7510 | case ProtoBuf.TYPES["enum"]:
|
7511 | buffer.writeVarint32(value);
|
7512 | break;
|
7513 |
|
7514 |
|
7515 | case ProtoBuf.TYPES["float"]:
|
7516 | buffer.writeFloat32(value);
|
7517 | break;
|
7518 |
|
7519 |
|
7520 | case ProtoBuf.TYPES["double"]:
|
7521 | buffer.writeFloat64(value);
|
7522 | break;
|
7523 |
|
7524 |
|
7525 | case ProtoBuf.TYPES["string"]:
|
7526 | buffer.writeVString(value);
|
7527 | break;
|
7528 |
|
7529 |
|
7530 | case ProtoBuf.TYPES["bytes"]:
|
7531 | if (value.remaining() < 0)
|
7532 | throw Error("Illegal value for "+this.toString(true)+": "+value.remaining()+" bytes remaining");
|
7533 | var prevOffset = value.offset;
|
7534 | buffer.writeVarint32(value.remaining());
|
7535 | buffer.append(value);
|
7536 | value.offset = prevOffset;
|
7537 | break;
|
7538 |
|
7539 |
|
7540 | case ProtoBuf.TYPES["message"]:
|
7541 | var bb = new ByteBuffer().LE();
|
7542 | this.resolvedType.encode(value, bb);
|
7543 | buffer.writeVarint32(bb.offset);
|
7544 | buffer.append(bb.flip());
|
7545 | break;
|
7546 |
|
7547 |
|
7548 | case ProtoBuf.TYPES["group"]:
|
7549 | this.resolvedType.encode(value, buffer);
|
7550 | buffer.writeVarint32((id << 3) | ProtoBuf.WIRE_TYPES.ENDGROUP);
|
7551 | break;
|
7552 |
|
7553 | default:
|
7554 |
|
7555 | throw Error("[INTERNAL] Illegal value to encode in "+this.toString(true)+": "+value+" (unknown type)");
|
7556 | }
|
7557 | return buffer;
|
7558 | };
|
7559 |
|
7560 | |
7561 |
|
7562 |
|
7563 |
|
7564 |
|
7565 |
|
7566 |
|
7567 |
|
7568 |
|
7569 | ElementPrototype.decode = function(buffer, wireType, id) {
|
7570 | if (wireType != this.type.wireType)
|
7571 | throw Error("Unexpected wire type for element");
|
7572 |
|
7573 | var value, nBytes;
|
7574 | switch (this.type) {
|
7575 |
|
7576 | case ProtoBuf.TYPES["int32"]:
|
7577 | return buffer.readVarint32() | 0;
|
7578 |
|
7579 |
|
7580 | case ProtoBuf.TYPES["uint32"]:
|
7581 | return buffer.readVarint32() >>> 0;
|
7582 |
|
7583 |
|
7584 | case ProtoBuf.TYPES["sint32"]:
|
7585 | return buffer.readVarint32ZigZag() | 0;
|
7586 |
|
7587 |
|
7588 | case ProtoBuf.TYPES["fixed32"]:
|
7589 | return buffer.readUint32() >>> 0;
|
7590 |
|
7591 | case ProtoBuf.TYPES["sfixed32"]:
|
7592 | return buffer.readInt32() | 0;
|
7593 |
|
7594 |
|
7595 | case ProtoBuf.TYPES["int64"]:
|
7596 | return buffer.readVarint64();
|
7597 |
|
7598 |
|
7599 | case ProtoBuf.TYPES["uint64"]:
|
7600 | return buffer.readVarint64().toUnsigned();
|
7601 |
|
7602 |
|
7603 | case ProtoBuf.TYPES["sint64"]:
|
7604 | return buffer.readVarint64ZigZag();
|
7605 |
|
7606 |
|
7607 | case ProtoBuf.TYPES["fixed64"]:
|
7608 | return buffer.readUint64();
|
7609 |
|
7610 |
|
7611 | case ProtoBuf.TYPES["sfixed64"]:
|
7612 | return buffer.readInt64();
|
7613 |
|
7614 |
|
7615 | case ProtoBuf.TYPES["bool"]:
|
7616 | return !!buffer.readVarint32();
|
7617 |
|
7618 |
|
7619 | case ProtoBuf.TYPES["enum"]:
|
7620 |
|
7621 | return buffer.readVarint32();
|
7622 |
|
7623 |
|
7624 | case ProtoBuf.TYPES["float"]:
|
7625 | return buffer.readFloat();
|
7626 |
|
7627 |
|
7628 | case ProtoBuf.TYPES["double"]:
|
7629 | return buffer.readDouble();
|
7630 |
|
7631 |
|
7632 | case ProtoBuf.TYPES["string"]:
|
7633 | return buffer.readVString();
|
7634 |
|
7635 |
|
7636 | case ProtoBuf.TYPES["bytes"]: {
|
7637 | nBytes = buffer.readVarint32();
|
7638 | if (buffer.remaining() < nBytes)
|
7639 | throw Error("Illegal number of bytes for "+this.toString(true)+": "+nBytes+" required but got only "+buffer.remaining());
|
7640 | value = buffer.clone();
|
7641 | value.limit = value.offset+nBytes;
|
7642 | buffer.offset += nBytes;
|
7643 | return value;
|
7644 | }
|
7645 |
|
7646 |
|
7647 | case ProtoBuf.TYPES["message"]: {
|
7648 | nBytes = buffer.readVarint32();
|
7649 | return this.resolvedType.decode(buffer, nBytes);
|
7650 | }
|
7651 |
|
7652 |
|
7653 | case ProtoBuf.TYPES["group"]:
|
7654 | return this.resolvedType.decode(buffer, -1, id);
|
7655 | }
|
7656 |
|
7657 |
|
7658 | throw Error("[INTERNAL] Illegal decode type");
|
7659 | };
|
7660 |
|
7661 | |
7662 |
|
7663 |
|
7664 |
|
7665 |
|
7666 |
|
7667 |
|
7668 |
|
7669 | ElementPrototype.valueFromString = function(str) {
|
7670 | if (!this.isMapKey) {
|
7671 | throw Error("valueFromString() called on non-map-key element");
|
7672 | }
|
7673 |
|
7674 | switch (this.type) {
|
7675 | case ProtoBuf.TYPES["int32"]:
|
7676 | case ProtoBuf.TYPES["sint32"]:
|
7677 | case ProtoBuf.TYPES["sfixed32"]:
|
7678 | case ProtoBuf.TYPES["uint32"]:
|
7679 | case ProtoBuf.TYPES["fixed32"]:
|
7680 | return this.verifyValue(parseInt(str));
|
7681 |
|
7682 | case ProtoBuf.TYPES["int64"]:
|
7683 | case ProtoBuf.TYPES["sint64"]:
|
7684 | case ProtoBuf.TYPES["sfixed64"]:
|
7685 | case ProtoBuf.TYPES["uint64"]:
|
7686 | case ProtoBuf.TYPES["fixed64"]:
|
7687 |
|
7688 | return this.verifyValue(str);
|
7689 |
|
7690 | case ProtoBuf.TYPES["bool"]:
|
7691 | return str === "true";
|
7692 |
|
7693 | case ProtoBuf.TYPES["string"]:
|
7694 | return this.verifyValue(str);
|
7695 |
|
7696 | case ProtoBuf.TYPES["bytes"]:
|
7697 | return ByteBuffer.fromBinary(str);
|
7698 | }
|
7699 | };
|
7700 |
|
7701 | |
7702 |
|
7703 |
|
7704 |
|
7705 |
|
7706 |
|
7707 |
|
7708 |
|
7709 |
|
7710 |
|
7711 |
|
7712 |
|
7713 |
|
7714 |
|
7715 |
|
7716 | ElementPrototype.valueToString = function(value) {
|
7717 | if (!this.isMapKey) {
|
7718 | throw Error("valueToString() called on non-map-key element");
|
7719 | }
|
7720 |
|
7721 | if (this.type === ProtoBuf.TYPES["bytes"]) {
|
7722 | return value.toString("binary");
|
7723 | } else {
|
7724 | return value.toString();
|
7725 | }
|
7726 | };
|
7727 |
|
7728 | |
7729 |
|
7730 |
|
7731 |
|
7732 | Reflect.Element = Element;
|
7733 |
|
7734 | |
7735 |
|
7736 |
|
7737 |
|
7738 |
|
7739 |
|
7740 |
|
7741 |
|
7742 |
|
7743 |
|
7744 |
|
7745 |
|
7746 | var Message = function(builder, parent, name, options, isGroup, syntax) {
|
7747 | Namespace.call(this, builder, parent, name, options, syntax);
|
7748 |
|
7749 | |
7750 |
|
7751 |
|
7752 | this.className = "Message";
|
7753 |
|
7754 | |
7755 |
|
7756 |
|
7757 |
|
7758 |
|
7759 | this.extensions = undefined;
|
7760 |
|
7761 | |
7762 |
|
7763 |
|
7764 |
|
7765 |
|
7766 | this.clazz = null;
|
7767 |
|
7768 | |
7769 |
|
7770 |
|
7771 |
|
7772 |
|
7773 | this.isGroup = !!isGroup;
|
7774 |
|
7775 |
|
7776 |
|
7777 | |
7778 |
|
7779 |
|
7780 |
|
7781 |
|
7782 | this._fields = null;
|
7783 |
|
7784 | |
7785 |
|
7786 |
|
7787 |
|
7788 |
|
7789 | this._fieldsById = null;
|
7790 |
|
7791 | |
7792 |
|
7793 |
|
7794 |
|
7795 |
|
7796 | this._fieldsByName = null;
|
7797 | };
|
7798 |
|
7799 | |
7800 |
|
7801 |
|
7802 |
|
7803 | var MessagePrototype = Message.prototype = Object.create(Namespace.prototype);
|
7804 |
|
7805 | |
7806 |
|
7807 |
|
7808 |
|
7809 |
|
7810 |
|
7811 |
|
7812 |
|
7813 | MessagePrototype.build = function(rebuild) {
|
7814 | if (this.clazz && !rebuild)
|
7815 | return this.clazz;
|
7816 |
|
7817 |
|
7818 | var clazz = (function(ProtoBuf, T) {
|
7819 |
|
7820 | var fields = T.getChildren(ProtoBuf.Reflect.Message.Field),
|
7821 | oneofs = T.getChildren(ProtoBuf.Reflect.Message.OneOf);
|
7822 |
|
7823 | |
7824 |
|
7825 |
|
7826 |
|
7827 |
|
7828 |
|
7829 |
|
7830 |
|
7831 |
|
7832 | var Message = function(values, var_args) {
|
7833 | ProtoBuf.Builder.Message.call(this);
|
7834 |
|
7835 |
|
7836 | for (var i=0, k=oneofs.length; i<k; ++i)
|
7837 | this[oneofs[i].name] = null;
|
7838 |
|
7839 | for (i=0, k=fields.length; i<k; ++i) {
|
7840 | var field = fields[i];
|
7841 | this[field.name] =
|
7842 | field.repeated ? [] :
|
7843 | (field.map ? new ProtoBuf.Map(field) : null);
|
7844 | if ((field.required || T.syntax === 'proto3') &&
|
7845 | field.defaultValue !== null)
|
7846 | this[field.name] = field.defaultValue;
|
7847 | }
|
7848 |
|
7849 | if (arguments.length > 0) {
|
7850 | var value;
|
7851 |
|
7852 | if (arguments.length === 1 && values !== null && typeof values === 'object' &&
|
7853 | (typeof values.encode !== 'function' || values instanceof Message) &&
|
7854 | !Array.isArray(values) &&
|
7855 | !(values instanceof ProtoBuf.Map) &&
|
7856 | !ByteBuffer.isByteBuffer(values) &&
|
7857 | !(values instanceof ArrayBuffer) &&
|
7858 | !(ProtoBuf.Long && values instanceof ProtoBuf.Long)) {
|
7859 | this.$set(values);
|
7860 | } else // Set field values from arguments, in declaration order
|
7861 | for (i=0, k=arguments.length; i<k; ++i)
|
7862 | if (typeof (value = arguments[i]) !== 'undefined')
|
7863 | this.$set(fields[i].name, value); // May throw
|
7864 | }
|
7865 | };
|
7866 |
|
7867 | /**
|
7868 | * @alias ProtoBuf.Builder.Message.prototype
|
7869 | * @inner
|
7870 | */
|
7871 | var MessagePrototype = Message.prototype = Object.create(ProtoBuf.Builder.Message.prototype);
|
7872 |
|
7873 | /**
|
7874 | * Adds a value to a repeated field.
|
7875 | * @name ProtoBuf.Builder.Message#add
|
7876 | * @function
|
7877 | * @param {string} key Field name
|
7878 | * @param {*} value Value to add
|
7879 | * @param {boolean=} noAssert Whether to assert the value or not (asserts by default)
|
7880 | * @returns {!ProtoBuf.Builder.Message} this
|
7881 | * @throws {Error} If the value cannot be added
|
7882 | * @expose
|
7883 | */
|
7884 | MessagePrototype.add = function(key, value, noAssert) {
|
7885 | var field = T._fieldsByName[key];
|
7886 | if (!noAssert) {
|
7887 | if (!field)
|
7888 | throw Error(this+"#"+key+" is undefined");
|
7889 | if (!(field instanceof ProtoBuf.Reflect.Message.Field))
|
7890 | throw Error(this+"#"+key+" is not a field: "+field.toString(true));
|
7891 | if (!field.repeated)
|
7892 | throw Error(this+"#"+key+" is not a repeated field");
|
7893 | value = field.verifyValue(value, true);
|
7894 | }
|
7895 | if (this[key] === null)
|
7896 | this[key] = [];
|
7897 | this[key].push(value);
|
7898 | return this;
|
7899 | };
|
7900 |
|
7901 | |
7902 |
|
7903 |
|
7904 |
|
7905 |
|
7906 |
|
7907 |
|
7908 |
|
7909 |
|
7910 |
|
7911 |
|
7912 | MessagePrototype.$add = MessagePrototype.add;
|
7913 |
|
7914 | |
7915 |
|
7916 |
|
7917 |
|
7918 |
|
7919 |
|
7920 |
|
7921 |
|
7922 |
|
7923 |
|
7924 |
|
7925 | MessagePrototype.set = function(keyOrObj, value, noAssert) {
|
7926 | if (keyOrObj && typeof keyOrObj === 'object') {
|
7927 | noAssert = value;
|
7928 | for (var ikey in keyOrObj) {
|
7929 |
|
7930 | if (keyOrObj.hasOwnProperty(ikey) && typeof (value = keyOrObj[ikey]) !== 'undefined' && T._oneofsByName[ikey] === undefined)
|
7931 | this.$set(ikey, value, noAssert);
|
7932 | }
|
7933 | return this;
|
7934 | }
|
7935 | var field = T._fieldsByName[keyOrObj];
|
7936 | if (!noAssert) {
|
7937 | if (!field)
|
7938 | throw Error(this+"#"+keyOrObj+" is not a field: undefined");
|
7939 | if (!(field instanceof ProtoBuf.Reflect.Message.Field))
|
7940 | throw Error(this+"#"+keyOrObj+" is not a field: "+field.toString(true));
|
7941 | this[field.name] = (value = field.verifyValue(value));
|
7942 | } else
|
7943 | this[keyOrObj] = value;
|
7944 | if (field && field.oneof) {
|
7945 | var currentField = this[field.oneof.name];
|
7946 | if (value !== null) {
|
7947 | if (currentField !== null && currentField !== field.name)
|
7948 | this[currentField] = null;
|
7949 | this[field.oneof.name] = field.name;
|
7950 | } else if (currentField === keyOrObj)
|
7951 | this[field.oneof.name] = null;
|
7952 | }
|
7953 | return this;
|
7954 | };
|
7955 |
|
7956 | |
7957 |
|
7958 |
|
7959 |
|
7960 |
|
7961 |
|
7962 |
|
7963 |
|
7964 |
|
7965 |
|
7966 | MessagePrototype.$set = MessagePrototype.set;
|
7967 |
|
7968 | /**
|
7969 | * Gets a field's value.
|
7970 | * @name ProtoBuf.Builder.Message#get
|
7971 | * @function
|
7972 | * @param {string} key Key
|
7973 | * @param {boolean=} noAssert Whether to not assert for an actual field, defaults to `false`
|
7974 | * @return {*} Value
|
7975 | * @throws {Error} If there is no such field
|
7976 | * @expose
|
7977 | */
|
7978 | MessagePrototype.get = function(key, noAssert) {
|
7979 | if (noAssert)
|
7980 | return this[key];
|
7981 | var field = T._fieldsByName[key];
|
7982 | if (!field || !(field instanceof ProtoBuf.Reflect.Message.Field))
|
7983 | throw Error(this+"#"+key+" is not a field: undefined");
|
7984 | if (!(field instanceof ProtoBuf.Reflect.Message.Field))
|
7985 | throw Error(this+"#"+key+" is not a field: "+field.toString(true));
|
7986 | return this[field.name];
|
7987 | };
|
7988 |
|
7989 | |
7990 |
|
7991 |
|
7992 |
|
7993 |
|
7994 |
|
7995 |
|
7996 |
|
7997 |
|
7998 | MessagePrototype.$get = MessagePrototype.get;
|
7999 |
|
8000 | // Getters and setters
|
8001 |
|
8002 | for (var i=0; i<fields.length; i++) {
|
8003 | var field = fields[i];
|
8004 |
|
8005 | if (field instanceof ProtoBuf.Reflect.Message.ExtensionField)
|
8006 | continue;
|
8007 |
|
8008 | if (T.builder.options['populateAccessors'])
|
8009 | (function(field) {
|
8010 |
|
8011 | var Name = field.originalName.replace(/(_[a-zA-Z])/g, function(match) {
|
8012 | return match.toUpperCase().replace('_','');
|
8013 | });
|
8014 | Name = Name.substring(0,1).toUpperCase() + Name.substring(1);
|
8015 |
|
8016 |
|
8017 | var name = field.originalName.replace(/([A-Z])/g, function(match) {
|
8018 | return "_"+match;
|
8019 | });
|
8020 |
|
8021 | |
8022 |
|
8023 |
|
8024 |
|
8025 |
|
8026 |
|
8027 |
|
8028 |
|
8029 | var setter = function(value, noAssert) {
|
8030 | this[field.name] = noAssert ? value : field.verifyValue(value);
|
8031 | return this;
|
8032 | };
|
8033 |
|
8034 | |
8035 |
|
8036 |
|
8037 |
|
8038 |
|
8039 |
|
8040 | var getter = function() {
|
8041 | return this[field.name];
|
8042 | };
|
8043 |
|
8044 | if (T.getChild("set"+Name) === null)
|
8045 | |
8046 |
|
8047 |
|
8048 |
|
8049 |
|
8050 |
|
8051 |
|
8052 |
|
8053 |
|
8054 |
|
8055 |
|
8056 | MessagePrototype["set"+Name] = setter;
|
8057 |
|
8058 | if (T.getChild("set_"+name) === null)
|
8059 | |
8060 |
|
8061 |
|
8062 |
|
8063 |
|
8064 |
|
8065 |
|
8066 |
|
8067 |
|
8068 |
|
8069 |
|
8070 | MessagePrototype["set_"+name] = setter;
|
8071 |
|
8072 | if (T.getChild("get"+Name) === null)
|
8073 | |
8074 |
|
8075 |
|
8076 |
|
8077 |
|
8078 |
|
8079 |
|
8080 |
|
8081 | MessagePrototype["get"+Name] = getter;
|
8082 |
|
8083 | if (T.getChild("get_"+name) === null)
|
8084 | |
8085 |
|
8086 |
|
8087 |
|
8088 |
|
8089 |
|
8090 |
|
8091 |
|
8092 | MessagePrototype["get_"+name] = getter;
|
8093 |
|
8094 | })(field);
|
8095 | }
|
8096 |
|
8097 |
|
8098 |
|
8099 | |
8100 |
|
8101 |
|
8102 |
|
8103 |
|
8104 |
|
8105 |
|
8106 |
|
8107 |
|
8108 |
|
8109 |
|
8110 |
|
8111 |
|
8112 |
|
8113 | MessagePrototype.encode = function(buffer, noVerify) {
|
8114 | if (typeof buffer === 'boolean')
|
8115 | noVerify = buffer,
|
8116 | buffer = undefined;
|
8117 | var isNew = false;
|
8118 | if (!buffer)
|
8119 | buffer = new ByteBuffer(),
|
8120 | isNew = true;
|
8121 | var le = buffer.littleEndian;
|
8122 | try {
|
8123 | T.encode(this, buffer.LE(), noVerify);
|
8124 | return (isNew ? buffer.flip() : buffer).LE(le);
|
8125 | } catch (e) {
|
8126 | buffer.LE(le);
|
8127 | throw(e);
|
8128 | }
|
8129 | };
|
8130 |
|
8131 | |
8132 |
|
8133 |
|
8134 |
|
8135 |
|
8136 |
|
8137 |
|
8138 |
|
8139 | Message.encode = function(data, buffer, noVerify) {
|
8140 | return new Message(data).encode(buffer, noVerify);
|
8141 | };
|
8142 |
|
8143 | |
8144 |
|
8145 |
|
8146 |
|
8147 |
|
8148 |
|
8149 |
|
8150 |
|
8151 | MessagePrototype.calculate = function() {
|
8152 | return T.calculate(this);
|
8153 | };
|
8154 |
|
8155 | |
8156 |
|
8157 |
|
8158 |
|
8159 |
|
8160 |
|
8161 |
|
8162 |
|
8163 |
|
8164 |
|
8165 |
|
8166 | MessagePrototype.encodeDelimited = function(buffer, noVerify) {
|
8167 | var isNew = false;
|
8168 | if (!buffer)
|
8169 | buffer = new ByteBuffer(),
|
8170 | isNew = true;
|
8171 | var enc = new ByteBuffer().LE();
|
8172 | T.encode(this, enc, noVerify).flip();
|
8173 | buffer.writeVarint32(enc.remaining());
|
8174 | buffer.append(enc);
|
8175 | return isNew ? buffer.flip() : buffer;
|
8176 | };
|
8177 |
|
8178 | |
8179 |
|
8180 |
|
8181 |
|
8182 |
|
8183 |
|
8184 |
|
8185 |
|
8186 |
|
8187 | MessagePrototype.encodeAB = function() {
|
8188 | try {
|
8189 | return this.encode().toArrayBuffer();
|
8190 | } catch (e) {
|
8191 | if (e["encoded"]) e["encoded"] = e["encoded"].toArrayBuffer();
|
8192 | throw(e);
|
8193 | }
|
8194 | };
|
8195 |
|
8196 | |
8197 |
|
8198 |
|
8199 |
|
8200 |
|
8201 |
|
8202 |
|
8203 |
|
8204 |
|
8205 | MessagePrototype.toArrayBuffer = MessagePrototype.encodeAB;
|
8206 |
|
8207 | |
8208 |
|
8209 |
|
8210 |
|
8211 |
|
8212 |
|
8213 |
|
8214 |
|
8215 |
|
8216 | MessagePrototype.encodeNB = function() {
|
8217 | try {
|
8218 | return this.encode().toBuffer();
|
8219 | } catch (e) {
|
8220 | if (e["encoded"]) e["encoded"] = e["encoded"].toBuffer();
|
8221 | throw(e);
|
8222 | }
|
8223 | };
|
8224 |
|
8225 | |
8226 |
|
8227 |
|
8228 |
|
8229 |
|
8230 |
|
8231 |
|
8232 |
|
8233 |
|
8234 | MessagePrototype.toBuffer = MessagePrototype.encodeNB;
|
8235 |
|
8236 | |
8237 |
|
8238 |
|
8239 |
|
8240 |
|
8241 |
|
8242 |
|
8243 |
|
8244 |
|
8245 | MessagePrototype.encode64 = function() {
|
8246 | try {
|
8247 | return this.encode().toBase64();
|
8248 | } catch (e) {
|
8249 | if (e["encoded"]) e["encoded"] = e["encoded"].toBase64();
|
8250 | throw(e);
|
8251 | }
|
8252 | };
|
8253 |
|
8254 | |
8255 |
|
8256 |
|
8257 |
|
8258 |
|
8259 |
|
8260 |
|
8261 |
|
8262 |
|
8263 | MessagePrototype.toBase64 = MessagePrototype.encode64;
|
8264 |
|
8265 | |
8266 |
|
8267 |
|
8268 |
|
8269 |
|
8270 |
|
8271 |
|
8272 |
|
8273 |
|
8274 | MessagePrototype.encodeHex = function() {
|
8275 | try {
|
8276 | return this.encode().toHex();
|
8277 | } catch (e) {
|
8278 | if (e["encoded"]) e["encoded"] = e["encoded"].toHex();
|
8279 | throw(e);
|
8280 | }
|
8281 | };
|
8282 |
|
8283 | |
8284 |
|
8285 |
|
8286 |
|
8287 |
|
8288 |
|
8289 |
|
8290 |
|
8291 |
|
8292 | MessagePrototype.toHex = MessagePrototype.encodeHex;
|
8293 |
|
8294 | |
8295 |
|
8296 |
|
8297 |
|
8298 |
|
8299 |
|
8300 |
|
8301 |
|
8302 |
|
8303 | function cloneRaw(obj, binaryAsBase64, longsAsStrings, resolvedType) {
|
8304 | if (obj === null || typeof obj !== 'object') {
|
8305 |
|
8306 | if (resolvedType && resolvedType instanceof ProtoBuf.Reflect.Enum) {
|
8307 | var name = ProtoBuf.Reflect.Enum.getName(resolvedType.object, obj);
|
8308 | if (name !== null)
|
8309 | return name;
|
8310 | }
|
8311 |
|
8312 | return obj;
|
8313 | }
|
8314 |
|
8315 | if (ByteBuffer.isByteBuffer(obj))
|
8316 | return binaryAsBase64 ? obj.toBase64() : obj.toBuffer();
|
8317 |
|
8318 | if (ProtoBuf.Long.isLong(obj))
|
8319 | return longsAsStrings ? obj.toString() : ProtoBuf.Long.fromValue(obj);
|
8320 | var clone;
|
8321 |
|
8322 | if (Array.isArray(obj)) {
|
8323 | clone = [];
|
8324 | obj.forEach(function(v, k) {
|
8325 | clone[k] = cloneRaw(v, binaryAsBase64, longsAsStrings, resolvedType);
|
8326 | });
|
8327 | return clone;
|
8328 | }
|
8329 | clone = {};
|
8330 |
|
8331 | if (obj instanceof ProtoBuf.Map) {
|
8332 | var it = obj.entries();
|
8333 | for (var e = it.next(); !e.done; e = it.next())
|
8334 | clone[obj.keyElem.valueToString(e.value[0])] = cloneRaw(e.value[1], binaryAsBase64, longsAsStrings, obj.valueElem.resolvedType);
|
8335 | return clone;
|
8336 | }
|
8337 |
|
8338 | var type = obj.$type,
|
8339 | field = undefined;
|
8340 | for (var i in obj)
|
8341 | if (obj.hasOwnProperty(i)) {
|
8342 | if (type && (field = type.getChild(i)))
|
8343 | clone[i] = cloneRaw(obj[i], binaryAsBase64, longsAsStrings, field.resolvedType);
|
8344 | else
|
8345 | clone[i] = cloneRaw(obj[i], binaryAsBase64, longsAsStrings);
|
8346 | }
|
8347 | return clone;
|
8348 | }
|
8349 |
|
8350 | |
8351 |
|
8352 |
|
8353 |
|
8354 |
|
8355 |
|
8356 |
|
8357 | MessagePrototype.toRaw = function(binaryAsBase64, longsAsStrings) {
|
8358 | return cloneRaw(this, !!binaryAsBase64, !!longsAsStrings, this.$type);
|
8359 | };
|
8360 |
|
8361 | |
8362 |
|
8363 |
|
8364 |
|
8365 |
|
8366 | MessagePrototype.encodeJSON = function() {
|
8367 | return JSON.stringify(
|
8368 | cloneRaw(this,
|
8369 | true,
|
8370 | true,
|
8371 | this.$type
|
8372 | )
|
8373 | );
|
8374 | };
|
8375 |
|
8376 | |
8377 |
|
8378 |
|
8379 |
|
8380 |
|
8381 |
|
8382 |
|
8383 |
|
8384 |
|
8385 |
|
8386 |
|
8387 |
|
8388 |
|
8389 |
|
8390 | Message.decode = function(buffer, length, enc) {
|
8391 | if (typeof length === 'string')
|
8392 | enc = length,
|
8393 | length = -1;
|
8394 | if (typeof buffer === 'string')
|
8395 | buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64");
|
8396 | else if (!ByteBuffer.isByteBuffer(buffer))
|
8397 | buffer = ByteBuffer.wrap(buffer);
|
8398 | var le = buffer.littleEndian;
|
8399 | try {
|
8400 | var msg = T.decode(buffer.LE(), length);
|
8401 | buffer.LE(le);
|
8402 | return msg;
|
8403 | } catch (e) {
|
8404 | buffer.LE(le);
|
8405 | throw(e);
|
8406 | }
|
8407 | };
|
8408 |
|
8409 | |
8410 |
|
8411 |
|
8412 |
|
8413 |
|
8414 |
|
8415 |
|
8416 |
|
8417 |
|
8418 |
|
8419 |
|
8420 | Message.decodeDelimited = function(buffer, enc) {
|
8421 | if (typeof buffer === 'string')
|
8422 | buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64");
|
8423 | else if (!ByteBuffer.isByteBuffer(buffer))
|
8424 | buffer = ByteBuffer.wrap(buffer);
|
8425 | if (buffer.remaining() < 1)
|
8426 | return null;
|
8427 | var off = buffer.offset,
|
8428 | len = buffer.readVarint32();
|
8429 | if (buffer.remaining() < len) {
|
8430 | buffer.offset = off;
|
8431 | return null;
|
8432 | }
|
8433 | try {
|
8434 | var msg = T.decode(buffer.slice(buffer.offset, buffer.offset + len).LE());
|
8435 | buffer.offset += len;
|
8436 | return msg;
|
8437 | } catch (err) {
|
8438 | buffer.offset += len;
|
8439 | throw err;
|
8440 | }
|
8441 | };
|
8442 |
|
8443 | |
8444 |
|
8445 |
|
8446 |
|
8447 |
|
8448 |
|
8449 |
|
8450 |
|
8451 |
|
8452 |
|
8453 | Message.decode64 = function(str) {
|
8454 | return Message.decode(str, "base64");
|
8455 | };
|
8456 |
|
8457 | |
8458 |
|
8459 |
|
8460 |
|
8461 |
|
8462 |
|
8463 |
|
8464 |
|
8465 |
|
8466 |
|
8467 | Message.decodeHex = function(str) {
|
8468 | return Message.decode(str, "hex");
|
8469 | };
|
8470 |
|
8471 | |
8472 |
|
8473 |
|
8474 |
|
8475 |
|
8476 |
|
8477 |
|
8478 |
|
8479 |
|
8480 |
|
8481 | Message.decodeJSON = function(str) {
|
8482 | return new Message(JSON.parse(str));
|
8483 | };
|
8484 |
|
8485 |
|
8486 |
|
8487 | |
8488 |
|
8489 |
|
8490 |
|
8491 |
|
8492 |
|
8493 |
|
8494 | MessagePrototype.toString = function() {
|
8495 | return T.toString();
|
8496 | };
|
8497 |
|
8498 | if (Object.defineProperty)
|
8499 | Object.defineProperty(Message, '$options', { "value": T.buildOpt() }),
|
8500 | Object.defineProperty(MessagePrototype, "$options", { "value": Message["$options"] }),
|
8501 | Object.defineProperty(Message, "$type", { "value": T }),
|
8502 | Object.defineProperty(MessagePrototype, "$type", { "value": T });
|
8503 |
|
8504 | return Message;
|
8505 |
|
8506 | })(ProtoBuf, this);
|
8507 |
|
8508 |
|
8509 | this._fields = [];
|
8510 | this._fieldsById = {};
|
8511 | this._fieldsByName = {};
|
8512 | this._oneofsByName = {};
|
8513 | for (var i=0, k=this.children.length, child; i<k; i++) {
|
8514 | child = this.children[i];
|
8515 | if (child instanceof Enum || child instanceof Message || child instanceof Service) {
|
8516 | if (clazz.hasOwnProperty(child.name))
|
8517 | throw Error("Illegal reflect child of "+this.toString(true)+": "+child.toString(true)+" cannot override static property '"+child.name+"'");
|
8518 | clazz[child.name] = child.build();
|
8519 | } else if (child instanceof Message.Field)
|
8520 | child.build(),
|
8521 | this._fields.push(child),
|
8522 | this._fieldsById[child.id] = child,
|
8523 | this._fieldsByName[child.name] = child;
|
8524 | else if (child instanceof Message.OneOf) {
|
8525 | this._oneofsByName[child.name] = child;
|
8526 | }
|
8527 | else if (!(child instanceof Message.OneOf) && !(child instanceof Extension))
|
8528 | throw Error("Illegal reflect child of "+this.toString(true)+": "+this.children[i].toString(true));
|
8529 | }
|
8530 |
|
8531 | return this.clazz = clazz;
|
8532 | };
|
8533 |
|
8534 | |
8535 |
|
8536 |
|
8537 |
|
8538 |
|
8539 |
|
8540 |
|
8541 |
|
8542 |
|
8543 | MessagePrototype.encode = function(message, buffer, noVerify) {
|
8544 | var fieldMissing = null,
|
8545 | field;
|
8546 | for (var i=0, k=this._fields.length, val; i<k; ++i) {
|
8547 | field = this._fields[i];
|
8548 | val = message[field.name];
|
8549 | if (field.required && val === null) {
|
8550 | if (fieldMissing === null)
|
8551 | fieldMissing = field;
|
8552 | } else
|
8553 | field.encode(noVerify ? val : field.verifyValue(val), buffer, message);
|
8554 | }
|
8555 | if (fieldMissing !== null) {
|
8556 | var err = Error("Missing at least one required field for "+this.toString(true)+": "+fieldMissing);
|
8557 | err["encoded"] = buffer;
|
8558 | throw(err);
|
8559 | }
|
8560 | return buffer;
|
8561 | };
|
8562 |
|
8563 | |
8564 |
|
8565 |
|
8566 |
|
8567 |
|
8568 |
|
8569 |
|
8570 | MessagePrototype.calculate = function(message) {
|
8571 | for (var n=0, i=0, k=this._fields.length, field, val; i<k; ++i) {
|
8572 | field = this._fields[i];
|
8573 | val = message[field.name];
|
8574 | if (field.required && val === null)
|
8575 | throw Error("Missing at least one required field for "+this.toString(true)+": "+field);
|
8576 | else
|
8577 | n += field.calculate(val, message);
|
8578 | }
|
8579 | return n;
|
8580 | };
|
8581 |
|
8582 | |
8583 |
|
8584 |
|
8585 |
|
8586 |
|
8587 |
|
8588 |
|
8589 |
|
8590 | function skipTillGroupEnd(expectedId, buf) {
|
8591 | var tag = buf.readVarint32(),
|
8592 | wireType = tag & 0x07,
|
8593 | id = tag >>> 3;
|
8594 | switch (wireType) {
|
8595 | case ProtoBuf.WIRE_TYPES.VARINT:
|
8596 | do tag = buf.readUint8();
|
8597 | while ((tag & 0x80) === 0x80);
|
8598 | break;
|
8599 | case ProtoBuf.WIRE_TYPES.BITS64:
|
8600 | buf.offset += 8;
|
8601 | break;
|
8602 | case ProtoBuf.WIRE_TYPES.LDELIM:
|
8603 | tag = buf.readVarint32();
|
8604 | buf.offset += tag;
|
8605 | break;
|
8606 | case ProtoBuf.WIRE_TYPES.STARTGROUP:
|
8607 | skipTillGroupEnd(id, buf);
|
8608 | break;
|
8609 | case ProtoBuf.WIRE_TYPES.ENDGROUP:
|
8610 | if (id === expectedId)
|
8611 | return false;
|
8612 | else
|
8613 | throw Error("Illegal GROUPEND after unknown group: "+id+" ("+expectedId+" expected)");
|
8614 | case ProtoBuf.WIRE_TYPES.BITS32:
|
8615 | buf.offset += 4;
|
8616 | break;
|
8617 | default:
|
8618 | throw Error("Illegal wire type in unknown group "+expectedId+": "+wireType);
|
8619 | }
|
8620 | return true;
|
8621 | }
|
8622 |
|
8623 | |
8624 |
|
8625 |
|
8626 |
|
8627 |
|
8628 |
|
8629 |
|
8630 |
|
8631 |
|
8632 | MessagePrototype.decode = function(buffer, length, expectedGroupEndId) {
|
8633 | if (typeof length !== 'number')
|
8634 | length = -1;
|
8635 | var start = buffer.offset,
|
8636 | msg = new (this.clazz)(),
|
8637 | tag, wireType, id, field;
|
8638 | while (buffer.offset < start+length || (length === -1 && buffer.remaining() > 0)) {
|
8639 | tag = buffer.readVarint32();
|
8640 | wireType = tag & 0x07;
|
8641 | id = tag >>> 3;
|
8642 | if (wireType === ProtoBuf.WIRE_TYPES.ENDGROUP) {
|
8643 | if (id !== expectedGroupEndId)
|
8644 | throw Error("Illegal group end indicator for "+this.toString(true)+": "+id+" ("+(expectedGroupEndId ? expectedGroupEndId+" expected" : "not a group")+")");
|
8645 | break;
|
8646 | }
|
8647 | if (!(field = this._fieldsById[id])) {
|
8648 |
|
8649 | switch (wireType) {
|
8650 | case ProtoBuf.WIRE_TYPES.VARINT:
|
8651 | buffer.readVarint32();
|
8652 | break;
|
8653 | case ProtoBuf.WIRE_TYPES.BITS32:
|
8654 | buffer.offset += 4;
|
8655 | break;
|
8656 | case ProtoBuf.WIRE_TYPES.BITS64:
|
8657 | buffer.offset += 8;
|
8658 | break;
|
8659 | case ProtoBuf.WIRE_TYPES.LDELIM:
|
8660 | var len = buffer.readVarint32();
|
8661 | buffer.offset += len;
|
8662 | break;
|
8663 | case ProtoBuf.WIRE_TYPES.STARTGROUP:
|
8664 | while (skipTillGroupEnd(id, buffer)) {}
|
8665 | break;
|
8666 | default:
|
8667 | throw Error("Illegal wire type for unknown field "+id+" in "+this.toString(true)+"#decode: "+wireType);
|
8668 | }
|
8669 | continue;
|
8670 | }
|
8671 | if (field.repeated && !field.options["packed"]) {
|
8672 | msg[field.name].push(field.decode(wireType, buffer));
|
8673 | } else if (field.map) {
|
8674 | var keyval = field.decode(wireType, buffer);
|
8675 | msg[field.name].set(keyval[0], keyval[1]);
|
8676 | } else {
|
8677 | msg[field.name] = field.decode(wireType, buffer);
|
8678 | if (field.oneof) {
|
8679 | var currentField = msg[field.oneof.name];
|
8680 | if (currentField !== null && currentField !== field.name)
|
8681 | msg[currentField] = null;
|
8682 | msg[field.oneof.name] = field.name;
|
8683 | }
|
8684 | }
|
8685 | }
|
8686 |
|
8687 |
|
8688 | for (var i=0, k=this._fields.length; i<k; ++i) {
|
8689 | field = this._fields[i];
|
8690 | if (msg[field.name] === null) {
|
8691 | if (this.syntax === "proto3") {
|
8692 | msg[field.name] = field.defaultValue;
|
8693 | } else if (field.required) {
|
8694 | var err = Error("Missing at least one required field for " + this.toString(true) + ": " + field.name);
|
8695 | err["decoded"] = msg;
|
8696 | throw(err);
|
8697 | } else if (ProtoBuf.populateDefaults && field.defaultValue !== null)
|
8698 | msg[field.name] = field.defaultValue;
|
8699 | }
|
8700 | }
|
8701 | return msg;
|
8702 | };
|
8703 |
|
8704 | |
8705 |
|
8706 |
|
8707 |
|
8708 | Reflect.Message = Message;
|
8709 |
|
8710 | |
8711 |
|
8712 |
|
8713 |
|
8714 |
|
8715 |
|
8716 |
|
8717 |
|
8718 |
|
8719 |
|
8720 |
|
8721 |
|
8722 |
|
8723 |
|
8724 |
|
8725 |
|
8726 | var Field = function(builder, message, rule, keytype, type, name, id, options, oneof, syntax) {
|
8727 | T.call(this, builder, message, name);
|
8728 |
|
8729 | |
8730 |
|
8731 |
|
8732 | this.className = "Message.Field";
|
8733 |
|
8734 | |
8735 |
|
8736 |
|
8737 |
|
8738 |
|
8739 | this.required = rule === "required";
|
8740 |
|
8741 | |
8742 |
|
8743 |
|
8744 |
|
8745 |
|
8746 | this.repeated = rule === "repeated";
|
8747 |
|
8748 | |
8749 |
|
8750 |
|
8751 |
|
8752 |
|
8753 | this.map = rule === "map";
|
8754 |
|
8755 | |
8756 |
|
8757 |
|
8758 |
|
8759 |
|
8760 |
|
8761 | this.keyType = keytype || null;
|
8762 |
|
8763 | |
8764 |
|
8765 |
|
8766 |
|
8767 |
|
8768 |
|
8769 | this.type = type;
|
8770 |
|
8771 | |
8772 |
|
8773 |
|
8774 |
|
8775 |
|
8776 | this.resolvedType = null;
|
8777 |
|
8778 | |
8779 |
|
8780 |
|
8781 |
|
8782 |
|
8783 | this.id = id;
|
8784 |
|
8785 | |
8786 |
|
8787 |
|
8788 |
|
8789 |
|
8790 |
|
8791 | this.options = options || {};
|
8792 |
|
8793 | |
8794 |
|
8795 |
|
8796 |
|
8797 |
|
8798 | this.defaultValue = null;
|
8799 |
|
8800 | |
8801 |
|
8802 |
|
8803 |
|
8804 |
|
8805 | this.oneof = oneof || null;
|
8806 |
|
8807 | |
8808 |
|
8809 |
|
8810 |
|
8811 |
|
8812 | this.syntax = syntax || 'proto2';
|
8813 |
|
8814 | |
8815 |
|
8816 |
|
8817 |
|
8818 |
|
8819 | this.originalName = this.name;
|
8820 |
|
8821 | |
8822 |
|
8823 |
|
8824 |
|
8825 |
|
8826 | this.element = null;
|
8827 |
|
8828 | |
8829 |
|
8830 |
|
8831 |
|
8832 |
|
8833 |
|
8834 | this.keyElement = null;
|
8835 |
|
8836 |
|
8837 | if (this.builder.options['convertFieldsToCamelCase'] && !(this instanceof Message.ExtensionField))
|
8838 | this.name = ProtoBuf.Util.toCamelCase(this.name);
|
8839 | };
|
8840 |
|
8841 | |
8842 |
|
8843 |
|
8844 |
|
8845 | var FieldPrototype = Field.prototype = Object.create(T.prototype);
|
8846 |
|
8847 | |
8848 |
|
8849 |
|
8850 |
|
8851 |
|
8852 | FieldPrototype.build = function() {
|
8853 | this.element = new Element(this.type, this.resolvedType, false, this.syntax, this.name);
|
8854 | if (this.map)
|
8855 | this.keyElement = new Element(this.keyType, undefined, true, this.syntax, this.name);
|
8856 |
|
8857 |
|
8858 |
|
8859 | if (this.syntax === 'proto3' && !this.repeated && !this.map)
|
8860 | this.defaultValue = Element.defaultFieldValue(this.type);
|
8861 |
|
8862 |
|
8863 | else if (typeof this.options['default'] !== 'undefined')
|
8864 | this.defaultValue = this.verifyValue(this.options['default']);
|
8865 | };
|
8866 |
|
8867 | |
8868 |
|
8869 |
|
8870 |
|
8871 |
|
8872 |
|
8873 |
|
8874 |
|
8875 | FieldPrototype.verifyValue = function(value, skipRepeated) {
|
8876 | skipRepeated = skipRepeated || false;
|
8877 | var self = this;
|
8878 | function fail(val, msg) {
|
8879 | throw Error("Illegal value for "+self.toString(true)+" of type "+self.type.name+": "+val+" ("+msg+")");
|
8880 | }
|
8881 | if (value === null) {
|
8882 | if (this.required)
|
8883 | fail(typeof value, "required");
|
8884 | if (this.syntax === 'proto3' && this.type !== ProtoBuf.TYPES["message"])
|
8885 | fail(typeof value, "proto3 field without field presence cannot be null");
|
8886 | return null;
|
8887 | }
|
8888 | var i;
|
8889 | if (this.repeated && !skipRepeated) {
|
8890 | if (!Array.isArray(value))
|
8891 | value = [value];
|
8892 | var res = [];
|
8893 | for (i=0; i<value.length; i++)
|
8894 | res.push(this.element.verifyValue(value[i]));
|
8895 | return res;
|
8896 | }
|
8897 | if (this.map && !skipRepeated) {
|
8898 | if (!(value instanceof ProtoBuf.Map)) {
|
8899 |
|
8900 | if (!(value instanceof Object)) {
|
8901 | fail(typeof value,
|
8902 | "expected ProtoBuf.Map or raw object for map field");
|
8903 | }
|
8904 | return new ProtoBuf.Map(this, value);
|
8905 | } else {
|
8906 | return value;
|
8907 | }
|
8908 | }
|
8909 |
|
8910 | if (!this.repeated && Array.isArray(value))
|
8911 | fail(typeof value, "no array expected");
|
8912 |
|
8913 | return this.element.verifyValue(value);
|
8914 | };
|
8915 |
|
8916 | |
8917 |
|
8918 |
|
8919 |
|
8920 |
|
8921 |
|
8922 |
|
8923 | FieldPrototype.hasWirePresence = function(value, message) {
|
8924 | if (this.syntax !== 'proto3')
|
8925 | return (value !== null);
|
8926 | if (this.oneof && message[this.oneof.name] === this.name)
|
8927 | return true;
|
8928 | switch (this.type) {
|
8929 | case ProtoBuf.TYPES["int32"]:
|
8930 | case ProtoBuf.TYPES["sint32"]:
|
8931 | case ProtoBuf.TYPES["sfixed32"]:
|
8932 | case ProtoBuf.TYPES["uint32"]:
|
8933 | case ProtoBuf.TYPES["fixed32"]:
|
8934 | return value !== 0;
|
8935 |
|
8936 | case ProtoBuf.TYPES["int64"]:
|
8937 | case ProtoBuf.TYPES["sint64"]:
|
8938 | case ProtoBuf.TYPES["sfixed64"]:
|
8939 | case ProtoBuf.TYPES["uint64"]:
|
8940 | case ProtoBuf.TYPES["fixed64"]:
|
8941 | return value.low !== 0 || value.high !== 0;
|
8942 |
|
8943 | case ProtoBuf.TYPES["bool"]:
|
8944 | return value;
|
8945 |
|
8946 | case ProtoBuf.TYPES["float"]:
|
8947 | case ProtoBuf.TYPES["double"]:
|
8948 | return value !== 0.0;
|
8949 |
|
8950 | case ProtoBuf.TYPES["string"]:
|
8951 | return value.length > 0;
|
8952 |
|
8953 | case ProtoBuf.TYPES["bytes"]:
|
8954 | return value.remaining() > 0;
|
8955 |
|
8956 | case ProtoBuf.TYPES["enum"]:
|
8957 | return value !== 0;
|
8958 |
|
8959 | case ProtoBuf.TYPES["message"]:
|
8960 | return value !== null;
|
8961 | default:
|
8962 | return true;
|
8963 | }
|
8964 | };
|
8965 |
|
8966 | |
8967 |
|
8968 |
|
8969 |
|
8970 |
|
8971 |
|
8972 |
|
8973 |
|
8974 |
|
8975 | FieldPrototype.encode = function(value, buffer, message) {
|
8976 | if (this.type === null || typeof this.type !== 'object')
|
8977 | throw Error("[INTERNAL] Unresolved type in "+this.toString(true)+": "+this.type);
|
8978 | if (value === null || (this.repeated && value.length == 0))
|
8979 | return buffer;
|
8980 | try {
|
8981 | if (this.repeated) {
|
8982 | var i;
|
8983 |
|
8984 |
|
8985 | if (this.options["packed"] && ProtoBuf.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType) >= 0) {
|
8986 |
|
8987 |
|
8988 |
|
8989 | buffer.writeVarint32((this.id << 3) | ProtoBuf.WIRE_TYPES.LDELIM);
|
8990 | buffer.ensureCapacity(buffer.offset += 1);
|
8991 | var start = buffer.offset;
|
8992 | for (i=0; i<value.length; i++)
|
8993 | this.element.encodeValue(this.id, value[i], buffer);
|
8994 | var len = buffer.offset-start,
|
8995 | varintLen = ByteBuffer.calculateVarint32(len);
|
8996 | if (varintLen > 1) {
|
8997 | var contents = buffer.slice(start, buffer.offset);
|
8998 | start += varintLen-1;
|
8999 | buffer.offset = start;
|
9000 | buffer.append(contents);
|
9001 | }
|
9002 | buffer.writeVarint32(len, start-varintLen);
|
9003 | } else {
|
9004 |
|
9005 |
|
9006 | for (i=0; i<value.length; i++)
|
9007 | buffer.writeVarint32((this.id << 3) | this.type.wireType),
|
9008 | this.element.encodeValue(this.id, value[i], buffer);
|
9009 | }
|
9010 | } else if (this.map) {
|
9011 |
|
9012 | value.forEach(function(val, key, m) {
|
9013 |
|
9014 | var length =
|
9015 | ByteBuffer.calculateVarint32((1 << 3) | this.keyType.wireType) +
|
9016 | this.keyElement.calculateLength(1, key) +
|
9017 | ByteBuffer.calculateVarint32((2 << 3) | this.type.wireType) +
|
9018 | this.element.calculateLength(2, val);
|
9019 |
|
9020 |
|
9021 | buffer.writeVarint32((this.id << 3) | ProtoBuf.WIRE_TYPES.LDELIM);
|
9022 | buffer.writeVarint32(length);
|
9023 |
|
9024 |
|
9025 | buffer.writeVarint32((1 << 3) | this.keyType.wireType);
|
9026 | this.keyElement.encodeValue(1, key, buffer);
|
9027 | buffer.writeVarint32((2 << 3) | this.type.wireType);
|
9028 | this.element.encodeValue(2, val, buffer);
|
9029 | }, this);
|
9030 | } else {
|
9031 | if (this.hasWirePresence(value, message)) {
|
9032 | buffer.writeVarint32((this.id << 3) | this.type.wireType);
|
9033 | this.element.encodeValue(this.id, value, buffer);
|
9034 | }
|
9035 | }
|
9036 | } catch (e) {
|
9037 | throw Error("Illegal value for "+this.toString(true)+": "+value+" ("+e+")");
|
9038 | }
|
9039 | return buffer;
|
9040 | };
|
9041 |
|
9042 | |
9043 |
|
9044 |
|
9045 |
|
9046 |
|
9047 |
|
9048 |
|
9049 | FieldPrototype.calculate = function(value, message) {
|
9050 | value = this.verifyValue(value);
|
9051 | if (this.type === null || typeof this.type !== 'object')
|
9052 | throw Error("[INTERNAL] Unresolved type in "+this.toString(true)+": "+this.type);
|
9053 | if (value === null || (this.repeated && value.length == 0))
|
9054 | return 0;
|
9055 | var n = 0;
|
9056 | try {
|
9057 | if (this.repeated) {
|
9058 | var i, ni;
|
9059 | if (this.options["packed"] && ProtoBuf.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType) >= 0) {
|
9060 | n += ByteBuffer.calculateVarint32((this.id << 3) | ProtoBuf.WIRE_TYPES.LDELIM);
|
9061 | ni = 0;
|
9062 | for (i=0; i<value.length; i++)
|
9063 | ni += this.element.calculateLength(this.id, value[i]);
|
9064 | n += ByteBuffer.calculateVarint32(ni);
|
9065 | n += ni;
|
9066 | } else {
|
9067 | for (i=0; i<value.length; i++)
|
9068 | n += ByteBuffer.calculateVarint32((this.id << 3) | this.type.wireType),
|
9069 | n += this.element.calculateLength(this.id, value[i]);
|
9070 | }
|
9071 | } else if (this.map) {
|
9072 |
|
9073 | value.forEach(function(val, key, m) {
|
9074 |
|
9075 | var length =
|
9076 | ByteBuffer.calculateVarint32((1 << 3) | this.keyType.wireType) +
|
9077 | this.keyElement.calculateLength(1, key) +
|
9078 | ByteBuffer.calculateVarint32((2 << 3) | this.type.wireType) +
|
9079 | this.element.calculateLength(2, val);
|
9080 |
|
9081 | n += ByteBuffer.calculateVarint32((this.id << 3) | ProtoBuf.WIRE_TYPES.LDELIM);
|
9082 | n += ByteBuffer.calculateVarint32(length);
|
9083 | n += length;
|
9084 | }, this);
|
9085 | } else {
|
9086 | if (this.hasWirePresence(value, message)) {
|
9087 | n += ByteBuffer.calculateVarint32((this.id << 3) | this.type.wireType);
|
9088 | n += this.element.calculateLength(this.id, value);
|
9089 | }
|
9090 | }
|
9091 | } catch (e) {
|
9092 | throw Error("Illegal value for "+this.toString(true)+": "+value+" ("+e+")");
|
9093 | }
|
9094 | return n;
|
9095 | };
|
9096 |
|
9097 | |
9098 |
|
9099 |
|
9100 |
|
9101 |
|
9102 |
|
9103 |
|
9104 |
|
9105 |
|
9106 |
|
9107 | FieldPrototype.decode = function(wireType, buffer, skipRepeated) {
|
9108 | var value, nBytes;
|
9109 |
|
9110 |
|
9111 |
|
9112 | var wireTypeOK =
|
9113 | (!this.map && wireType == this.type.wireType) ||
|
9114 | (!skipRepeated && this.repeated && this.options["packed"] &&
|
9115 | wireType == ProtoBuf.WIRE_TYPES.LDELIM) ||
|
9116 | (this.map && wireType == ProtoBuf.WIRE_TYPES.LDELIM);
|
9117 | if (!wireTypeOK)
|
9118 | throw Error("Illegal wire type for field "+this.toString(true)+": "+wireType+" ("+this.type.wireType+" expected)");
|
9119 |
|
9120 |
|
9121 | if (wireType == ProtoBuf.WIRE_TYPES.LDELIM && this.repeated && this.options["packed"] && ProtoBuf.PACKABLE_WIRE_TYPES.indexOf(this.type.wireType) >= 0) {
|
9122 | if (!skipRepeated) {
|
9123 | nBytes = buffer.readVarint32();
|
9124 | nBytes = buffer.offset + nBytes;
|
9125 | var values = [];
|
9126 | while (buffer.offset < nBytes)
|
9127 | values.push(this.decode(this.type.wireType, buffer, true));
|
9128 | return values;
|
9129 | }
|
9130 |
|
9131 | }
|
9132 |
|
9133 |
|
9134 | if (this.map) {
|
9135 |
|
9136 | var key = Element.defaultFieldValue(this.keyType);
|
9137 | value = Element.defaultFieldValue(this.type);
|
9138 |
|
9139 |
|
9140 | nBytes = buffer.readVarint32();
|
9141 | if (buffer.remaining() < nBytes)
|
9142 | throw Error("Illegal number of bytes for "+this.toString(true)+": "+nBytes+" required but got only "+buffer.remaining());
|
9143 |
|
9144 |
|
9145 | var msgbuf = buffer.clone();
|
9146 | msgbuf.limit = msgbuf.offset + nBytes;
|
9147 | buffer.offset += nBytes;
|
9148 |
|
9149 | while (msgbuf.remaining() > 0) {
|
9150 | var tag = msgbuf.readVarint32();
|
9151 | wireType = tag & 0x07;
|
9152 | var id = tag >>> 3;
|
9153 | if (id === 1) {
|
9154 | key = this.keyElement.decode(msgbuf, wireType, id);
|
9155 | } else if (id === 2) {
|
9156 | value = this.element.decode(msgbuf, wireType, id);
|
9157 | } else {
|
9158 | throw Error("Unexpected tag in map field key/value submessage");
|
9159 | }
|
9160 | }
|
9161 |
|
9162 | return [key, value];
|
9163 | }
|
9164 |
|
9165 |
|
9166 | return this.element.decode(buffer, wireType, this.id);
|
9167 | };
|
9168 |
|
9169 | |
9170 |
|
9171 |
|
9172 |
|
9173 | Reflect.Message.Field = Field;
|
9174 |
|
9175 | |
9176 |
|
9177 |
|
9178 |
|
9179 |
|
9180 |
|
9181 |
|
9182 |
|
9183 |
|
9184 |
|
9185 |
|
9186 |
|
9187 |
|
9188 | var ExtensionField = function(builder, message, rule, type, name, id, options) {
|
9189 | Field.call(this, builder, message, rule, null, type, name, id, options);
|
9190 |
|
9191 | |
9192 |
|
9193 |
|
9194 |
|
9195 |
|
9196 | this.extension;
|
9197 | };
|
9198 |
|
9199 |
|
9200 | ExtensionField.prototype = Object.create(Field.prototype);
|
9201 |
|
9202 | |
9203 |
|
9204 |
|
9205 |
|
9206 | Reflect.Message.ExtensionField = ExtensionField;
|
9207 |
|
9208 | |
9209 |
|
9210 |
|
9211 |
|
9212 |
|
9213 |
|
9214 |
|
9215 |
|
9216 |
|
9217 | var OneOf = function(builder, message, name) {
|
9218 | T.call(this, builder, message, name);
|
9219 |
|
9220 | |
9221 |
|
9222 |
|
9223 |
|
9224 |
|
9225 | this.fields = [];
|
9226 | };
|
9227 |
|
9228 | |
9229 |
|
9230 |
|
9231 |
|
9232 | Reflect.Message.OneOf = OneOf;
|
9233 |
|
9234 | |
9235 |
|
9236 |
|
9237 |
|
9238 |
|
9239 |
|
9240 |
|
9241 |
|
9242 |
|
9243 |
|
9244 |
|
9245 | var Enum = function(builder, parent, name, options, syntax) {
|
9246 | Namespace.call(this, builder, parent, name, options, syntax);
|
9247 |
|
9248 | |
9249 |
|
9250 |
|
9251 | this.className = "Enum";
|
9252 |
|
9253 | |
9254 |
|
9255 |
|
9256 |
|
9257 |
|
9258 | this.object = null;
|
9259 | };
|
9260 |
|
9261 | |
9262 |
|
9263 |
|
9264 |
|
9265 |
|
9266 |
|
9267 |
|
9268 | Enum.getName = function(enm, value) {
|
9269 | var keys = Object.keys(enm);
|
9270 | for (var i=0, key; i<keys.length; ++i)
|
9271 | if (enm[key = keys[i]] === value)
|
9272 | return key;
|
9273 | return null;
|
9274 | };
|
9275 |
|
9276 | |
9277 |
|
9278 |
|
9279 |
|
9280 | var EnumPrototype = Enum.prototype = Object.create(Namespace.prototype);
|
9281 |
|
9282 | |
9283 |
|
9284 |
|
9285 |
|
9286 |
|
9287 |
|
9288 | EnumPrototype.build = function(rebuild) {
|
9289 | if (this.object && !rebuild)
|
9290 | return this.object;
|
9291 | var enm = new ProtoBuf.Builder.Enum(),
|
9292 | values = this.getChildren(Enum.Value);
|
9293 | for (var i=0, k=values.length; i<k; ++i)
|
9294 | enm[values[i]['name']] = values[i]['id'];
|
9295 | if (Object.defineProperty)
|
9296 | Object.defineProperty(enm, '$options', {
|
9297 | "value": this.buildOpt(),
|
9298 | "enumerable": false
|
9299 | });
|
9300 | return this.object = enm;
|
9301 | };
|
9302 |
|
9303 | |
9304 |
|
9305 |
|
9306 |
|
9307 | Reflect.Enum = Enum;
|
9308 |
|
9309 | |
9310 |
|
9311 |
|
9312 |
|
9313 |
|
9314 |
|
9315 |
|
9316 |
|
9317 |
|
9318 |
|
9319 | var Value = function(builder, enm, name, id) {
|
9320 | T.call(this, builder, enm, name);
|
9321 |
|
9322 | |
9323 |
|
9324 |
|
9325 | this.className = "Enum.Value";
|
9326 |
|
9327 | |
9328 |
|
9329 |
|
9330 |
|
9331 |
|
9332 | this.id = id;
|
9333 | };
|
9334 |
|
9335 |
|
9336 | Value.prototype = Object.create(T.prototype);
|
9337 |
|
9338 | |
9339 |
|
9340 |
|
9341 |
|
9342 | Reflect.Enum.Value = Value;
|
9343 |
|
9344 | |
9345 |
|
9346 |
|
9347 |
|
9348 |
|
9349 |
|
9350 |
|
9351 |
|
9352 |
|
9353 | var Extension = function(builder, parent, name, field) {
|
9354 | T.call(this, builder, parent, name);
|
9355 |
|
9356 | |
9357 |
|
9358 |
|
9359 |
|
9360 |
|
9361 | this.field = field;
|
9362 | };
|
9363 |
|
9364 |
|
9365 | Extension.prototype = Object.create(T.prototype);
|
9366 |
|
9367 | |
9368 |
|
9369 |
|
9370 |
|
9371 | Reflect.Extension = Extension;
|
9372 |
|
9373 | |
9374 |
|
9375 |
|
9376 |
|
9377 |
|
9378 |
|
9379 |
|
9380 |
|
9381 |
|
9382 |
|
9383 | var Service = function(builder, root, name, options) {
|
9384 | Namespace.call(this, builder, root, name, options);
|
9385 |
|
9386 | |
9387 |
|
9388 |
|
9389 | this.className = "Service";
|
9390 |
|
9391 | |
9392 |
|
9393 |
|
9394 |
|
9395 | this.clazz = null;
|
9396 | };
|
9397 |
|
9398 | |
9399 |
|
9400 |
|
9401 |
|
9402 | var ServicePrototype = Service.prototype = Object.create(Namespace.prototype);
|
9403 |
|
9404 | |
9405 |
|
9406 |
|
9407 |
|
9408 |
|
9409 |
|
9410 |
|
9411 |
|
9412 | ServicePrototype.build = function(rebuild) {
|
9413 | if (this.clazz && !rebuild)
|
9414 | return this.clazz;
|
9415 |
|
9416 |
|
9417 | return this.clazz = (function(ProtoBuf, T) {
|
9418 |
|
9419 | |
9420 |
|
9421 |
|
9422 |
|
9423 |
|
9424 |
|
9425 |
|
9426 |
|
9427 | var Service = function(rpcImpl) {
|
9428 | ProtoBuf.Builder.Service.call(this);
|
9429 |
|
9430 | |
9431 |
|
9432 |
|
9433 |
|
9434 |
|
9435 |
|
9436 | this.rpcImpl = rpcImpl || function(name, msg, callback) {
|
9437 |
|
9438 |
|
9439 |
|
9440 | setTimeout(callback.bind(this, Error("Not implemented, see: https://github.com/dcodeIO/ProtoBuf.js/wiki/Services")), 0);
|
9441 | };
|
9442 | };
|
9443 |
|
9444 | |
9445 |
|
9446 |
|
9447 |
|
9448 | var ServicePrototype = Service.prototype = Object.create(ProtoBuf.Builder.Service.prototype);
|
9449 |
|
9450 | |
9451 |
|
9452 |
|
9453 |
|
9454 |
|
9455 |
|
9456 |
|
9457 |
|
9458 |
|
9459 |
|
9460 |
|
9461 | |
9462 |
|
9463 |
|
9464 |
|
9465 |
|
9466 |
|
9467 |
|
9468 |
|
9469 |
|
9470 |
|
9471 | var rpc = T.getChildren(ProtoBuf.Reflect.Service.RPCMethod);
|
9472 | for (var i=0; i<rpc.length; i++) {
|
9473 | (function(method) {
|
9474 |
|
9475 |
|
9476 | ServicePrototype[method.name] = function(req, callback) {
|
9477 | try {
|
9478 | try {
|
9479 |
|
9480 | req = method.resolvedRequestType.clazz.decode(ByteBuffer.wrap(req));
|
9481 | } catch (err) {
|
9482 | if (!(err instanceof TypeError))
|
9483 | throw err;
|
9484 | }
|
9485 | if (req === null || typeof req !== 'object')
|
9486 | throw Error("Illegal arguments");
|
9487 | if (!(req instanceof method.resolvedRequestType.clazz))
|
9488 | req = new method.resolvedRequestType.clazz(req);
|
9489 | this.rpcImpl(method.fqn(), req, function(err, res) {
|
9490 | if (err) {
|
9491 | callback(err);
|
9492 | return;
|
9493 | }
|
9494 |
|
9495 | if (res === null)
|
9496 | res = '';
|
9497 | try { res = method.resolvedResponseType.clazz.decode(res); } catch (notABuffer) {}
|
9498 | if (!res || !(res instanceof method.resolvedResponseType.clazz)) {
|
9499 | callback(Error("Illegal response type received in service method "+ T.name+"#"+method.name));
|
9500 | return;
|
9501 | }
|
9502 | callback(null, res);
|
9503 | });
|
9504 | } catch (err) {
|
9505 | setTimeout(callback.bind(this, err), 0);
|
9506 | }
|
9507 | };
|
9508 |
|
9509 |
|
9510 | Service[method.name] = function(rpcImpl, req, callback) {
|
9511 | new Service(rpcImpl)[method.name](req, callback);
|
9512 | };
|
9513 |
|
9514 | if (Object.defineProperty)
|
9515 | Object.defineProperty(Service[method.name], "$options", { "value": method.buildOpt() }),
|
9516 | Object.defineProperty(ServicePrototype[method.name], "$options", { "value": Service[method.name]["$options"] });
|
9517 | })(rpc[i]);
|
9518 | }
|
9519 |
|
9520 | if (Object.defineProperty)
|
9521 | Object.defineProperty(Service, "$options", { "value": T.buildOpt() }),
|
9522 | Object.defineProperty(ServicePrototype, "$options", { "value": Service["$options"] }),
|
9523 | Object.defineProperty(Service, "$type", { "value": T }),
|
9524 | Object.defineProperty(ServicePrototype, "$type", { "value": T });
|
9525 |
|
9526 | return Service;
|
9527 |
|
9528 | })(ProtoBuf, this);
|
9529 | };
|
9530 |
|
9531 | |
9532 |
|
9533 |
|
9534 |
|
9535 | Reflect.Service = Service;
|
9536 |
|
9537 | |
9538 |
|
9539 |
|
9540 |
|
9541 |
|
9542 |
|
9543 |
|
9544 |
|
9545 |
|
9546 |
|
9547 | var Method = function(builder, svc, name, options) {
|
9548 | T.call(this, builder, svc, name);
|
9549 |
|
9550 | |
9551 |
|
9552 |
|
9553 | this.className = "Service.Method";
|
9554 |
|
9555 | |
9556 |
|
9557 |
|
9558 |
|
9559 |
|
9560 | this.options = options || {};
|
9561 | };
|
9562 |
|
9563 | |
9564 |
|
9565 |
|
9566 |
|
9567 | var MethodPrototype = Method.prototype = Object.create(T.prototype);
|
9568 |
|
9569 | |
9570 |
|
9571 |
|
9572 |
|
9573 |
|
9574 |
|
9575 | MethodPrototype.buildOpt = NamespacePrototype.buildOpt;
|
9576 |
|
9577 | |
9578 |
|
9579 |
|
9580 |
|
9581 | Reflect.Service.Method = Method;
|
9582 |
|
9583 | |
9584 |
|
9585 |
|
9586 |
|
9587 |
|
9588 |
|
9589 |
|
9590 |
|
9591 |
|
9592 |
|
9593 |
|
9594 |
|
9595 |
|
9596 |
|
9597 | var RPCMethod = function(builder, svc, name, request, response, request_stream, response_stream, options) {
|
9598 | Method.call(this, builder, svc, name, options);
|
9599 |
|
9600 | |
9601 |
|
9602 |
|
9603 | this.className = "Service.RPCMethod";
|
9604 |
|
9605 | |
9606 |
|
9607 |
|
9608 |
|
9609 |
|
9610 | this.requestName = request;
|
9611 |
|
9612 | |
9613 |
|
9614 |
|
9615 |
|
9616 |
|
9617 | this.responseName = response;
|
9618 |
|
9619 | |
9620 |
|
9621 |
|
9622 |
|
9623 |
|
9624 | this.requestStream = request_stream;
|
9625 |
|
9626 | |
9627 |
|
9628 |
|
9629 |
|
9630 |
|
9631 | this.responseStream = response_stream;
|
9632 |
|
9633 | |
9634 |
|
9635 |
|
9636 |
|
9637 |
|
9638 | this.resolvedRequestType = null;
|
9639 |
|
9640 | |
9641 |
|
9642 |
|
9643 |
|
9644 |
|
9645 | this.resolvedResponseType = null;
|
9646 | };
|
9647 |
|
9648 |
|
9649 | RPCMethod.prototype = Object.create(Method.prototype);
|
9650 |
|
9651 | |
9652 |
|
9653 |
|
9654 |
|
9655 | Reflect.Service.RPCMethod = RPCMethod;
|
9656 |
|
9657 | return Reflect;
|
9658 |
|
9659 | })(ProtoBuf);
|
9660 |
|
9661 | |
9662 |
|
9663 |
|
9664 |
|
9665 | ProtoBuf.Builder = (function(ProtoBuf, Lang, Reflect) {
|
9666 |
|
9667 | |
9668 |
|
9669 |
|
9670 |
|
9671 |
|
9672 |
|
9673 |
|
9674 | var Builder = function(options) {
|
9675 |
|
9676 | |
9677 |
|
9678 |
|
9679 |
|
9680 |
|
9681 | this.ns = new Reflect.Namespace(this, null, "");
|
9682 |
|
9683 | |
9684 |
|
9685 |
|
9686 |
|
9687 |
|
9688 | this.ptr = this.ns;
|
9689 |
|
9690 | |
9691 |
|
9692 |
|
9693 |
|
9694 |
|
9695 | this.resolved = false;
|
9696 |
|
9697 | |
9698 |
|
9699 |
|
9700 |
|
9701 |
|
9702 | this.result = null;
|
9703 |
|
9704 | |
9705 |
|
9706 |
|
9707 |
|
9708 |
|
9709 | this.files = {};
|
9710 |
|
9711 | |
9712 |
|
9713 |
|
9714 |
|
9715 |
|
9716 | this.importRoot = null;
|
9717 |
|
9718 | |
9719 |
|
9720 |
|
9721 |
|
9722 |
|
9723 | this.options = options || {};
|
9724 | };
|
9725 |
|
9726 | |
9727 |
|
9728 |
|
9729 |
|
9730 | var BuilderPrototype = Builder.prototype;
|
9731 |
|
9732 |
|
9733 |
|
9734 | |
9735 |
|
9736 |
|
9737 |
|
9738 |
|
9739 |
|
9740 | Builder.isMessage = function(def) {
|
9741 |
|
9742 | if (typeof def["name"] !== 'string')
|
9743 | return false;
|
9744 |
|
9745 | if (typeof def["values"] !== 'undefined' || typeof def["rpc"] !== 'undefined')
|
9746 | return false;
|
9747 | return true;
|
9748 | };
|
9749 |
|
9750 | |
9751 |
|
9752 |
|
9753 |
|
9754 |
|
9755 |
|
9756 | Builder.isMessageField = function(def) {
|
9757 |
|
9758 | if (typeof def["rule"] !== 'string' || typeof def["name"] !== 'string' || typeof def["type"] !== 'string' || typeof def["id"] === 'undefined')
|
9759 | return false;
|
9760 | return true;
|
9761 | };
|
9762 |
|
9763 | |
9764 |
|
9765 |
|
9766 |
|
9767 |
|
9768 |
|
9769 | Builder.isEnum = function(def) {
|
9770 |
|
9771 | if (typeof def["name"] !== 'string')
|
9772 | return false;
|
9773 |
|
9774 | if (typeof def["values"] === 'undefined' || !Array.isArray(def["values"]) || def["values"].length === 0)
|
9775 | return false;
|
9776 | return true;
|
9777 | };
|
9778 |
|
9779 | |
9780 |
|
9781 |
|
9782 |
|
9783 |
|
9784 |
|
9785 | Builder.isService = function(def) {
|
9786 |
|
9787 | if (typeof def["name"] !== 'string' || typeof def["rpc"] !== 'object' || !def["rpc"])
|
9788 | return false;
|
9789 | return true;
|
9790 | };
|
9791 |
|
9792 | |
9793 |
|
9794 |
|
9795 |
|
9796 |
|
9797 |
|
9798 | Builder.isExtend = function(def) {
|
9799 |
|
9800 | if (typeof def["ref"] !== 'string')
|
9801 | return false;
|
9802 | return true;
|
9803 | };
|
9804 |
|
9805 |
|
9806 |
|
9807 | |
9808 |
|
9809 |
|
9810 |
|
9811 |
|
9812 | BuilderPrototype.reset = function() {
|
9813 | this.ptr = this.ns;
|
9814 | return this;
|
9815 | };
|
9816 |
|
9817 | |
9818 |
|
9819 |
|
9820 |
|
9821 |
|
9822 |
|
9823 | BuilderPrototype.define = function(namespace) {
|
9824 | if (typeof namespace !== 'string' || !Lang.TYPEREF.test(namespace))
|
9825 | throw Error("illegal namespace: "+namespace);
|
9826 | namespace.split(".").forEach(function(part) {
|
9827 | var ns = this.ptr.getChild(part);
|
9828 | if (ns === null)
|
9829 | this.ptr.addChild(ns = new Reflect.Namespace(this, this.ptr, part));
|
9830 | this.ptr = ns;
|
9831 | }, this);
|
9832 | return this;
|
9833 | };
|
9834 |
|
9835 | |
9836 |
|
9837 |
|
9838 |
|
9839 |
|
9840 |
|
9841 |
|
9842 | BuilderPrototype.create = function(defs) {
|
9843 | if (!defs)
|
9844 | return this;
|
9845 | if (!Array.isArray(defs))
|
9846 | defs = [defs];
|
9847 | else {
|
9848 | if (defs.length === 0)
|
9849 | return this;
|
9850 | defs = defs.slice();
|
9851 | }
|
9852 |
|
9853 |
|
9854 | var stack = [defs];
|
9855 | while (stack.length > 0) {
|
9856 | defs = stack.pop();
|
9857 |
|
9858 | if (!Array.isArray(defs))
|
9859 | throw Error("not a valid namespace: "+JSON.stringify(defs));
|
9860 |
|
9861 | while (defs.length > 0) {
|
9862 | var def = defs.shift();
|
9863 |
|
9864 | if (Builder.isMessage(def)) {
|
9865 | var obj = new Reflect.Message(this, this.ptr, def["name"], def["options"], def["isGroup"], def["syntax"]);
|
9866 |
|
9867 |
|
9868 | var oneofs = {};
|
9869 | if (def["oneofs"])
|
9870 | Object.keys(def["oneofs"]).forEach(function(name) {
|
9871 | obj.addChild(oneofs[name] = new Reflect.Message.OneOf(this, obj, name));
|
9872 | }, this);
|
9873 |
|
9874 |
|
9875 | if (def["fields"])
|
9876 | def["fields"].forEach(function(fld) {
|
9877 | if (obj.getChild(fld["id"]|0) !== null)
|
9878 | throw Error("duplicate or invalid field id in "+obj.name+": "+fld['id']);
|
9879 | if (fld["options"] && typeof fld["options"] !== 'object')
|
9880 | throw Error("illegal field options in "+obj.name+"#"+fld["name"]);
|
9881 | var oneof = null;
|
9882 | if (typeof fld["oneof"] === 'string' && !(oneof = oneofs[fld["oneof"]]))
|
9883 | throw Error("illegal oneof in "+obj.name+"#"+fld["name"]+": "+fld["oneof"]);
|
9884 | fld = new Reflect.Message.Field(this, obj, fld["rule"], fld["keytype"], fld["type"], fld["name"], fld["id"], fld["options"], oneof, def["syntax"]);
|
9885 | if (oneof)
|
9886 | oneof.fields.push(fld);
|
9887 | obj.addChild(fld);
|
9888 | }, this);
|
9889 |
|
9890 |
|
9891 | var subObj = [];
|
9892 | if (def["enums"])
|
9893 | def["enums"].forEach(function(enm) {
|
9894 | subObj.push(enm);
|
9895 | });
|
9896 | if (def["messages"])
|
9897 | def["messages"].forEach(function(msg) {
|
9898 | subObj.push(msg);
|
9899 | });
|
9900 | if (def["services"])
|
9901 | def["services"].forEach(function(svc) {
|
9902 | subObj.push(svc);
|
9903 | });
|
9904 |
|
9905 |
|
9906 | if (def["extensions"]) {
|
9907 | if (typeof def["extensions"][0] === 'number')
|
9908 | obj.extensions = [ def["extensions"] ];
|
9909 | else
|
9910 | obj.extensions = def["extensions"];
|
9911 | }
|
9912 |
|
9913 |
|
9914 | this.ptr.addChild(obj);
|
9915 | if (subObj.length > 0) {
|
9916 | stack.push(defs);
|
9917 | defs = subObj;
|
9918 | subObj = null;
|
9919 | this.ptr = obj;
|
9920 | obj = null;
|
9921 | continue;
|
9922 | }
|
9923 | subObj = null;
|
9924 |
|
9925 | } else if (Builder.isEnum(def)) {
|
9926 |
|
9927 | obj = new Reflect.Enum(this, this.ptr, def["name"], def["options"], def["syntax"]);
|
9928 | def["values"].forEach(function(val) {
|
9929 | obj.addChild(new Reflect.Enum.Value(this, obj, val["name"], val["id"]));
|
9930 | }, this);
|
9931 | this.ptr.addChild(obj);
|
9932 |
|
9933 | } else if (Builder.isService(def)) {
|
9934 |
|
9935 | obj = new Reflect.Service(this, this.ptr, def["name"], def["options"]);
|
9936 | Object.keys(def["rpc"]).forEach(function(name) {
|
9937 | var mtd = def["rpc"][name];
|
9938 | obj.addChild(new Reflect.Service.RPCMethod(this, obj, name, mtd["request"], mtd["response"], !!mtd["request_stream"], !!mtd["response_stream"], mtd["options"]));
|
9939 | }, this);
|
9940 | this.ptr.addChild(obj);
|
9941 |
|
9942 | } else if (Builder.isExtend(def)) {
|
9943 |
|
9944 | obj = this.ptr.resolve(def["ref"], true);
|
9945 | if (obj) {
|
9946 | def["fields"].forEach(function(fld) {
|
9947 | if (obj.getChild(fld['id']|0) !== null)
|
9948 | throw Error("duplicate extended field id in "+obj.name+": "+fld['id']);
|
9949 |
|
9950 | if (obj.extensions) {
|
9951 | var valid = false;
|
9952 | obj.extensions.forEach(function(range) {
|
9953 | if (fld["id"] >= range[0] && fld["id"] <= range[1])
|
9954 | valid = true;
|
9955 | });
|
9956 | if (!valid)
|
9957 | throw Error("illegal extended field id in "+obj.name+": "+fld['id']+" (not within valid ranges)");
|
9958 | }
|
9959 |
|
9960 | var name = fld["name"];
|
9961 | if (this.options['convertFieldsToCamelCase'])
|
9962 | name = ProtoBuf.Util.toCamelCase(name);
|
9963 |
|
9964 | var field = new Reflect.Message.ExtensionField(this, obj, fld["rule"], fld["type"], this.ptr.fqn()+'.'+name, fld["id"], fld["options"]);
|
9965 |
|
9966 |
|
9967 |
|
9968 | var ext = new Reflect.Extension(this, this.ptr, fld["name"], field);
|
9969 | field.extension = ext;
|
9970 | this.ptr.addChild(ext);
|
9971 | obj.addChild(field);
|
9972 | }, this);
|
9973 |
|
9974 | } else if (!/\.?google\.protobuf\./.test(def["ref"]))
|
9975 | throw Error("extended message "+def["ref"]+" is not defined");
|
9976 |
|
9977 | } else
|
9978 | throw Error("not a valid definition: "+JSON.stringify(def));
|
9979 |
|
9980 | def = null;
|
9981 | obj = null;
|
9982 | }
|
9983 |
|
9984 | defs = null;
|
9985 | this.ptr = this.ptr.parent;
|
9986 | }
|
9987 | this.resolved = false;
|
9988 | this.result = null;
|
9989 | return this;
|
9990 | };
|
9991 |
|
9992 | |
9993 |
|
9994 |
|
9995 |
|
9996 |
|
9997 | function propagateSyntax(parent) {
|
9998 | if (parent['messages']) {
|
9999 | parent['messages'].forEach(function(child) {
|
10000 | child["syntax"] = parent["syntax"];
|
10001 | propagateSyntax(child);
|
10002 | });
|
10003 | }
|
10004 | if (parent['enums']) {
|
10005 | parent['enums'].forEach(function(child) {
|
10006 | child["syntax"] = parent["syntax"];
|
10007 | });
|
10008 | }
|
10009 | }
|
10010 |
|
10011 | |
10012 |
|
10013 |
|
10014 |
|
10015 |
|
10016 |
|
10017 |
|
10018 |
|
10019 | BuilderPrototype["import"] = function(json, filename) {
|
10020 | var delim = '/';
|
10021 |
|
10022 |
|
10023 |
|
10024 | if (typeof filename === 'string') {
|
10025 |
|
10026 | if (ProtoBuf.Util.IS_NODE)
|
10027 | filename = require$$2['resolve'](filename);
|
10028 | if (this.files[filename] === true)
|
10029 | return this.reset();
|
10030 | this.files[filename] = true;
|
10031 |
|
10032 | } else if (typeof filename === 'object') {
|
10033 |
|
10034 | var root = filename.root;
|
10035 | if (ProtoBuf.Util.IS_NODE)
|
10036 | root = require$$2['resolve'](root);
|
10037 | if (root.indexOf("\\") >= 0 || filename.file.indexOf("\\") >= 0)
|
10038 | delim = '\\';
|
10039 | var fname;
|
10040 | if (ProtoBuf.Util.IS_NODE)
|
10041 | fname = require$$2['join'](root, filename.file);
|
10042 | else
|
10043 | fname = root + delim + filename.file;
|
10044 | if (this.files[fname] === true)
|
10045 | return this.reset();
|
10046 | this.files[fname] = true;
|
10047 | }
|
10048 |
|
10049 |
|
10050 |
|
10051 | if (json['imports'] && json['imports'].length > 0) {
|
10052 | var importRoot,
|
10053 | resetRoot = false;
|
10054 |
|
10055 | if (typeof filename === 'object') {
|
10056 |
|
10057 | this.importRoot = filename["root"]; resetRoot = true;
|
10058 | importRoot = this.importRoot;
|
10059 | filename = filename["file"];
|
10060 | if (importRoot.indexOf("\\") >= 0 || filename.indexOf("\\") >= 0)
|
10061 | delim = '\\';
|
10062 |
|
10063 | } else if (typeof filename === 'string') {
|
10064 |
|
10065 | if (this.importRoot)
|
10066 | importRoot = this.importRoot;
|
10067 | else {
|
10068 | if (filename.indexOf("/") >= 0) {
|
10069 | importRoot = filename.replace(/\/[^\/]*$/, "");
|
10070 | if ( importRoot === "")
|
10071 | importRoot = "/";
|
10072 | } else if (filename.indexOf("\\") >= 0) {
|
10073 | importRoot = filename.replace(/\\[^\\]*$/, "");
|
10074 | delim = '\\';
|
10075 | } else
|
10076 | importRoot = ".";
|
10077 | }
|
10078 |
|
10079 | } else
|
10080 | importRoot = null;
|
10081 |
|
10082 | for (var i=0; i<json['imports'].length; i++) {
|
10083 | if (typeof json['imports'][i] === 'string') {
|
10084 | if (!importRoot)
|
10085 | throw Error("cannot determine import root");
|
10086 | var importFilename = json['imports'][i];
|
10087 | if (importFilename === "google/protobuf/descriptor.proto")
|
10088 | continue;
|
10089 | if (ProtoBuf.Util.IS_NODE)
|
10090 | importFilename = require$$2['join'](importRoot, importFilename);
|
10091 | else
|
10092 | importFilename = importRoot + delim + importFilename;
|
10093 | if (this.files[importFilename] === true)
|
10094 | continue;
|
10095 | if (/\.proto$/i.test(importFilename) && !ProtoBuf.DotProto)
|
10096 | importFilename = importFilename.replace(/\.proto$/, ".json");
|
10097 | var contents = ProtoBuf.Util.fetch(importFilename);
|
10098 | if (contents === null)
|
10099 | throw Error("failed to import '"+importFilename+"' in '"+filename+"': file not found");
|
10100 | if (/\.json$/i.test(importFilename))
|
10101 | this["import"](JSON.parse(contents+""), importFilename);
|
10102 | else
|
10103 | this["import"](ProtoBuf.DotProto.Parser.parse(contents), importFilename);
|
10104 | } else
|
10105 | if (!filename)
|
10106 | this["import"](json['imports'][i]);
|
10107 | else if (/\.(\w+)$/.test(filename))
|
10108 | this["import"](json['imports'][i], filename.replace(/^(.+)\.(\w+)$/, function($0, $1, $2) { return $1+"_import"+i+"."+$2; }));
|
10109 | else
|
10110 | this["import"](json['imports'][i], filename+"_import"+i);
|
10111 | }
|
10112 | if (resetRoot)
|
10113 | this.importRoot = null;
|
10114 | }
|
10115 |
|
10116 |
|
10117 |
|
10118 | if (json['package'])
|
10119 | this.define(json['package']);
|
10120 | if (json['syntax'])
|
10121 | propagateSyntax(json);
|
10122 | var base = this.ptr;
|
10123 | if (json['options'])
|
10124 | Object.keys(json['options']).forEach(function(key) {
|
10125 | base.options[key] = json['options'][key];
|
10126 | });
|
10127 | if (json['messages'])
|
10128 | this.create(json['messages']),
|
10129 | this.ptr = base;
|
10130 | if (json['enums'])
|
10131 | this.create(json['enums']),
|
10132 | this.ptr = base;
|
10133 | if (json['services'])
|
10134 | this.create(json['services']),
|
10135 | this.ptr = base;
|
10136 | if (json['extends'])
|
10137 | this.create(json['extends']);
|
10138 |
|
10139 | return this.reset();
|
10140 | };
|
10141 |
|
10142 | |
10143 |
|
10144 |
|
10145 |
|
10146 |
|
10147 |
|
10148 | BuilderPrototype.resolveAll = function() {
|
10149 |
|
10150 | var res;
|
10151 | if (this.ptr == null || typeof this.ptr.type === 'object')
|
10152 | return this;
|
10153 |
|
10154 | if (this.ptr instanceof Reflect.Namespace) {
|
10155 |
|
10156 | this.ptr.children.forEach(function(child) {
|
10157 | this.ptr = child;
|
10158 | this.resolveAll();
|
10159 | }, this);
|
10160 |
|
10161 | } else if (this.ptr instanceof Reflect.Message.Field) {
|
10162 |
|
10163 | if (!Lang.TYPE.test(this.ptr.type)) {
|
10164 | if (!Lang.TYPEREF.test(this.ptr.type))
|
10165 | throw Error("illegal type reference in "+this.ptr.toString(true)+": "+this.ptr.type);
|
10166 | res = (this.ptr instanceof Reflect.Message.ExtensionField ? this.ptr.extension.parent : this.ptr.parent).resolve(this.ptr.type, true);
|
10167 | if (!res)
|
10168 | throw Error("unresolvable type reference in "+this.ptr.toString(true)+": "+this.ptr.type);
|
10169 | this.ptr.resolvedType = res;
|
10170 | if (res instanceof Reflect.Enum) {
|
10171 | this.ptr.type = ProtoBuf.TYPES["enum"];
|
10172 | if (this.ptr.syntax === 'proto3' && res.syntax !== 'proto3')
|
10173 | throw Error("proto3 message cannot reference proto2 enum");
|
10174 | }
|
10175 | else if (res instanceof Reflect.Message)
|
10176 | this.ptr.type = res.isGroup ? ProtoBuf.TYPES["group"] : ProtoBuf.TYPES["message"];
|
10177 | else
|
10178 | throw Error("illegal type reference in "+this.ptr.toString(true)+": "+this.ptr.type);
|
10179 | } else
|
10180 | this.ptr.type = ProtoBuf.TYPES[this.ptr.type];
|
10181 |
|
10182 |
|
10183 |
|
10184 | if (this.ptr.map) {
|
10185 | if (!Lang.TYPE.test(this.ptr.keyType))
|
10186 | throw Error("illegal key type for map field in "+this.ptr.toString(true)+": "+this.ptr.keyType);
|
10187 | this.ptr.keyType = ProtoBuf.TYPES[this.ptr.keyType];
|
10188 | }
|
10189 |
|
10190 |
|
10191 |
|
10192 | if (
|
10193 | this.ptr.syntax === 'proto3' &&
|
10194 | this.ptr.repeated && this.ptr.options.packed === undefined &&
|
10195 | ProtoBuf.PACKABLE_WIRE_TYPES.indexOf(this.ptr.type.wireType) !== -1
|
10196 | ) {
|
10197 | this.ptr.options.packed = true;
|
10198 | }
|
10199 |
|
10200 | } else if (this.ptr instanceof ProtoBuf.Reflect.Service.Method) {
|
10201 |
|
10202 | if (this.ptr instanceof ProtoBuf.Reflect.Service.RPCMethod) {
|
10203 | res = this.ptr.parent.resolve(this.ptr.requestName, true);
|
10204 | if (!res || !(res instanceof ProtoBuf.Reflect.Message))
|
10205 | throw Error("Illegal type reference in "+this.ptr.toString(true)+": "+this.ptr.requestName);
|
10206 | this.ptr.resolvedRequestType = res;
|
10207 | res = this.ptr.parent.resolve(this.ptr.responseName, true);
|
10208 | if (!res || !(res instanceof ProtoBuf.Reflect.Message))
|
10209 | throw Error("Illegal type reference in "+this.ptr.toString(true)+": "+this.ptr.responseName);
|
10210 | this.ptr.resolvedResponseType = res;
|
10211 | } else
|
10212 | throw Error("illegal service type in "+this.ptr.toString(true));
|
10213 |
|
10214 | } else if (
|
10215 | !(this.ptr instanceof ProtoBuf.Reflect.Message.OneOf) &&
|
10216 | !(this.ptr instanceof ProtoBuf.Reflect.Extension) &&
|
10217 | !(this.ptr instanceof ProtoBuf.Reflect.Enum.Value)
|
10218 | )
|
10219 | throw Error("illegal object in namespace: "+typeof(this.ptr)+": "+this.ptr);
|
10220 |
|
10221 | return this.reset();
|
10222 | };
|
10223 |
|
10224 | |
10225 |
|
10226 |
|
10227 |
|
10228 |
|
10229 |
|
10230 |
|
10231 |
|
10232 | BuilderPrototype.build = function(path) {
|
10233 | this.reset();
|
10234 | if (!this.resolved)
|
10235 | this.resolveAll(),
|
10236 | this.resolved = true,
|
10237 | this.result = null;
|
10238 | if (this.result === null)
|
10239 | this.result = this.ns.build();
|
10240 | if (!path)
|
10241 | return this.result;
|
10242 | var part = typeof path === 'string' ? path.split(".") : path,
|
10243 | ptr = this.result;
|
10244 | for (var i=0; i<part.length; i++)
|
10245 | if (ptr[part[i]])
|
10246 | ptr = ptr[part[i]];
|
10247 | else {
|
10248 | ptr = null;
|
10249 | break;
|
10250 | }
|
10251 | return ptr;
|
10252 | };
|
10253 |
|
10254 | |
10255 |
|
10256 |
|
10257 |
|
10258 |
|
10259 |
|
10260 | BuilderPrototype.lookup = function(path, excludeNonNamespace) {
|
10261 | return path ? this.ns.resolve(path, excludeNonNamespace) : this.ns;
|
10262 | };
|
10263 |
|
10264 | |
10265 |
|
10266 |
|
10267 |
|
10268 |
|
10269 | BuilderPrototype.toString = function() {
|
10270 | return "Builder";
|
10271 | };
|
10272 |
|
10273 |
|
10274 |
|
10275 |
|
10276 | |
10277 |
|
10278 |
|
10279 | Builder.Message = function() {};
|
10280 |
|
10281 | |
10282 |
|
10283 |
|
10284 | Builder.Enum = function() {};
|
10285 |
|
10286 | |
10287 |
|
10288 |
|
10289 | Builder.Service = function() {};
|
10290 |
|
10291 | return Builder;
|
10292 |
|
10293 | })(ProtoBuf, ProtoBuf.Lang, ProtoBuf.Reflect);
|
10294 |
|
10295 | |
10296 |
|
10297 |
|
10298 |
|
10299 | ProtoBuf.Map = (function(ProtoBuf, Reflect) {
|
10300 |
|
10301 | |
10302 |
|
10303 |
|
10304 |
|
10305 |
|
10306 |
|
10307 |
|
10308 |
|
10309 |
|
10310 |
|
10311 |
|
10312 | var Map = function(field, contents) {
|
10313 | if (!field.map)
|
10314 | throw Error("field is not a map");
|
10315 |
|
10316 | |
10317 |
|
10318 |
|
10319 |
|
10320 | this.field = field;
|
10321 |
|
10322 | |
10323 |
|
10324 |
|
10325 |
|
10326 | this.keyElem = new Reflect.Element(field.keyType, null, true, field.syntax);
|
10327 |
|
10328 | |
10329 |
|
10330 |
|
10331 |
|
10332 | this.valueElem = new Reflect.Element(field.type, field.resolvedType, false, field.syntax);
|
10333 |
|
10334 | |
10335 |
|
10336 |
|
10337 |
|
10338 |
|
10339 |
|
10340 |
|
10341 |
|
10342 |
|
10343 |
|
10344 |
|
10345 |
|
10346 |
|
10347 |
|
10348 | this.map = {};
|
10349 |
|
10350 | |
10351 |
|
10352 |
|
10353 | Object.defineProperty(this, "size", {
|
10354 | get: function() { return Object.keys(this.map).length; }
|
10355 | });
|
10356 |
|
10357 |
|
10358 | if (contents) {
|
10359 | var keys = Object.keys(contents);
|
10360 | for (var i = 0; i < keys.length; i++) {
|
10361 | var key = this.keyElem.valueFromString(keys[i]);
|
10362 | var val = this.valueElem.verifyValue(contents[keys[i]]);
|
10363 | this.map[this.keyElem.valueToString(key)] =
|
10364 | { key: key, value: val };
|
10365 | }
|
10366 | }
|
10367 | };
|
10368 |
|
10369 | var MapPrototype = Map.prototype;
|
10370 |
|
10371 | |
10372 |
|
10373 |
|
10374 |
|
10375 |
|
10376 |
|
10377 | function arrayIterator(arr) {
|
10378 | var idx = 0;
|
10379 | return {
|
10380 | next: function() {
|
10381 | if (idx < arr.length)
|
10382 | return { done: false, value: arr[idx++] };
|
10383 | return { done: true };
|
10384 | }
|
10385 | }
|
10386 | }
|
10387 |
|
10388 | |
10389 |
|
10390 |
|
10391 | MapPrototype.clear = function() {
|
10392 | this.map = {};
|
10393 | };
|
10394 |
|
10395 | |
10396 |
|
10397 |
|
10398 |
|
10399 | MapPrototype["delete"] = function(key) {
|
10400 | var keyValue = this.keyElem.valueToString(this.keyElem.verifyValue(key));
|
10401 | var hadKey = keyValue in this.map;
|
10402 | delete this.map[keyValue];
|
10403 | return hadKey;
|
10404 | };
|
10405 |
|
10406 | |
10407 |
|
10408 |
|
10409 |
|
10410 | MapPrototype.entries = function() {
|
10411 | var entries = [];
|
10412 | var strKeys = Object.keys(this.map);
|
10413 | for (var i = 0, entry; i < strKeys.length; i++)
|
10414 | entries.push([(entry=this.map[strKeys[i]]).key, entry.value]);
|
10415 | return arrayIterator(entries);
|
10416 | };
|
10417 |
|
10418 | |
10419 |
|
10420 |
|
10421 |
|
10422 | MapPrototype.keys = function() {
|
10423 | var keys = [];
|
10424 | var strKeys = Object.keys(this.map);
|
10425 | for (var i = 0; i < strKeys.length; i++)
|
10426 | keys.push(this.map[strKeys[i]].key);
|
10427 | return arrayIterator(keys);
|
10428 | };
|
10429 |
|
10430 | |
10431 |
|
10432 |
|
10433 |
|
10434 | MapPrototype.values = function() {
|
10435 | var values = [];
|
10436 | var strKeys = Object.keys(this.map);
|
10437 | for (var i = 0; i < strKeys.length; i++)
|
10438 | values.push(this.map[strKeys[i]].value);
|
10439 | return arrayIterator(values);
|
10440 | };
|
10441 |
|
10442 | |
10443 |
|
10444 |
|
10445 |
|
10446 |
|
10447 | MapPrototype.forEach = function(cb, thisArg) {
|
10448 | var strKeys = Object.keys(this.map);
|
10449 | for (var i = 0, entry; i < strKeys.length; i++)
|
10450 | cb.call(thisArg, (entry=this.map[strKeys[i]]).value, entry.key, this);
|
10451 | };
|
10452 |
|
10453 | |
10454 |
|
10455 |
|
10456 |
|
10457 |
|
10458 |
|
10459 | MapPrototype.set = function(key, value) {
|
10460 | var keyValue = this.keyElem.verifyValue(key);
|
10461 | var valValue = this.valueElem.verifyValue(value);
|
10462 | this.map[this.keyElem.valueToString(keyValue)] =
|
10463 | { key: keyValue, value: valValue };
|
10464 | return this;
|
10465 | };
|
10466 |
|
10467 | |
10468 |
|
10469 |
|
10470 |
|
10471 |
|
10472 | MapPrototype.get = function(key) {
|
10473 | var keyValue = this.keyElem.valueToString(this.keyElem.verifyValue(key));
|
10474 | if (!(keyValue in this.map))
|
10475 | return undefined;
|
10476 | return this.map[keyValue].value;
|
10477 | };
|
10478 |
|
10479 | |
10480 |
|
10481 |
|
10482 |
|
10483 |
|
10484 | MapPrototype.has = function(key) {
|
10485 | var keyValue = this.keyElem.valueToString(this.keyElem.verifyValue(key));
|
10486 | return (keyValue in this.map);
|
10487 | };
|
10488 |
|
10489 | return Map;
|
10490 | })(ProtoBuf, ProtoBuf.Reflect);
|
10491 |
|
10492 |
|
10493 | |
10494 |
|
10495 |
|
10496 |
|
10497 |
|
10498 |
|
10499 | ProtoBuf.newBuilder = function(options) {
|
10500 | options = options || {};
|
10501 | if (typeof options['convertFieldsToCamelCase'] === 'undefined')
|
10502 | options['convertFieldsToCamelCase'] = ProtoBuf.convertFieldsToCamelCase;
|
10503 | if (typeof options['populateAccessors'] === 'undefined')
|
10504 | options['populateAccessors'] = ProtoBuf.populateAccessors;
|
10505 | return new ProtoBuf.Builder(options);
|
10506 | };
|
10507 |
|
10508 | |
10509 |
|
10510 |
|
10511 |
|
10512 |
|
10513 |
|
10514 |
|
10515 |
|
10516 |
|
10517 | ProtoBuf.loadJson = function(json, builder, filename) {
|
10518 | if (typeof builder === 'string' || (builder && typeof builder["file"] === 'string' && typeof builder["root"] === 'string'))
|
10519 | filename = builder,
|
10520 | builder = null;
|
10521 | if (!builder || typeof builder !== 'object')
|
10522 | builder = ProtoBuf.newBuilder();
|
10523 | if (typeof json === 'string')
|
10524 | json = JSON.parse(json);
|
10525 | builder["import"](json, filename);
|
10526 | builder.resolveAll();
|
10527 | return builder;
|
10528 | };
|
10529 |
|
10530 | |
10531 |
|
10532 |
|
10533 |
|
10534 |
|
10535 |
|
10536 |
|
10537 |
|
10538 |
|
10539 |
|
10540 |
|
10541 |
|
10542 | ProtoBuf.loadJsonFile = function(filename, callback, builder) {
|
10543 | if (callback && typeof callback === 'object')
|
10544 | builder = callback,
|
10545 | callback = null;
|
10546 | else if (!callback || typeof callback !== 'function')
|
10547 | callback = null;
|
10548 | if (callback)
|
10549 | return ProtoBuf.Util.fetch(typeof filename === 'string' ? filename : filename["root"]+"/"+filename["file"], function(contents) {
|
10550 | if (contents === null) {
|
10551 | callback(Error("Failed to fetch file"));
|
10552 | return;
|
10553 | }
|
10554 | try {
|
10555 | callback(null, ProtoBuf.loadJson(JSON.parse(contents), builder, filename));
|
10556 | } catch (e) {
|
10557 | callback(e);
|
10558 | }
|
10559 | });
|
10560 | var contents = ProtoBuf.Util.fetch(typeof filename === 'object' ? filename["root"]+"/"+filename["file"] : filename);
|
10561 | return contents === null ? null : ProtoBuf.loadJson(JSON.parse(contents), builder, filename);
|
10562 | };
|
10563 |
|
10564 | return ProtoBuf;
|
10565 | });
|
10566 | });
|
10567 |
|
10568 | var messageCompiled = protobufLight.newBuilder({})['import']({
|
10569 | package: 'push_server.messages2',
|
10570 | syntax: 'proto2',
|
10571 | options: {
|
10572 | objc_class_prefix: 'AVIM'
|
10573 | },
|
10574 | messages: [{
|
10575 | name: 'JsonObjectMessage',
|
10576 | syntax: 'proto2',
|
10577 | fields: [{
|
10578 | rule: 'required',
|
10579 | type: 'string',
|
10580 | name: 'data',
|
10581 | id: 1
|
10582 | }]
|
10583 | }, {
|
10584 | name: 'UnreadTuple',
|
10585 | syntax: 'proto2',
|
10586 | fields: [{
|
10587 | rule: 'required',
|
10588 | type: 'string',
|
10589 | name: 'cid',
|
10590 | id: 1
|
10591 | }, {
|
10592 | rule: 'required',
|
10593 | type: 'int32',
|
10594 | name: 'unread',
|
10595 | id: 2
|
10596 | }, {
|
10597 | rule: 'optional',
|
10598 | type: 'string',
|
10599 | name: 'mid',
|
10600 | id: 3
|
10601 | }, {
|
10602 | rule: 'optional',
|
10603 | type: 'int64',
|
10604 | name: 'timestamp',
|
10605 | id: 4
|
10606 | }, {
|
10607 | rule: 'optional',
|
10608 | type: 'string',
|
10609 | name: 'from',
|
10610 | id: 5
|
10611 | }, {
|
10612 | rule: 'optional',
|
10613 | type: 'string',
|
10614 | name: 'data',
|
10615 | id: 6
|
10616 | }, {
|
10617 | rule: 'optional',
|
10618 | type: 'int64',
|
10619 | name: 'patchTimestamp',
|
10620 | id: 7
|
10621 | }, {
|
10622 | rule: 'optional',
|
10623 | type: 'bool',
|
10624 | name: 'mentioned',
|
10625 | id: 8
|
10626 | }, {
|
10627 | rule: 'optional',
|
10628 | type: 'bytes',
|
10629 | name: 'binaryMsg',
|
10630 | id: 9
|
10631 | }, {
|
10632 | rule: 'optional',
|
10633 | type: 'int32',
|
10634 | name: 'convType',
|
10635 | id: 10
|
10636 | }]
|
10637 | }, {
|
10638 | name: 'LogItem',
|
10639 | syntax: 'proto2',
|
10640 | fields: [{
|
10641 | rule: 'optional',
|
10642 | type: 'string',
|
10643 | name: 'from',
|
10644 | id: 1
|
10645 | }, {
|
10646 | rule: 'optional',
|
10647 | type: 'string',
|
10648 | name: 'data',
|
10649 | id: 2
|
10650 | }, {
|
10651 | rule: 'optional',
|
10652 | type: 'int64',
|
10653 | name: 'timestamp',
|
10654 | id: 3
|
10655 | }, {
|
10656 | rule: 'optional',
|
10657 | type: 'string',
|
10658 | name: 'msgId',
|
10659 | id: 4
|
10660 | }, {
|
10661 | rule: 'optional',
|
10662 | type: 'int64',
|
10663 | name: 'ackAt',
|
10664 | id: 5
|
10665 | }, {
|
10666 | rule: 'optional',
|
10667 | type: 'int64',
|
10668 | name: 'readAt',
|
10669 | id: 6
|
10670 | }, {
|
10671 | rule: 'optional',
|
10672 | type: 'int64',
|
10673 | name: 'patchTimestamp',
|
10674 | id: 7
|
10675 | }, {
|
10676 | rule: 'optional',
|
10677 | type: 'bool',
|
10678 | name: 'mentionAll',
|
10679 | id: 8
|
10680 | }, {
|
10681 | rule: 'repeated',
|
10682 | type: 'string',
|
10683 | name: 'mentionPids',
|
10684 | id: 9
|
10685 | }, {
|
10686 | rule: 'optional',
|
10687 | type: 'bool',
|
10688 | name: 'bin',
|
10689 | id: 10
|
10690 | }, {
|
10691 | rule: 'optional',
|
10692 | type: 'int32',
|
10693 | name: 'convType',
|
10694 | id: 11
|
10695 | }]
|
10696 | }, {
|
10697 | name: 'ConvMemberInfo',
|
10698 | syntax: 'proto2',
|
10699 | fields: [{
|
10700 | rule: 'optional',
|
10701 | type: 'string',
|
10702 | name: 'pid',
|
10703 | id: 1
|
10704 | }, {
|
10705 | rule: 'optional',
|
10706 | type: 'string',
|
10707 | name: 'role',
|
10708 | id: 2
|
10709 | }, {
|
10710 | rule: 'optional',
|
10711 | type: 'string',
|
10712 | name: 'infoId',
|
10713 | id: 3
|
10714 | }]
|
10715 | }, {
|
10716 | name: 'DataCommand',
|
10717 | syntax: 'proto2',
|
10718 | fields: [{
|
10719 | rule: 'repeated',
|
10720 | type: 'string',
|
10721 | name: 'ids',
|
10722 | id: 1
|
10723 | }, {
|
10724 | rule: 'repeated',
|
10725 | type: 'JsonObjectMessage',
|
10726 | name: 'msg',
|
10727 | id: 2
|
10728 | }, {
|
10729 | rule: 'optional',
|
10730 | type: 'bool',
|
10731 | name: 'offline',
|
10732 | id: 3
|
10733 | }]
|
10734 | }, {
|
10735 | name: 'SessionCommand',
|
10736 | syntax: 'proto2',
|
10737 | fields: [{
|
10738 | rule: 'optional',
|
10739 | type: 'int64',
|
10740 | name: 't',
|
10741 | id: 1
|
10742 | }, {
|
10743 | rule: 'optional',
|
10744 | type: 'string',
|
10745 | name: 'n',
|
10746 | id: 2
|
10747 | }, {
|
10748 | rule: 'optional',
|
10749 | type: 'string',
|
10750 | name: 's',
|
10751 | id: 3
|
10752 | }, {
|
10753 | rule: 'optional',
|
10754 | type: 'string',
|
10755 | name: 'ua',
|
10756 | id: 4
|
10757 | }, {
|
10758 | rule: 'optional',
|
10759 | type: 'bool',
|
10760 | name: 'r',
|
10761 | id: 5
|
10762 | }, {
|
10763 | rule: 'optional',
|
10764 | type: 'string',
|
10765 | name: 'tag',
|
10766 | id: 6
|
10767 | }, {
|
10768 | rule: 'optional',
|
10769 | type: 'string',
|
10770 | name: 'deviceId',
|
10771 | id: 7
|
10772 | }, {
|
10773 | rule: 'repeated',
|
10774 | type: 'string',
|
10775 | name: 'sessionPeerIds',
|
10776 | id: 8
|
10777 | }, {
|
10778 | rule: 'repeated',
|
10779 | type: 'string',
|
10780 | name: 'onlineSessionPeerIds',
|
10781 | id: 9
|
10782 | }, {
|
10783 | rule: 'optional',
|
10784 | type: 'string',
|
10785 | name: 'st',
|
10786 | id: 10
|
10787 | }, {
|
10788 | rule: 'optional',
|
10789 | type: 'int32',
|
10790 | name: 'stTtl',
|
10791 | id: 11
|
10792 | }, {
|
10793 | rule: 'optional',
|
10794 | type: 'int32',
|
10795 | name: 'code',
|
10796 | id: 12
|
10797 | }, {
|
10798 | rule: 'optional',
|
10799 | type: 'string',
|
10800 | name: 'reason',
|
10801 | id: 13
|
10802 | }, {
|
10803 | rule: 'optional',
|
10804 | type: 'string',
|
10805 | name: 'deviceToken',
|
10806 | id: 14
|
10807 | }, {
|
10808 | rule: 'optional',
|
10809 | type: 'bool',
|
10810 | name: 'sp',
|
10811 | id: 15
|
10812 | }, {
|
10813 | rule: 'optional',
|
10814 | type: 'string',
|
10815 | name: 'detail',
|
10816 | id: 16
|
10817 | }, {
|
10818 | rule: 'optional',
|
10819 | type: 'int64',
|
10820 | name: 'lastUnreadNotifTime',
|
10821 | id: 17
|
10822 | }, {
|
10823 | rule: 'optional',
|
10824 | type: 'int64',
|
10825 | name: 'lastPatchTime',
|
10826 | id: 18
|
10827 | }, {
|
10828 | rule: 'optional',
|
10829 | type: 'int64',
|
10830 | name: 'configBitmap',
|
10831 | id: 19
|
10832 | }]
|
10833 | }, {
|
10834 | name: 'ErrorCommand',
|
10835 | syntax: 'proto2',
|
10836 | fields: [{
|
10837 | rule: 'required',
|
10838 | type: 'int32',
|
10839 | name: 'code',
|
10840 | id: 1
|
10841 | }, {
|
10842 | rule: 'required',
|
10843 | type: 'string',
|
10844 | name: 'reason',
|
10845 | id: 2
|
10846 | }, {
|
10847 | rule: 'optional',
|
10848 | type: 'int32',
|
10849 | name: 'appCode',
|
10850 | id: 3
|
10851 | }, {
|
10852 | rule: 'optional',
|
10853 | type: 'string',
|
10854 | name: 'detail',
|
10855 | id: 4
|
10856 | }, {
|
10857 | rule: 'repeated',
|
10858 | type: 'string',
|
10859 | name: 'pids',
|
10860 | id: 5
|
10861 | }, {
|
10862 | rule: 'optional',
|
10863 | type: 'string',
|
10864 | name: 'appMsg',
|
10865 | id: 6
|
10866 | }]
|
10867 | }, {
|
10868 | name: 'DirectCommand',
|
10869 | syntax: 'proto2',
|
10870 | fields: [{
|
10871 | rule: 'optional',
|
10872 | type: 'string',
|
10873 | name: 'msg',
|
10874 | id: 1
|
10875 | }, {
|
10876 | rule: 'optional',
|
10877 | type: 'string',
|
10878 | name: 'uid',
|
10879 | id: 2
|
10880 | }, {
|
10881 | rule: 'optional',
|
10882 | type: 'string',
|
10883 | name: 'fromPeerId',
|
10884 | id: 3
|
10885 | }, {
|
10886 | rule: 'optional',
|
10887 | type: 'int64',
|
10888 | name: 'timestamp',
|
10889 | id: 4
|
10890 | }, {
|
10891 | rule: 'optional',
|
10892 | type: 'bool',
|
10893 | name: 'offline',
|
10894 | id: 5
|
10895 | }, {
|
10896 | rule: 'optional',
|
10897 | type: 'bool',
|
10898 | name: 'hasMore',
|
10899 | id: 6
|
10900 | }, {
|
10901 | rule: 'repeated',
|
10902 | type: 'string',
|
10903 | name: 'toPeerIds',
|
10904 | id: 7
|
10905 | }, {
|
10906 | rule: 'optional',
|
10907 | type: 'bool',
|
10908 | name: 'r',
|
10909 | id: 10
|
10910 | }, {
|
10911 | rule: 'optional',
|
10912 | type: 'string',
|
10913 | name: 'cid',
|
10914 | id: 11
|
10915 | }, {
|
10916 | rule: 'optional',
|
10917 | type: 'string',
|
10918 | name: 'id',
|
10919 | id: 12
|
10920 | }, {
|
10921 | rule: 'optional',
|
10922 | type: 'bool',
|
10923 | name: 'transient',
|
10924 | id: 13
|
10925 | }, {
|
10926 | rule: 'optional',
|
10927 | type: 'string',
|
10928 | name: 'dt',
|
10929 | id: 14
|
10930 | }, {
|
10931 | rule: 'optional',
|
10932 | type: 'string',
|
10933 | name: 'roomId',
|
10934 | id: 15
|
10935 | }, {
|
10936 | rule: 'optional',
|
10937 | type: 'string',
|
10938 | name: 'pushData',
|
10939 | id: 16
|
10940 | }, {
|
10941 | rule: 'optional',
|
10942 | type: 'bool',
|
10943 | name: 'will',
|
10944 | id: 17
|
10945 | }, {
|
10946 | rule: 'optional',
|
10947 | type: 'int64',
|
10948 | name: 'patchTimestamp',
|
10949 | id: 18
|
10950 | }, {
|
10951 | rule: 'optional',
|
10952 | type: 'bytes',
|
10953 | name: 'binaryMsg',
|
10954 | id: 19
|
10955 | }, {
|
10956 | rule: 'repeated',
|
10957 | type: 'string',
|
10958 | name: 'mentionPids',
|
10959 | id: 20
|
10960 | }, {
|
10961 | rule: 'optional',
|
10962 | type: 'bool',
|
10963 | name: 'mentionAll',
|
10964 | id: 21
|
10965 | }, {
|
10966 | rule: 'optional',
|
10967 | type: 'int32',
|
10968 | name: 'convType',
|
10969 | id: 22
|
10970 | }]
|
10971 | }, {
|
10972 | name: 'AckCommand',
|
10973 | syntax: 'proto2',
|
10974 | fields: [{
|
10975 | rule: 'optional',
|
10976 | type: 'int32',
|
10977 | name: 'code',
|
10978 | id: 1
|
10979 | }, {
|
10980 | rule: 'optional',
|
10981 | type: 'string',
|
10982 | name: 'reason',
|
10983 | id: 2
|
10984 | }, {
|
10985 | rule: 'optional',
|
10986 | type: 'string',
|
10987 | name: 'mid',
|
10988 | id: 3
|
10989 | }, {
|
10990 | rule: 'optional',
|
10991 | type: 'string',
|
10992 | name: 'cid',
|
10993 | id: 4
|
10994 | }, {
|
10995 | rule: 'optional',
|
10996 | type: 'int64',
|
10997 | name: 't',
|
10998 | id: 5
|
10999 | }, {
|
11000 | rule: 'optional',
|
11001 | type: 'string',
|
11002 | name: 'uid',
|
11003 | id: 6
|
11004 | }, {
|
11005 | rule: 'optional',
|
11006 | type: 'int64',
|
11007 | name: 'fromts',
|
11008 | id: 7
|
11009 | }, {
|
11010 | rule: 'optional',
|
11011 | type: 'int64',
|
11012 | name: 'tots',
|
11013 | id: 8
|
11014 | }, {
|
11015 | rule: 'optional',
|
11016 | type: 'string',
|
11017 | name: 'type',
|
11018 | id: 9
|
11019 | }, {
|
11020 | rule: 'repeated',
|
11021 | type: 'string',
|
11022 | name: 'ids',
|
11023 | id: 10
|
11024 | }, {
|
11025 | rule: 'optional',
|
11026 | type: 'int32',
|
11027 | name: 'appCode',
|
11028 | id: 11
|
11029 | }, {
|
11030 | rule: 'optional',
|
11031 | type: 'string',
|
11032 | name: 'appMsg',
|
11033 | id: 12
|
11034 | }]
|
11035 | }, {
|
11036 | name: 'UnreadCommand',
|
11037 | syntax: 'proto2',
|
11038 | fields: [{
|
11039 | rule: 'repeated',
|
11040 | type: 'UnreadTuple',
|
11041 | name: 'convs',
|
11042 | id: 1
|
11043 | }, {
|
11044 | rule: 'optional',
|
11045 | type: 'int64',
|
11046 | name: 'notifTime',
|
11047 | id: 2
|
11048 | }]
|
11049 | }, {
|
11050 | name: 'ConvCommand',
|
11051 | syntax: 'proto2',
|
11052 | fields: [{
|
11053 | rule: 'repeated',
|
11054 | type: 'string',
|
11055 | name: 'm',
|
11056 | id: 1
|
11057 | }, {
|
11058 | rule: 'optional',
|
11059 | type: 'bool',
|
11060 | name: 'transient',
|
11061 | id: 2
|
11062 | }, {
|
11063 | rule: 'optional',
|
11064 | type: 'bool',
|
11065 | name: 'unique',
|
11066 | id: 3
|
11067 | }, {
|
11068 | rule: 'optional',
|
11069 | type: 'string',
|
11070 | name: 'cid',
|
11071 | id: 4
|
11072 | }, {
|
11073 | rule: 'optional',
|
11074 | type: 'string',
|
11075 | name: 'cdate',
|
11076 | id: 5
|
11077 | }, {
|
11078 | rule: 'optional',
|
11079 | type: 'string',
|
11080 | name: 'initBy',
|
11081 | id: 6
|
11082 | }, {
|
11083 | rule: 'optional',
|
11084 | type: 'string',
|
11085 | name: 'sort',
|
11086 | id: 7
|
11087 | }, {
|
11088 | rule: 'optional',
|
11089 | type: 'int32',
|
11090 | name: 'limit',
|
11091 | id: 8
|
11092 | }, {
|
11093 | rule: 'optional',
|
11094 | type: 'int32',
|
11095 | name: 'skip',
|
11096 | id: 9
|
11097 | }, {
|
11098 | rule: 'optional',
|
11099 | type: 'int32',
|
11100 | name: 'flag',
|
11101 | id: 10
|
11102 | }, {
|
11103 | rule: 'optional',
|
11104 | type: 'int32',
|
11105 | name: 'count',
|
11106 | id: 11
|
11107 | }, {
|
11108 | rule: 'optional',
|
11109 | type: 'string',
|
11110 | name: 'udate',
|
11111 | id: 12
|
11112 | }, {
|
11113 | rule: 'optional',
|
11114 | type: 'int64',
|
11115 | name: 't',
|
11116 | id: 13
|
11117 | }, {
|
11118 | rule: 'optional',
|
11119 | type: 'string',
|
11120 | name: 'n',
|
11121 | id: 14
|
11122 | }, {
|
11123 | rule: 'optional',
|
11124 | type: 'string',
|
11125 | name: 's',
|
11126 | id: 15
|
11127 | }, {
|
11128 | rule: 'optional',
|
11129 | type: 'bool',
|
11130 | name: 'statusSub',
|
11131 | id: 16
|
11132 | }, {
|
11133 | rule: 'optional',
|
11134 | type: 'bool',
|
11135 | name: 'statusPub',
|
11136 | id: 17
|
11137 | }, {
|
11138 | rule: 'optional',
|
11139 | type: 'int32',
|
11140 | name: 'statusTTL',
|
11141 | id: 18
|
11142 | }, {
|
11143 | rule: 'optional',
|
11144 | type: 'string',
|
11145 | name: 'uniqueId',
|
11146 | id: 19
|
11147 | }, {
|
11148 | rule: 'optional',
|
11149 | type: 'string',
|
11150 | name: 'targetClientId',
|
11151 | id: 20
|
11152 | }, {
|
11153 | rule: 'optional',
|
11154 | type: 'int64',
|
11155 | name: 'maxReadTimestamp',
|
11156 | id: 21
|
11157 | }, {
|
11158 | rule: 'optional',
|
11159 | type: 'int64',
|
11160 | name: 'maxAckTimestamp',
|
11161 | id: 22
|
11162 | }, {
|
11163 | rule: 'optional',
|
11164 | type: 'bool',
|
11165 | name: 'queryAllMembers',
|
11166 | id: 23
|
11167 | }, {
|
11168 | rule: 'repeated',
|
11169 | type: 'MaxReadTuple',
|
11170 | name: 'maxReadTuples',
|
11171 | id: 24
|
11172 | }, {
|
11173 | rule: 'repeated',
|
11174 | type: 'string',
|
11175 | name: 'cids',
|
11176 | id: 25
|
11177 | }, {
|
11178 | rule: 'optional',
|
11179 | type: 'ConvMemberInfo',
|
11180 | name: 'info',
|
11181 | id: 26
|
11182 | }, {
|
11183 | rule: 'optional',
|
11184 | type: 'bool',
|
11185 | name: 'tempConv',
|
11186 | id: 27
|
11187 | }, {
|
11188 | rule: 'optional',
|
11189 | type: 'int32',
|
11190 | name: 'tempConvTTL',
|
11191 | id: 28
|
11192 | }, {
|
11193 | rule: 'repeated',
|
11194 | type: 'string',
|
11195 | name: 'tempConvIds',
|
11196 | id: 29
|
11197 | }, {
|
11198 | rule: 'repeated',
|
11199 | type: 'string',
|
11200 | name: 'allowedPids',
|
11201 | id: 30
|
11202 | }, {
|
11203 | rule: 'repeated',
|
11204 | type: 'ErrorCommand',
|
11205 | name: 'failedPids',
|
11206 | id: 31
|
11207 | }, {
|
11208 | rule: 'optional',
|
11209 | type: 'string',
|
11210 | name: 'next',
|
11211 | id: 40
|
11212 | }, {
|
11213 | rule: 'optional',
|
11214 | type: 'JsonObjectMessage',
|
11215 | name: 'results',
|
11216 | id: 100
|
11217 | }, {
|
11218 | rule: 'optional',
|
11219 | type: 'JsonObjectMessage',
|
11220 | name: 'where',
|
11221 | id: 101
|
11222 | }, {
|
11223 | rule: 'optional',
|
11224 | type: 'JsonObjectMessage',
|
11225 | name: 'attr',
|
11226 | id: 103
|
11227 | }, {
|
11228 | rule: 'optional',
|
11229 | type: 'JsonObjectMessage',
|
11230 | name: 'attrModified',
|
11231 | id: 104
|
11232 | }]
|
11233 | }, {
|
11234 | name: 'RoomCommand',
|
11235 | syntax: 'proto2',
|
11236 | fields: [{
|
11237 | rule: 'optional',
|
11238 | type: 'string',
|
11239 | name: 'roomId',
|
11240 | id: 1
|
11241 | }, {
|
11242 | rule: 'optional',
|
11243 | type: 'string',
|
11244 | name: 's',
|
11245 | id: 2
|
11246 | }, {
|
11247 | rule: 'optional',
|
11248 | type: 'int64',
|
11249 | name: 't',
|
11250 | id: 3
|
11251 | }, {
|
11252 | rule: 'optional',
|
11253 | type: 'string',
|
11254 | name: 'n',
|
11255 | id: 4
|
11256 | }, {
|
11257 | rule: 'optional',
|
11258 | type: 'bool',
|
11259 | name: 'transient',
|
11260 | id: 5
|
11261 | }, {
|
11262 | rule: 'repeated',
|
11263 | type: 'string',
|
11264 | name: 'roomPeerIds',
|
11265 | id: 6
|
11266 | }, {
|
11267 | rule: 'optional',
|
11268 | type: 'string',
|
11269 | name: 'byPeerId',
|
11270 | id: 7
|
11271 | }]
|
11272 | }, {
|
11273 | name: 'LogsCommand',
|
11274 | syntax: 'proto2',
|
11275 | fields: [{
|
11276 | rule: 'optional',
|
11277 | type: 'string',
|
11278 | name: 'cid',
|
11279 | id: 1
|
11280 | }, {
|
11281 | rule: 'optional',
|
11282 | type: 'int32',
|
11283 | name: 'l',
|
11284 | id: 2
|
11285 | }, {
|
11286 | rule: 'optional',
|
11287 | type: 'int32',
|
11288 | name: 'limit',
|
11289 | id: 3
|
11290 | }, {
|
11291 | rule: 'optional',
|
11292 | type: 'int64',
|
11293 | name: 't',
|
11294 | id: 4
|
11295 | }, {
|
11296 | rule: 'optional',
|
11297 | type: 'int64',
|
11298 | name: 'tt',
|
11299 | id: 5
|
11300 | }, {
|
11301 | rule: 'optional',
|
11302 | type: 'string',
|
11303 | name: 'tmid',
|
11304 | id: 6
|
11305 | }, {
|
11306 | rule: 'optional',
|
11307 | type: 'string',
|
11308 | name: 'mid',
|
11309 | id: 7
|
11310 | }, {
|
11311 | rule: 'optional',
|
11312 | type: 'string',
|
11313 | name: 'checksum',
|
11314 | id: 8
|
11315 | }, {
|
11316 | rule: 'optional',
|
11317 | type: 'bool',
|
11318 | name: 'stored',
|
11319 | id: 9
|
11320 | }, {
|
11321 | rule: 'optional',
|
11322 | type: 'QueryDirection',
|
11323 | name: 'direction',
|
11324 | id: 10,
|
11325 | options: {
|
11326 | default: 'OLD'
|
11327 | }
|
11328 | }, {
|
11329 | rule: 'optional',
|
11330 | type: 'bool',
|
11331 | name: 'tIncluded',
|
11332 | id: 11
|
11333 | }, {
|
11334 | rule: 'optional',
|
11335 | type: 'bool',
|
11336 | name: 'ttIncluded',
|
11337 | id: 12
|
11338 | }, {
|
11339 | rule: 'optional',
|
11340 | type: 'int32',
|
11341 | name: 'lctype',
|
11342 | id: 13
|
11343 | }, {
|
11344 | rule: 'repeated',
|
11345 | type: 'LogItem',
|
11346 | name: 'logs',
|
11347 | id: 105
|
11348 | }],
|
11349 | enums: [{
|
11350 | name: 'QueryDirection',
|
11351 | syntax: 'proto2',
|
11352 | values: [{
|
11353 | name: 'OLD',
|
11354 | id: 1
|
11355 | }, {
|
11356 | name: 'NEW',
|
11357 | id: 2
|
11358 | }]
|
11359 | }]
|
11360 | }, {
|
11361 | name: 'RcpCommand',
|
11362 | syntax: 'proto2',
|
11363 | fields: [{
|
11364 | rule: 'optional',
|
11365 | type: 'string',
|
11366 | name: 'id',
|
11367 | id: 1
|
11368 | }, {
|
11369 | rule: 'optional',
|
11370 | type: 'string',
|
11371 | name: 'cid',
|
11372 | id: 2
|
11373 | }, {
|
11374 | rule: 'optional',
|
11375 | type: 'int64',
|
11376 | name: 't',
|
11377 | id: 3
|
11378 | }, {
|
11379 | rule: 'optional',
|
11380 | type: 'bool',
|
11381 | name: 'read',
|
11382 | id: 4
|
11383 | }, {
|
11384 | rule: 'optional',
|
11385 | type: 'string',
|
11386 | name: 'from',
|
11387 | id: 5
|
11388 | }]
|
11389 | }, {
|
11390 | name: 'ReadTuple',
|
11391 | syntax: 'proto2',
|
11392 | fields: [{
|
11393 | rule: 'required',
|
11394 | type: 'string',
|
11395 | name: 'cid',
|
11396 | id: 1
|
11397 | }, {
|
11398 | rule: 'optional',
|
11399 | type: 'int64',
|
11400 | name: 'timestamp',
|
11401 | id: 2
|
11402 | }, {
|
11403 | rule: 'optional',
|
11404 | type: 'string',
|
11405 | name: 'mid',
|
11406 | id: 3
|
11407 | }]
|
11408 | }, {
|
11409 | name: 'MaxReadTuple',
|
11410 | syntax: 'proto2',
|
11411 | fields: [{
|
11412 | rule: 'optional',
|
11413 | type: 'string',
|
11414 | name: 'pid',
|
11415 | id: 1
|
11416 | }, {
|
11417 | rule: 'optional',
|
11418 | type: 'int64',
|
11419 | name: 'maxAckTimestamp',
|
11420 | id: 2
|
11421 | }, {
|
11422 | rule: 'optional',
|
11423 | type: 'int64',
|
11424 | name: 'maxReadTimestamp',
|
11425 | id: 3
|
11426 | }]
|
11427 | }, {
|
11428 | name: 'ReadCommand',
|
11429 | syntax: 'proto2',
|
11430 | fields: [{
|
11431 | rule: 'optional',
|
11432 | type: 'string',
|
11433 | name: 'cid',
|
11434 | id: 1
|
11435 | }, {
|
11436 | rule: 'repeated',
|
11437 | type: 'string',
|
11438 | name: 'cids',
|
11439 | id: 2
|
11440 | }, {
|
11441 | rule: 'repeated',
|
11442 | type: 'ReadTuple',
|
11443 | name: 'convs',
|
11444 | id: 3
|
11445 | }]
|
11446 | }, {
|
11447 | name: 'PresenceCommand',
|
11448 | syntax: 'proto2',
|
11449 | fields: [{
|
11450 | rule: 'optional',
|
11451 | type: 'StatusType',
|
11452 | name: 'status',
|
11453 | id: 1
|
11454 | }, {
|
11455 | rule: 'repeated',
|
11456 | type: 'string',
|
11457 | name: 'sessionPeerIds',
|
11458 | id: 2
|
11459 | }, {
|
11460 | rule: 'optional',
|
11461 | type: 'string',
|
11462 | name: 'cid',
|
11463 | id: 3
|
11464 | }]
|
11465 | }, {
|
11466 | name: 'ReportCommand',
|
11467 | syntax: 'proto2',
|
11468 | fields: [{
|
11469 | rule: 'optional',
|
11470 | type: 'bool',
|
11471 | name: 'initiative',
|
11472 | id: 1
|
11473 | }, {
|
11474 | rule: 'optional',
|
11475 | type: 'string',
|
11476 | name: 'type',
|
11477 | id: 2
|
11478 | }, {
|
11479 | rule: 'optional',
|
11480 | type: 'string',
|
11481 | name: 'data',
|
11482 | id: 3
|
11483 | }]
|
11484 | }, {
|
11485 | name: 'PatchItem',
|
11486 | syntax: 'proto2',
|
11487 | fields: [{
|
11488 | rule: 'optional',
|
11489 | type: 'string',
|
11490 | name: 'cid',
|
11491 | id: 1
|
11492 | }, {
|
11493 | rule: 'optional',
|
11494 | type: 'string',
|
11495 | name: 'mid',
|
11496 | id: 2
|
11497 | }, {
|
11498 | rule: 'optional',
|
11499 | type: 'int64',
|
11500 | name: 'timestamp',
|
11501 | id: 3
|
11502 | }, {
|
11503 | rule: 'optional',
|
11504 | type: 'bool',
|
11505 | name: 'recall',
|
11506 | id: 4
|
11507 | }, {
|
11508 | rule: 'optional',
|
11509 | type: 'string',
|
11510 | name: 'data',
|
11511 | id: 5
|
11512 | }, {
|
11513 | rule: 'optional',
|
11514 | type: 'int64',
|
11515 | name: 'patchTimestamp',
|
11516 | id: 6
|
11517 | }, {
|
11518 | rule: 'optional',
|
11519 | type: 'string',
|
11520 | name: 'from',
|
11521 | id: 7
|
11522 | }, {
|
11523 | rule: 'optional',
|
11524 | type: 'bytes',
|
11525 | name: 'binaryMsg',
|
11526 | id: 8
|
11527 | }, {
|
11528 | rule: 'optional',
|
11529 | type: 'bool',
|
11530 | name: 'mentionAll',
|
11531 | id: 9
|
11532 | }, {
|
11533 | rule: 'repeated',
|
11534 | type: 'string',
|
11535 | name: 'mentionPids',
|
11536 | id: 10
|
11537 | }, {
|
11538 | rule: 'optional',
|
11539 | type: 'int64',
|
11540 | name: 'patchCode',
|
11541 | id: 11
|
11542 | }, {
|
11543 | rule: 'optional',
|
11544 | type: 'string',
|
11545 | name: 'patchReason',
|
11546 | id: 12
|
11547 | }]
|
11548 | }, {
|
11549 | name: 'PatchCommand',
|
11550 | syntax: 'proto2',
|
11551 | fields: [{
|
11552 | rule: 'repeated',
|
11553 | type: 'PatchItem',
|
11554 | name: 'patches',
|
11555 | id: 1
|
11556 | }, {
|
11557 | rule: 'optional',
|
11558 | type: 'int64',
|
11559 | name: 'lastPatchTime',
|
11560 | id: 2
|
11561 | }]
|
11562 | }, {
|
11563 | name: 'PubsubCommand',
|
11564 | syntax: 'proto2',
|
11565 | fields: [{
|
11566 | rule: 'optional',
|
11567 | type: 'string',
|
11568 | name: 'cid',
|
11569 | id: 1
|
11570 | }, {
|
11571 | rule: 'repeated',
|
11572 | type: 'string',
|
11573 | name: 'cids',
|
11574 | id: 2
|
11575 | }, {
|
11576 | rule: 'optional',
|
11577 | type: 'string',
|
11578 | name: 'topic',
|
11579 | id: 3
|
11580 | }, {
|
11581 | rule: 'optional',
|
11582 | type: 'string',
|
11583 | name: 'subtopic',
|
11584 | id: 4
|
11585 | }, {
|
11586 | rule: 'repeated',
|
11587 | type: 'string',
|
11588 | name: 'topics',
|
11589 | id: 5
|
11590 | }, {
|
11591 | rule: 'repeated',
|
11592 | type: 'string',
|
11593 | name: 'subtopics',
|
11594 | id: 6
|
11595 | }, {
|
11596 | rule: 'optional',
|
11597 | type: 'JsonObjectMessage',
|
11598 | name: 'results',
|
11599 | id: 7
|
11600 | }]
|
11601 | }, {
|
11602 | name: 'BlacklistCommand',
|
11603 | syntax: 'proto2',
|
11604 | fields: [{
|
11605 | rule: 'optional',
|
11606 | type: 'string',
|
11607 | name: 'srcCid',
|
11608 | id: 1
|
11609 | }, {
|
11610 | rule: 'repeated',
|
11611 | type: 'string',
|
11612 | name: 'toPids',
|
11613 | id: 2
|
11614 | }, {
|
11615 | rule: 'optional',
|
11616 | type: 'string',
|
11617 | name: 'srcPid',
|
11618 | id: 3
|
11619 | }, {
|
11620 | rule: 'repeated',
|
11621 | type: 'string',
|
11622 | name: 'toCids',
|
11623 | id: 4
|
11624 | }, {
|
11625 | rule: 'optional',
|
11626 | type: 'int32',
|
11627 | name: 'limit',
|
11628 | id: 5
|
11629 | }, {
|
11630 | rule: 'optional',
|
11631 | type: 'string',
|
11632 | name: 'next',
|
11633 | id: 6
|
11634 | }, {
|
11635 | rule: 'repeated',
|
11636 | type: 'string',
|
11637 | name: 'blockedPids',
|
11638 | id: 8
|
11639 | }, {
|
11640 | rule: 'repeated',
|
11641 | type: 'string',
|
11642 | name: 'blockedCids',
|
11643 | id: 9
|
11644 | }, {
|
11645 | rule: 'repeated',
|
11646 | type: 'string',
|
11647 | name: 'allowedPids',
|
11648 | id: 10
|
11649 | }, {
|
11650 | rule: 'repeated',
|
11651 | type: 'ErrorCommand',
|
11652 | name: 'failedPids',
|
11653 | id: 11
|
11654 | }, {
|
11655 | rule: 'optional',
|
11656 | type: 'int64',
|
11657 | name: 't',
|
11658 | id: 12
|
11659 | }, {
|
11660 | rule: 'optional',
|
11661 | type: 'string',
|
11662 | name: 'n',
|
11663 | id: 13
|
11664 | }, {
|
11665 | rule: 'optional',
|
11666 | type: 'string',
|
11667 | name: 's',
|
11668 | id: 14
|
11669 | }]
|
11670 | }, {
|
11671 | name: 'GenericCommand',
|
11672 | syntax: 'proto2',
|
11673 | fields: [{
|
11674 | rule: 'optional',
|
11675 | type: 'CommandType',
|
11676 | name: 'cmd',
|
11677 | id: 1
|
11678 | }, {
|
11679 | rule: 'optional',
|
11680 | type: 'OpType',
|
11681 | name: 'op',
|
11682 | id: 2
|
11683 | }, {
|
11684 | rule: 'optional',
|
11685 | type: 'string',
|
11686 | name: 'appId',
|
11687 | id: 3
|
11688 | }, {
|
11689 | rule: 'optional',
|
11690 | type: 'string',
|
11691 | name: 'peerId',
|
11692 | id: 4
|
11693 | }, {
|
11694 | rule: 'optional',
|
11695 | type: 'int32',
|
11696 | name: 'i',
|
11697 | id: 5
|
11698 | }, {
|
11699 | rule: 'optional',
|
11700 | type: 'string',
|
11701 | name: 'installationId',
|
11702 | id: 6
|
11703 | }, {
|
11704 | rule: 'optional',
|
11705 | type: 'int32',
|
11706 | name: 'priority',
|
11707 | id: 7
|
11708 | }, {
|
11709 | rule: 'optional',
|
11710 | type: 'int32',
|
11711 | name: 'service',
|
11712 | id: 8
|
11713 | }, {
|
11714 | rule: 'optional',
|
11715 | type: 'int64',
|
11716 | name: 'serverTs',
|
11717 | id: 9
|
11718 | }, {
|
11719 | rule: 'optional',
|
11720 | type: 'int64',
|
11721 | name: 'clientTs',
|
11722 | id: 10
|
11723 | }, {
|
11724 | rule: 'optional',
|
11725 | type: 'int32',
|
11726 | name: 'notificationType',
|
11727 | id: 11
|
11728 | }, {
|
11729 | rule: 'optional',
|
11730 | type: 'DataCommand',
|
11731 | name: 'dataMessage',
|
11732 | id: 101
|
11733 | }, {
|
11734 | rule: 'optional',
|
11735 | type: 'SessionCommand',
|
11736 | name: 'sessionMessage',
|
11737 | id: 102
|
11738 | }, {
|
11739 | rule: 'optional',
|
11740 | type: 'ErrorCommand',
|
11741 | name: 'errorMessage',
|
11742 | id: 103
|
11743 | }, {
|
11744 | rule: 'optional',
|
11745 | type: 'DirectCommand',
|
11746 | name: 'directMessage',
|
11747 | id: 104
|
11748 | }, {
|
11749 | rule: 'optional',
|
11750 | type: 'AckCommand',
|
11751 | name: 'ackMessage',
|
11752 | id: 105
|
11753 | }, {
|
11754 | rule: 'optional',
|
11755 | type: 'UnreadCommand',
|
11756 | name: 'unreadMessage',
|
11757 | id: 106
|
11758 | }, {
|
11759 | rule: 'optional',
|
11760 | type: 'ReadCommand',
|
11761 | name: 'readMessage',
|
11762 | id: 107
|
11763 | }, {
|
11764 | rule: 'optional',
|
11765 | type: 'RcpCommand',
|
11766 | name: 'rcpMessage',
|
11767 | id: 108
|
11768 | }, {
|
11769 | rule: 'optional',
|
11770 | type: 'LogsCommand',
|
11771 | name: 'logsMessage',
|
11772 | id: 109
|
11773 | }, {
|
11774 | rule: 'optional',
|
11775 | type: 'ConvCommand',
|
11776 | name: 'convMessage',
|
11777 | id: 110
|
11778 | }, {
|
11779 | rule: 'optional',
|
11780 | type: 'RoomCommand',
|
11781 | name: 'roomMessage',
|
11782 | id: 111
|
11783 | }, {
|
11784 | rule: 'optional',
|
11785 | type: 'PresenceCommand',
|
11786 | name: 'presenceMessage',
|
11787 | id: 112
|
11788 | }, {
|
11789 | rule: 'optional',
|
11790 | type: 'ReportCommand',
|
11791 | name: 'reportMessage',
|
11792 | id: 113
|
11793 | }, {
|
11794 | rule: 'optional',
|
11795 | type: 'PatchCommand',
|
11796 | name: 'patchMessage',
|
11797 | id: 114
|
11798 | }, {
|
11799 | rule: 'optional',
|
11800 | type: 'PubsubCommand',
|
11801 | name: 'pubsubMessage',
|
11802 | id: 115
|
11803 | }, {
|
11804 | rule: 'optional',
|
11805 | type: 'BlacklistCommand',
|
11806 | name: 'blacklistMessage',
|
11807 | id: 116
|
11808 | }]
|
11809 | }],
|
11810 | enums: [{
|
11811 | name: 'CommandType',
|
11812 | syntax: 'proto2',
|
11813 | values: [{
|
11814 | name: 'session',
|
11815 | id: 0
|
11816 | }, {
|
11817 | name: 'conv',
|
11818 | id: 1
|
11819 | }, {
|
11820 | name: 'direct',
|
11821 | id: 2
|
11822 | }, {
|
11823 | name: 'ack',
|
11824 | id: 3
|
11825 | }, {
|
11826 | name: 'rcp',
|
11827 | id: 4
|
11828 | }, {
|
11829 | name: 'unread',
|
11830 | id: 5
|
11831 | }, {
|
11832 | name: 'logs',
|
11833 | id: 6
|
11834 | }, {
|
11835 | name: 'error',
|
11836 | id: 7
|
11837 | }, {
|
11838 | name: 'login',
|
11839 | id: 8
|
11840 | }, {
|
11841 | name: 'data',
|
11842 | id: 9
|
11843 | }, {
|
11844 | name: 'room',
|
11845 | id: 10
|
11846 | }, {
|
11847 | name: 'read',
|
11848 | id: 11
|
11849 | }, {
|
11850 | name: 'presence',
|
11851 | id: 12
|
11852 | }, {
|
11853 | name: 'report',
|
11854 | id: 13
|
11855 | }, {
|
11856 | name: 'echo',
|
11857 | id: 14
|
11858 | }, {
|
11859 | name: 'loggedin',
|
11860 | id: 15
|
11861 | }, {
|
11862 | name: 'logout',
|
11863 | id: 16
|
11864 | }, {
|
11865 | name: 'loggedout',
|
11866 | id: 17
|
11867 | }, {
|
11868 | name: 'patch',
|
11869 | id: 18
|
11870 | }, {
|
11871 | name: 'pubsub',
|
11872 | id: 19
|
11873 | }, {
|
11874 | name: 'blacklist',
|
11875 | id: 20
|
11876 | }, {
|
11877 | name: 'goaway',
|
11878 | id: 21
|
11879 | }]
|
11880 | }, {
|
11881 | name: 'OpType',
|
11882 | syntax: 'proto2',
|
11883 | values: [{
|
11884 | name: 'open',
|
11885 | id: 1
|
11886 | }, {
|
11887 | name: 'add',
|
11888 | id: 2
|
11889 | }, {
|
11890 | name: 'remove',
|
11891 | id: 3
|
11892 | }, {
|
11893 | name: 'close',
|
11894 | id: 4
|
11895 | }, {
|
11896 | name: 'opened',
|
11897 | id: 5
|
11898 | }, {
|
11899 | name: 'closed',
|
11900 | id: 6
|
11901 | }, {
|
11902 | name: 'query',
|
11903 | id: 7
|
11904 | }, {
|
11905 | name: 'query_result',
|
11906 | id: 8
|
11907 | }, {
|
11908 | name: 'conflict',
|
11909 | id: 9
|
11910 | }, {
|
11911 | name: 'added',
|
11912 | id: 10
|
11913 | }, {
|
11914 | name: 'removed',
|
11915 | id: 11
|
11916 | }, {
|
11917 | name: 'refresh',
|
11918 | id: 12
|
11919 | }, {
|
11920 | name: 'refreshed',
|
11921 | id: 13
|
11922 | }, {
|
11923 | name: 'start',
|
11924 | id: 30
|
11925 | }, {
|
11926 | name: 'started',
|
11927 | id: 31
|
11928 | }, {
|
11929 | name: 'joined',
|
11930 | id: 32
|
11931 | }, {
|
11932 | name: 'members_joined',
|
11933 | id: 33
|
11934 | }, {
|
11935 | name: 'left',
|
11936 | id: 39
|
11937 | }, {
|
11938 | name: 'members_left',
|
11939 | id: 40
|
11940 | }, {
|
11941 | name: 'results',
|
11942 | id: 42
|
11943 | }, {
|
11944 | name: 'count',
|
11945 | id: 43
|
11946 | }, {
|
11947 | name: 'result',
|
11948 | id: 44
|
11949 | }, {
|
11950 | name: 'update',
|
11951 | id: 45
|
11952 | }, {
|
11953 | name: 'updated',
|
11954 | id: 46
|
11955 | }, {
|
11956 | name: 'mute',
|
11957 | id: 47
|
11958 | }, {
|
11959 | name: 'unmute',
|
11960 | id: 48
|
11961 | }, {
|
11962 | name: 'status',
|
11963 | id: 49
|
11964 | }, {
|
11965 | name: 'members',
|
11966 | id: 50
|
11967 | }, {
|
11968 | name: 'max_read',
|
11969 | id: 51
|
11970 | }, {
|
11971 | name: 'is_member',
|
11972 | id: 52
|
11973 | }, {
|
11974 | name: 'member_info_update',
|
11975 | id: 53
|
11976 | }, {
|
11977 | name: 'member_info_updated',
|
11978 | id: 54
|
11979 | }, {
|
11980 | name: 'member_info_changed',
|
11981 | id: 55
|
11982 | }, {
|
11983 | name: 'join',
|
11984 | id: 80
|
11985 | }, {
|
11986 | name: 'invite',
|
11987 | id: 81
|
11988 | }, {
|
11989 | name: 'leave',
|
11990 | id: 82
|
11991 | }, {
|
11992 | name: 'kick',
|
11993 | id: 83
|
11994 | }, {
|
11995 | name: 'reject',
|
11996 | id: 84
|
11997 | }, {
|
11998 | name: 'invited',
|
11999 | id: 85
|
12000 | }, {
|
12001 | name: 'kicked',
|
12002 | id: 86
|
12003 | }, {
|
12004 | name: 'upload',
|
12005 | id: 100
|
12006 | }, {
|
12007 | name: 'uploaded',
|
12008 | id: 101
|
12009 | }, {
|
12010 | name: 'subscribe',
|
12011 | id: 120
|
12012 | }, {
|
12013 | name: 'subscribed',
|
12014 | id: 121
|
12015 | }, {
|
12016 | name: 'unsubscribe',
|
12017 | id: 122
|
12018 | }, {
|
12019 | name: 'unsubscribed',
|
12020 | id: 123
|
12021 | }, {
|
12022 | name: 'is_subscribed',
|
12023 | id: 124
|
12024 | }, {
|
12025 | name: 'modify',
|
12026 | id: 150
|
12027 | }, {
|
12028 | name: 'modified',
|
12029 | id: 151
|
12030 | }, {
|
12031 | name: 'block',
|
12032 | id: 170
|
12033 | }, {
|
12034 | name: 'unblock',
|
12035 | id: 171
|
12036 | }, {
|
12037 | name: 'blocked',
|
12038 | id: 172
|
12039 | }, {
|
12040 | name: 'unblocked',
|
12041 | id: 173
|
12042 | }, {
|
12043 | name: 'members_blocked',
|
12044 | id: 174
|
12045 | }, {
|
12046 | name: 'members_unblocked',
|
12047 | id: 175
|
12048 | }, {
|
12049 | name: 'check_block',
|
12050 | id: 176
|
12051 | }, {
|
12052 | name: 'check_result',
|
12053 | id: 177
|
12054 | }, {
|
12055 | name: 'add_shutup',
|
12056 | id: 180
|
12057 | }, {
|
12058 | name: 'remove_shutup',
|
12059 | id: 181
|
12060 | }, {
|
12061 | name: 'query_shutup',
|
12062 | id: 182
|
12063 | }, {
|
12064 | name: 'shutup_added',
|
12065 | id: 183
|
12066 | }, {
|
12067 | name: 'shutup_removed',
|
12068 | id: 184
|
12069 | }, {
|
12070 | name: 'shutup_result',
|
12071 | id: 185
|
12072 | }, {
|
12073 | name: 'shutuped',
|
12074 | id: 186
|
12075 | }, {
|
12076 | name: 'unshutuped',
|
12077 | id: 187
|
12078 | }, {
|
12079 | name: 'members_shutuped',
|
12080 | id: 188
|
12081 | }, {
|
12082 | name: 'members_unshutuped',
|
12083 | id: 189
|
12084 | }, {
|
12085 | name: 'check_shutup',
|
12086 | id: 190
|
12087 | }]
|
12088 | }, {
|
12089 | name: 'StatusType',
|
12090 | syntax: 'proto2',
|
12091 | values: [{
|
12092 | name: 'on',
|
12093 | id: 1
|
12094 | }, {
|
12095 | name: 'off',
|
12096 | id: 2
|
12097 | }]
|
12098 | }],
|
12099 | isNamespace: true
|
12100 | }).build();
|
12101 |
|
12102 | var _messages$push_server = messageCompiled.push_server.messages2,
|
12103 | JsonObjectMessage = _messages$push_server.JsonObjectMessage,
|
12104 | UnreadTuple = _messages$push_server.UnreadTuple,
|
12105 | LogItem = _messages$push_server.LogItem,
|
12106 | DataCommand = _messages$push_server.DataCommand,
|
12107 | SessionCommand = _messages$push_server.SessionCommand,
|
12108 | ErrorCommand = _messages$push_server.ErrorCommand,
|
12109 | DirectCommand = _messages$push_server.DirectCommand,
|
12110 | AckCommand = _messages$push_server.AckCommand,
|
12111 | UnreadCommand = _messages$push_server.UnreadCommand,
|
12112 | ConvCommand = _messages$push_server.ConvCommand,
|
12113 | RoomCommand = _messages$push_server.RoomCommand,
|
12114 | LogsCommand = _messages$push_server.LogsCommand,
|
12115 | RcpCommand = _messages$push_server.RcpCommand,
|
12116 | ReadTuple = _messages$push_server.ReadTuple,
|
12117 | MaxReadTuple = _messages$push_server.MaxReadTuple,
|
12118 | ReadCommand = _messages$push_server.ReadCommand,
|
12119 | PresenceCommand = _messages$push_server.PresenceCommand,
|
12120 | ReportCommand = _messages$push_server.ReportCommand,
|
12121 | GenericCommand = _messages$push_server.GenericCommand,
|
12122 | BlacklistCommand = _messages$push_server.BlacklistCommand,
|
12123 | PatchCommand = _messages$push_server.PatchCommand,
|
12124 | PatchItem = _messages$push_server.PatchItem,
|
12125 | ConvMemberInfo = _messages$push_server.ConvMemberInfo,
|
12126 | CommandType = _messages$push_server.CommandType,
|
12127 | OpType = _messages$push_server.OpType,
|
12128 | StatusType = _messages$push_server.StatusType;
|
12129 |
|
12130 | var message = Object.freeze({
|
12131 | JsonObjectMessage: JsonObjectMessage,
|
12132 | UnreadTuple: UnreadTuple,
|
12133 | LogItem: LogItem,
|
12134 | DataCommand: DataCommand,
|
12135 | SessionCommand: SessionCommand,
|
12136 | ErrorCommand: ErrorCommand,
|
12137 | DirectCommand: DirectCommand,
|
12138 | AckCommand: AckCommand,
|
12139 | UnreadCommand: UnreadCommand,
|
12140 | ConvCommand: ConvCommand,
|
12141 | RoomCommand: RoomCommand,
|
12142 | LogsCommand: LogsCommand,
|
12143 | RcpCommand: RcpCommand,
|
12144 | ReadTuple: ReadTuple,
|
12145 | MaxReadTuple: MaxReadTuple,
|
12146 | ReadCommand: ReadCommand,
|
12147 | PresenceCommand: PresenceCommand,
|
12148 | ReportCommand: ReportCommand,
|
12149 | GenericCommand: GenericCommand,
|
12150 | BlacklistCommand: BlacklistCommand,
|
12151 | PatchCommand: PatchCommand,
|
12152 | PatchItem: PatchItem,
|
12153 | ConvMemberInfo: ConvMemberInfo,
|
12154 | CommandType: CommandType,
|
12155 | OpType: OpType,
|
12156 | StatusType: StatusType
|
12157 | });
|
12158 |
|
12159 | var eventemitter3 = createCommonjsModule(function (module) {
|
12160 |
|
12161 | var has = Object.prototype.hasOwnProperty
|
12162 | , prefix = '~';
|
12163 |
|
12164 | |
12165 |
|
12166 |
|
12167 |
|
12168 |
|
12169 |
|
12170 |
|
12171 | function Events() {}
|
12172 |
|
12173 |
|
12174 |
|
12175 |
|
12176 |
|
12177 |
|
12178 |
|
12179 |
|
12180 | if (Object.create) {
|
12181 | Events.prototype = Object.create(null);
|
12182 |
|
12183 |
|
12184 |
|
12185 |
|
12186 |
|
12187 | if (!new Events().__proto__) prefix = false;
|
12188 | }
|
12189 |
|
12190 | |
12191 |
|
12192 |
|
12193 |
|
12194 |
|
12195 |
|
12196 |
|
12197 |
|
12198 |
|
12199 | function EE(fn, context, once) {
|
12200 | this.fn = fn;
|
12201 | this.context = context;
|
12202 | this.once = once || false;
|
12203 | }
|
12204 |
|
12205 | |
12206 |
|
12207 |
|
12208 |
|
12209 |
|
12210 |
|
12211 |
|
12212 |
|
12213 |
|
12214 |
|
12215 |
|
12216 | function addListener(emitter, event, fn, context, once) {
|
12217 | if (typeof fn !== 'function') {
|
12218 | throw new TypeError('The listener must be a function');
|
12219 | }
|
12220 |
|
12221 | var listener = new EE(fn, context || emitter, once)
|
12222 | , evt = prefix ? prefix + event : event;
|
12223 |
|
12224 | if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
12225 | else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
12226 | else emitter._events[evt] = [emitter._events[evt], listener];
|
12227 |
|
12228 | return emitter;
|
12229 | }
|
12230 |
|
12231 | |
12232 |
|
12233 |
|
12234 |
|
12235 |
|
12236 |
|
12237 |
|
12238 | function clearEvent(emitter, evt) {
|
12239 | if (--emitter._eventsCount === 0) emitter._events = new Events();
|
12240 | else delete emitter._events[evt];
|
12241 | }
|
12242 |
|
12243 | |
12244 |
|
12245 |
|
12246 |
|
12247 |
|
12248 |
|
12249 |
|
12250 | function EventEmitter() {
|
12251 | this._events = new Events();
|
12252 | this._eventsCount = 0;
|
12253 | }
|
12254 |
|
12255 | |
12256 |
|
12257 |
|
12258 |
|
12259 |
|
12260 |
|
12261 |
|
12262 | EventEmitter.prototype.eventNames = function eventNames() {
|
12263 | var names = []
|
12264 | , events
|
12265 | , name;
|
12266 |
|
12267 | if (this._eventsCount === 0) return names;
|
12268 |
|
12269 | for (name in (events = this._events)) {
|
12270 | if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
12271 | }
|
12272 |
|
12273 | if (Object.getOwnPropertySymbols) {
|
12274 | return names.concat(Object.getOwnPropertySymbols(events));
|
12275 | }
|
12276 |
|
12277 | return names;
|
12278 | };
|
12279 |
|
12280 | |
12281 |
|
12282 |
|
12283 |
|
12284 |
|
12285 |
|
12286 |
|
12287 | EventEmitter.prototype.listeners = function listeners(event) {
|
12288 | var evt = prefix ? prefix + event : event
|
12289 | , handlers = this._events[evt];
|
12290 |
|
12291 | if (!handlers) return [];
|
12292 | if (handlers.fn) return [handlers.fn];
|
12293 |
|
12294 | for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
12295 | ee[i] = handlers[i].fn;
|
12296 | }
|
12297 |
|
12298 | return ee;
|
12299 | };
|
12300 |
|
12301 | |
12302 |
|
12303 |
|
12304 |
|
12305 |
|
12306 |
|
12307 |
|
12308 | EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
12309 | var evt = prefix ? prefix + event : event
|
12310 | , listeners = this._events[evt];
|
12311 |
|
12312 | if (!listeners) return 0;
|
12313 | if (listeners.fn) return 1;
|
12314 | return listeners.length;
|
12315 | };
|
12316 |
|
12317 | |
12318 |
|
12319 |
|
12320 |
|
12321 |
|
12322 |
|
12323 |
|
12324 | EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
12325 | var evt = prefix ? prefix + event : event;
|
12326 |
|
12327 | if (!this._events[evt]) return false;
|
12328 |
|
12329 | var listeners = this._events[evt]
|
12330 | , len = arguments.length
|
12331 | , args
|
12332 | , i;
|
12333 |
|
12334 | if (listeners.fn) {
|
12335 | if (listeners.once) this.removeListener(event, listeners.fn, undefined, true);
|
12336 |
|
12337 | switch (len) {
|
12338 | case 1: return listeners.fn.call(listeners.context), true;
|
12339 | case 2: return listeners.fn.call(listeners.context, a1), true;
|
12340 | case 3: return listeners.fn.call(listeners.context, a1, a2), true;
|
12341 | case 4: return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
12342 | case 5: return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
12343 | case 6: return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
12344 | }
|
12345 |
|
12346 | for (i = 1, args = new Array(len -1); i < len; i++) {
|
12347 | args[i - 1] = arguments[i];
|
12348 | }
|
12349 |
|
12350 | listeners.fn.apply(listeners.context, args);
|
12351 | } else {
|
12352 | var length = listeners.length
|
12353 | , j;
|
12354 |
|
12355 | for (i = 0; i < length; i++) {
|
12356 | if (listeners[i].once) this.removeListener(event, listeners[i].fn, undefined, true);
|
12357 |
|
12358 | switch (len) {
|
12359 | case 1: listeners[i].fn.call(listeners[i].context); break;
|
12360 | case 2: listeners[i].fn.call(listeners[i].context, a1); break;
|
12361 | case 3: listeners[i].fn.call(listeners[i].context, a1, a2); break;
|
12362 | case 4: listeners[i].fn.call(listeners[i].context, a1, a2, a3); break;
|
12363 | default:
|
12364 | if (!args) for (j = 1, args = new Array(len -1); j < len; j++) {
|
12365 | args[j - 1] = arguments[j];
|
12366 | }
|
12367 |
|
12368 | listeners[i].fn.apply(listeners[i].context, args);
|
12369 | }
|
12370 | }
|
12371 | }
|
12372 |
|
12373 | return true;
|
12374 | };
|
12375 |
|
12376 | |
12377 |
|
12378 |
|
12379 |
|
12380 |
|
12381 |
|
12382 |
|
12383 |
|
12384 |
|
12385 | EventEmitter.prototype.on = function on(event, fn, context) {
|
12386 | return addListener(this, event, fn, context, false);
|
12387 | };
|
12388 |
|
12389 | |
12390 |
|
12391 |
|
12392 |
|
12393 |
|
12394 |
|
12395 |
|
12396 |
|
12397 |
|
12398 | EventEmitter.prototype.once = function once(event, fn, context) {
|
12399 | return addListener(this, event, fn, context, true);
|
12400 | };
|
12401 |
|
12402 | |
12403 |
|
12404 |
|
12405 |
|
12406 |
|
12407 |
|
12408 |
|
12409 |
|
12410 |
|
12411 |
|
12412 | EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
12413 | var evt = prefix ? prefix + event : event;
|
12414 |
|
12415 | if (!this._events[evt]) return this;
|
12416 | if (!fn) {
|
12417 | clearEvent(this, evt);
|
12418 | return this;
|
12419 | }
|
12420 |
|
12421 | var listeners = this._events[evt];
|
12422 |
|
12423 | if (listeners.fn) {
|
12424 | if (
|
12425 | listeners.fn === fn &&
|
12426 | (!once || listeners.once) &&
|
12427 | (!context || listeners.context === context)
|
12428 | ) {
|
12429 | clearEvent(this, evt);
|
12430 | }
|
12431 | } else {
|
12432 | for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
12433 | if (
|
12434 | listeners[i].fn !== fn ||
|
12435 | (once && !listeners[i].once) ||
|
12436 | (context && listeners[i].context !== context)
|
12437 | ) {
|
12438 | events.push(listeners[i]);
|
12439 | }
|
12440 | }
|
12441 |
|
12442 |
|
12443 |
|
12444 |
|
12445 | if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
12446 | else clearEvent(this, evt);
|
12447 | }
|
12448 |
|
12449 | return this;
|
12450 | };
|
12451 |
|
12452 | |
12453 |
|
12454 |
|
12455 |
|
12456 |
|
12457 |
|
12458 |
|
12459 | EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
12460 | var evt;
|
12461 |
|
12462 | if (event) {
|
12463 | evt = prefix ? prefix + event : event;
|
12464 | if (this._events[evt]) clearEvent(this, evt);
|
12465 | } else {
|
12466 | this._events = new Events();
|
12467 | this._eventsCount = 0;
|
12468 | }
|
12469 |
|
12470 | return this;
|
12471 | };
|
12472 |
|
12473 |
|
12474 |
|
12475 |
|
12476 | EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
12477 | EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
12478 |
|
12479 |
|
12480 |
|
12481 |
|
12482 | EventEmitter.prefixed = prefix;
|
12483 |
|
12484 |
|
12485 |
|
12486 |
|
12487 | EventEmitter.EventEmitter = EventEmitter;
|
12488 |
|
12489 |
|
12490 |
|
12491 |
|
12492 | {
|
12493 | module.exports = EventEmitter;
|
12494 | }
|
12495 | });
|
12496 |
|
12497 | var runtime = createCommonjsModule(function (module) {
|
12498 | |
12499 |
|
12500 |
|
12501 |
|
12502 |
|
12503 |
|
12504 |
|
12505 | !(function(global) {
|
12506 |
|
12507 | var Op = Object.prototype;
|
12508 | var hasOwn = Op.hasOwnProperty;
|
12509 | var undefined$1;
|
12510 | var $Symbol = typeof Symbol === "function" ? Symbol : {};
|
12511 | var iteratorSymbol = $Symbol.iterator || "@@iterator";
|
12512 | var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
|
12513 | var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
12514 | var runtime = global.regeneratorRuntime;
|
12515 | if (runtime) {
|
12516 | {
|
12517 |
|
12518 |
|
12519 | module.exports = runtime;
|
12520 | }
|
12521 |
|
12522 |
|
12523 | return;
|
12524 | }
|
12525 |
|
12526 |
|
12527 |
|
12528 | runtime = global.regeneratorRuntime = module.exports;
|
12529 |
|
12530 | function wrap(innerFn, outerFn, self, tryLocsList) {
|
12531 |
|
12532 | var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
|
12533 | var generator = Object.create(protoGenerator.prototype);
|
12534 | var context = new Context(tryLocsList || []);
|
12535 |
|
12536 |
|
12537 |
|
12538 | generator._invoke = makeInvokeMethod(innerFn, self, context);
|
12539 |
|
12540 | return generator;
|
12541 | }
|
12542 | runtime.wrap = wrap;
|
12543 |
|
12544 |
|
12545 |
|
12546 |
|
12547 |
|
12548 |
|
12549 |
|
12550 |
|
12551 |
|
12552 |
|
12553 |
|
12554 | function tryCatch(fn, obj, arg) {
|
12555 | try {
|
12556 | return { type: "normal", arg: fn.call(obj, arg) };
|
12557 | } catch (err) {
|
12558 | return { type: "throw", arg: err };
|
12559 | }
|
12560 | }
|
12561 |
|
12562 | var GenStateSuspendedStart = "suspendedStart";
|
12563 | var GenStateSuspendedYield = "suspendedYield";
|
12564 | var GenStateExecuting = "executing";
|
12565 | var GenStateCompleted = "completed";
|
12566 |
|
12567 |
|
12568 |
|
12569 | var ContinueSentinel = {};
|
12570 |
|
12571 |
|
12572 |
|
12573 |
|
12574 |
|
12575 | function Generator() {}
|
12576 | function GeneratorFunction() {}
|
12577 | function GeneratorFunctionPrototype() {}
|
12578 |
|
12579 |
|
12580 |
|
12581 | var IteratorPrototype = {};
|
12582 | IteratorPrototype[iteratorSymbol] = function () {
|
12583 | return this;
|
12584 | };
|
12585 |
|
12586 | var getProto = Object.getPrototypeOf;
|
12587 | var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
12588 | if (NativeIteratorPrototype &&
|
12589 | NativeIteratorPrototype !== Op &&
|
12590 | hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
|
12591 |
|
12592 |
|
12593 | IteratorPrototype = NativeIteratorPrototype;
|
12594 | }
|
12595 |
|
12596 | var Gp = GeneratorFunctionPrototype.prototype =
|
12597 | Generator.prototype = Object.create(IteratorPrototype);
|
12598 | GeneratorFunction.prototype = Gp.constructor = GeneratorFunctionPrototype;
|
12599 | GeneratorFunctionPrototype.constructor = GeneratorFunction;
|
12600 | GeneratorFunctionPrototype[toStringTagSymbol] =
|
12601 | GeneratorFunction.displayName = "GeneratorFunction";
|
12602 |
|
12603 |
|
12604 |
|
12605 | function defineIteratorMethods(prototype) {
|
12606 | ["next", "throw", "return"].forEach(function(method) {
|
12607 | prototype[method] = function(arg) {
|
12608 | return this._invoke(method, arg);
|
12609 | };
|
12610 | });
|
12611 | }
|
12612 |
|
12613 | runtime.isGeneratorFunction = function(genFun) {
|
12614 | var ctor = typeof genFun === "function" && genFun.constructor;
|
12615 | return ctor
|
12616 | ? ctor === GeneratorFunction ||
|
12617 |
|
12618 |
|
12619 | (ctor.displayName || ctor.name) === "GeneratorFunction"
|
12620 | : false;
|
12621 | };
|
12622 |
|
12623 | runtime.mark = function(genFun) {
|
12624 | if (Object.setPrototypeOf) {
|
12625 | Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
|
12626 | } else {
|
12627 | genFun.__proto__ = GeneratorFunctionPrototype;
|
12628 | if (!(toStringTagSymbol in genFun)) {
|
12629 | genFun[toStringTagSymbol] = "GeneratorFunction";
|
12630 | }
|
12631 | }
|
12632 | genFun.prototype = Object.create(Gp);
|
12633 | return genFun;
|
12634 | };
|
12635 |
|
12636 |
|
12637 |
|
12638 |
|
12639 |
|
12640 | runtime.awrap = function(arg) {
|
12641 | return { __await: arg };
|
12642 | };
|
12643 |
|
12644 | function AsyncIterator(generator) {
|
12645 | function invoke(method, arg, resolve, reject) {
|
12646 | var record = tryCatch(generator[method], generator, arg);
|
12647 | if (record.type === "throw") {
|
12648 | reject(record.arg);
|
12649 | } else {
|
12650 | var result = record.arg;
|
12651 | var value = result.value;
|
12652 | if (value &&
|
12653 | typeof value === "object" &&
|
12654 | hasOwn.call(value, "__await")) {
|
12655 | return Promise.resolve(value.__await).then(function(value) {
|
12656 | invoke("next", value, resolve, reject);
|
12657 | }, function(err) {
|
12658 | invoke("throw", err, resolve, reject);
|
12659 | });
|
12660 | }
|
12661 |
|
12662 | return Promise.resolve(value).then(function(unwrapped) {
|
12663 |
|
12664 |
|
12665 |
|
12666 | result.value = unwrapped;
|
12667 | resolve(result);
|
12668 | }, function(error) {
|
12669 |
|
12670 |
|
12671 | return invoke("throw", error, resolve, reject);
|
12672 | });
|
12673 | }
|
12674 | }
|
12675 |
|
12676 | var previousPromise;
|
12677 |
|
12678 | function enqueue(method, arg) {
|
12679 | function callInvokeWithMethodAndArg() {
|
12680 | return new Promise(function(resolve, reject) {
|
12681 | invoke(method, arg, resolve, reject);
|
12682 | });
|
12683 | }
|
12684 |
|
12685 | return previousPromise =
|
12686 |
|
12687 |
|
12688 |
|
12689 |
|
12690 |
|
12691 |
|
12692 |
|
12693 |
|
12694 |
|
12695 |
|
12696 |
|
12697 |
|
12698 | previousPromise ? previousPromise.then(
|
12699 | callInvokeWithMethodAndArg,
|
12700 |
|
12701 |
|
12702 | callInvokeWithMethodAndArg
|
12703 | ) : callInvokeWithMethodAndArg();
|
12704 | }
|
12705 |
|
12706 |
|
12707 |
|
12708 | this._invoke = enqueue;
|
12709 | }
|
12710 |
|
12711 | defineIteratorMethods(AsyncIterator.prototype);
|
12712 | AsyncIterator.prototype[asyncIteratorSymbol] = function () {
|
12713 | return this;
|
12714 | };
|
12715 | runtime.AsyncIterator = AsyncIterator;
|
12716 |
|
12717 |
|
12718 |
|
12719 |
|
12720 | runtime.async = function(innerFn, outerFn, self, tryLocsList) {
|
12721 | var iter = new AsyncIterator(
|
12722 | wrap(innerFn, outerFn, self, tryLocsList)
|
12723 | );
|
12724 |
|
12725 | return runtime.isGeneratorFunction(outerFn)
|
12726 | ? iter
|
12727 | : iter.next().then(function(result) {
|
12728 | return result.done ? result.value : iter.next();
|
12729 | });
|
12730 | };
|
12731 |
|
12732 | function makeInvokeMethod(innerFn, self, context) {
|
12733 | var state = GenStateSuspendedStart;
|
12734 |
|
12735 | return function invoke(method, arg) {
|
12736 | if (state === GenStateExecuting) {
|
12737 | throw new Error("Generator is already running");
|
12738 | }
|
12739 |
|
12740 | if (state === GenStateCompleted) {
|
12741 | if (method === "throw") {
|
12742 | throw arg;
|
12743 | }
|
12744 |
|
12745 |
|
12746 |
|
12747 | return doneResult();
|
12748 | }
|
12749 |
|
12750 | context.method = method;
|
12751 | context.arg = arg;
|
12752 |
|
12753 | while (true) {
|
12754 | var delegate = context.delegate;
|
12755 | if (delegate) {
|
12756 | var delegateResult = maybeInvokeDelegate(delegate, context);
|
12757 | if (delegateResult) {
|
12758 | if (delegateResult === ContinueSentinel) continue;
|
12759 | return delegateResult;
|
12760 | }
|
12761 | }
|
12762 |
|
12763 | if (context.method === "next") {
|
12764 |
|
12765 |
|
12766 | context.sent = context._sent = context.arg;
|
12767 |
|
12768 | } else if (context.method === "throw") {
|
12769 | if (state === GenStateSuspendedStart) {
|
12770 | state = GenStateCompleted;
|
12771 | throw context.arg;
|
12772 | }
|
12773 |
|
12774 | context.dispatchException(context.arg);
|
12775 |
|
12776 | } else if (context.method === "return") {
|
12777 | context.abrupt("return", context.arg);
|
12778 | }
|
12779 |
|
12780 | state = GenStateExecuting;
|
12781 |
|
12782 | var record = tryCatch(innerFn, self, context);
|
12783 | if (record.type === "normal") {
|
12784 |
|
12785 |
|
12786 | state = context.done
|
12787 | ? GenStateCompleted
|
12788 | : GenStateSuspendedYield;
|
12789 |
|
12790 | if (record.arg === ContinueSentinel) {
|
12791 | continue;
|
12792 | }
|
12793 |
|
12794 | return {
|
12795 | value: record.arg,
|
12796 | done: context.done
|
12797 | };
|
12798 |
|
12799 | } else if (record.type === "throw") {
|
12800 | state = GenStateCompleted;
|
12801 |
|
12802 |
|
12803 | context.method = "throw";
|
12804 | context.arg = record.arg;
|
12805 | }
|
12806 | }
|
12807 | };
|
12808 | }
|
12809 |
|
12810 |
|
12811 |
|
12812 |
|
12813 |
|
12814 | function maybeInvokeDelegate(delegate, context) {
|
12815 | var method = delegate.iterator[context.method];
|
12816 | if (method === undefined$1) {
|
12817 |
|
12818 |
|
12819 | context.delegate = null;
|
12820 |
|
12821 | if (context.method === "throw") {
|
12822 | if (delegate.iterator.return) {
|
12823 |
|
12824 |
|
12825 | context.method = "return";
|
12826 | context.arg = undefined$1;
|
12827 | maybeInvokeDelegate(delegate, context);
|
12828 |
|
12829 | if (context.method === "throw") {
|
12830 |
|
12831 |
|
12832 | return ContinueSentinel;
|
12833 | }
|
12834 | }
|
12835 |
|
12836 | context.method = "throw";
|
12837 | context.arg = new TypeError(
|
12838 | "The iterator does not provide a 'throw' method");
|
12839 | }
|
12840 |
|
12841 | return ContinueSentinel;
|
12842 | }
|
12843 |
|
12844 | var record = tryCatch(method, delegate.iterator, context.arg);
|
12845 |
|
12846 | if (record.type === "throw") {
|
12847 | context.method = "throw";
|
12848 | context.arg = record.arg;
|
12849 | context.delegate = null;
|
12850 | return ContinueSentinel;
|
12851 | }
|
12852 |
|
12853 | var info = record.arg;
|
12854 |
|
12855 | if (! info) {
|
12856 | context.method = "throw";
|
12857 | context.arg = new TypeError("iterator result is not an object");
|
12858 | context.delegate = null;
|
12859 | return ContinueSentinel;
|
12860 | }
|
12861 |
|
12862 | if (info.done) {
|
12863 |
|
12864 |
|
12865 | context[delegate.resultName] = info.value;
|
12866 |
|
12867 |
|
12868 | context.next = delegate.nextLoc;
|
12869 |
|
12870 |
|
12871 |
|
12872 |
|
12873 |
|
12874 |
|
12875 |
|
12876 | if (context.method !== "return") {
|
12877 | context.method = "next";
|
12878 | context.arg = undefined$1;
|
12879 | }
|
12880 |
|
12881 | } else {
|
12882 |
|
12883 | return info;
|
12884 | }
|
12885 |
|
12886 |
|
12887 |
|
12888 | context.delegate = null;
|
12889 | return ContinueSentinel;
|
12890 | }
|
12891 |
|
12892 |
|
12893 |
|
12894 | defineIteratorMethods(Gp);
|
12895 |
|
12896 | Gp[toStringTagSymbol] = "Generator";
|
12897 |
|
12898 |
|
12899 |
|
12900 |
|
12901 |
|
12902 |
|
12903 | Gp[iteratorSymbol] = function() {
|
12904 | return this;
|
12905 | };
|
12906 |
|
12907 | Gp.toString = function() {
|
12908 | return "[object Generator]";
|
12909 | };
|
12910 |
|
12911 | function pushTryEntry(locs) {
|
12912 | var entry = { tryLoc: locs[0] };
|
12913 |
|
12914 | if (1 in locs) {
|
12915 | entry.catchLoc = locs[1];
|
12916 | }
|
12917 |
|
12918 | if (2 in locs) {
|
12919 | entry.finallyLoc = locs[2];
|
12920 | entry.afterLoc = locs[3];
|
12921 | }
|
12922 |
|
12923 | this.tryEntries.push(entry);
|
12924 | }
|
12925 |
|
12926 | function resetTryEntry(entry) {
|
12927 | var record = entry.completion || {};
|
12928 | record.type = "normal";
|
12929 | delete record.arg;
|
12930 | entry.completion = record;
|
12931 | }
|
12932 |
|
12933 | function Context(tryLocsList) {
|
12934 |
|
12935 |
|
12936 |
|
12937 | this.tryEntries = [{ tryLoc: "root" }];
|
12938 | tryLocsList.forEach(pushTryEntry, this);
|
12939 | this.reset(true);
|
12940 | }
|
12941 |
|
12942 | runtime.keys = function(object) {
|
12943 | var keys = [];
|
12944 | for (var key in object) {
|
12945 | keys.push(key);
|
12946 | }
|
12947 | keys.reverse();
|
12948 |
|
12949 |
|
12950 |
|
12951 | return function next() {
|
12952 | while (keys.length) {
|
12953 | var key = keys.pop();
|
12954 | if (key in object) {
|
12955 | next.value = key;
|
12956 | next.done = false;
|
12957 | return next;
|
12958 | }
|
12959 | }
|
12960 |
|
12961 |
|
12962 |
|
12963 |
|
12964 | next.done = true;
|
12965 | return next;
|
12966 | };
|
12967 | };
|
12968 |
|
12969 | function values(iterable) {
|
12970 | if (iterable) {
|
12971 | var iteratorMethod = iterable[iteratorSymbol];
|
12972 | if (iteratorMethod) {
|
12973 | return iteratorMethod.call(iterable);
|
12974 | }
|
12975 |
|
12976 | if (typeof iterable.next === "function") {
|
12977 | return iterable;
|
12978 | }
|
12979 |
|
12980 | if (!isNaN(iterable.length)) {
|
12981 | var i = -1, next = function next() {
|
12982 | while (++i < iterable.length) {
|
12983 | if (hasOwn.call(iterable, i)) {
|
12984 | next.value = iterable[i];
|
12985 | next.done = false;
|
12986 | return next;
|
12987 | }
|
12988 | }
|
12989 |
|
12990 | next.value = undefined$1;
|
12991 | next.done = true;
|
12992 |
|
12993 | return next;
|
12994 | };
|
12995 |
|
12996 | return next.next = next;
|
12997 | }
|
12998 | }
|
12999 |
|
13000 |
|
13001 | return { next: doneResult };
|
13002 | }
|
13003 | runtime.values = values;
|
13004 |
|
13005 | function doneResult() {
|
13006 | return { value: undefined$1, done: true };
|
13007 | }
|
13008 |
|
13009 | Context.prototype = {
|
13010 | constructor: Context,
|
13011 |
|
13012 | reset: function(skipTempReset) {
|
13013 | this.prev = 0;
|
13014 | this.next = 0;
|
13015 |
|
13016 |
|
13017 | this.sent = this._sent = undefined$1;
|
13018 | this.done = false;
|
13019 | this.delegate = null;
|
13020 |
|
13021 | this.method = "next";
|
13022 | this.arg = undefined$1;
|
13023 |
|
13024 | this.tryEntries.forEach(resetTryEntry);
|
13025 |
|
13026 | if (!skipTempReset) {
|
13027 | for (var name in this) {
|
13028 |
|
13029 | if (name.charAt(0) === "t" &&
|
13030 | hasOwn.call(this, name) &&
|
13031 | !isNaN(+name.slice(1))) {
|
13032 | this[name] = undefined$1;
|
13033 | }
|
13034 | }
|
13035 | }
|
13036 | },
|
13037 |
|
13038 | stop: function() {
|
13039 | this.done = true;
|
13040 |
|
13041 | var rootEntry = this.tryEntries[0];
|
13042 | var rootRecord = rootEntry.completion;
|
13043 | if (rootRecord.type === "throw") {
|
13044 | throw rootRecord.arg;
|
13045 | }
|
13046 |
|
13047 | return this.rval;
|
13048 | },
|
13049 |
|
13050 | dispatchException: function(exception) {
|
13051 | if (this.done) {
|
13052 | throw exception;
|
13053 | }
|
13054 |
|
13055 | var context = this;
|
13056 | function handle(loc, caught) {
|
13057 | record.type = "throw";
|
13058 | record.arg = exception;
|
13059 | context.next = loc;
|
13060 |
|
13061 | if (caught) {
|
13062 |
|
13063 |
|
13064 | context.method = "next";
|
13065 | context.arg = undefined$1;
|
13066 | }
|
13067 |
|
13068 | return !! caught;
|
13069 | }
|
13070 |
|
13071 | for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
13072 | var entry = this.tryEntries[i];
|
13073 | var record = entry.completion;
|
13074 |
|
13075 | if (entry.tryLoc === "root") {
|
13076 |
|
13077 |
|
13078 |
|
13079 | return handle("end");
|
13080 | }
|
13081 |
|
13082 | if (entry.tryLoc <= this.prev) {
|
13083 | var hasCatch = hasOwn.call(entry, "catchLoc");
|
13084 | var hasFinally = hasOwn.call(entry, "finallyLoc");
|
13085 |
|
13086 | if (hasCatch && hasFinally) {
|
13087 | if (this.prev < entry.catchLoc) {
|
13088 | return handle(entry.catchLoc, true);
|
13089 | } else if (this.prev < entry.finallyLoc) {
|
13090 | return handle(entry.finallyLoc);
|
13091 | }
|
13092 |
|
13093 | } else if (hasCatch) {
|
13094 | if (this.prev < entry.catchLoc) {
|
13095 | return handle(entry.catchLoc, true);
|
13096 | }
|
13097 |
|
13098 | } else if (hasFinally) {
|
13099 | if (this.prev < entry.finallyLoc) {
|
13100 | return handle(entry.finallyLoc);
|
13101 | }
|
13102 |
|
13103 | } else {
|
13104 | throw new Error("try statement without catch or finally");
|
13105 | }
|
13106 | }
|
13107 | }
|
13108 | },
|
13109 |
|
13110 | abrupt: function(type, arg) {
|
13111 | for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
13112 | var entry = this.tryEntries[i];
|
13113 | if (entry.tryLoc <= this.prev &&
|
13114 | hasOwn.call(entry, "finallyLoc") &&
|
13115 | this.prev < entry.finallyLoc) {
|
13116 | var finallyEntry = entry;
|
13117 | break;
|
13118 | }
|
13119 | }
|
13120 |
|
13121 | if (finallyEntry &&
|
13122 | (type === "break" ||
|
13123 | type === "continue") &&
|
13124 | finallyEntry.tryLoc <= arg &&
|
13125 | arg <= finallyEntry.finallyLoc) {
|
13126 |
|
13127 |
|
13128 | finallyEntry = null;
|
13129 | }
|
13130 |
|
13131 | var record = finallyEntry ? finallyEntry.completion : {};
|
13132 | record.type = type;
|
13133 | record.arg = arg;
|
13134 |
|
13135 | if (finallyEntry) {
|
13136 | this.method = "next";
|
13137 | this.next = finallyEntry.finallyLoc;
|
13138 | return ContinueSentinel;
|
13139 | }
|
13140 |
|
13141 | return this.complete(record);
|
13142 | },
|
13143 |
|
13144 | complete: function(record, afterLoc) {
|
13145 | if (record.type === "throw") {
|
13146 | throw record.arg;
|
13147 | }
|
13148 |
|
13149 | if (record.type === "break" ||
|
13150 | record.type === "continue") {
|
13151 | this.next = record.arg;
|
13152 | } else if (record.type === "return") {
|
13153 | this.rval = this.arg = record.arg;
|
13154 | this.method = "return";
|
13155 | this.next = "end";
|
13156 | } else if (record.type === "normal" && afterLoc) {
|
13157 | this.next = afterLoc;
|
13158 | }
|
13159 |
|
13160 | return ContinueSentinel;
|
13161 | },
|
13162 |
|
13163 | finish: function(finallyLoc) {
|
13164 | for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
13165 | var entry = this.tryEntries[i];
|
13166 | if (entry.finallyLoc === finallyLoc) {
|
13167 | this.complete(entry.completion, entry.afterLoc);
|
13168 | resetTryEntry(entry);
|
13169 | return ContinueSentinel;
|
13170 | }
|
13171 | }
|
13172 | },
|
13173 |
|
13174 | "catch": function(tryLoc) {
|
13175 | for (var i = this.tryEntries.length - 1; i >= 0; --i) {
|
13176 | var entry = this.tryEntries[i];
|
13177 | if (entry.tryLoc === tryLoc) {
|
13178 | var record = entry.completion;
|
13179 | if (record.type === "throw") {
|
13180 | var thrown = record.arg;
|
13181 | resetTryEntry(entry);
|
13182 | }
|
13183 | return thrown;
|
13184 | }
|
13185 | }
|
13186 |
|
13187 |
|
13188 |
|
13189 | throw new Error("illegal catch attempt");
|
13190 | },
|
13191 |
|
13192 | delegateYield: function(iterable, resultName, nextLoc) {
|
13193 | this.delegate = {
|
13194 | iterator: values(iterable),
|
13195 | resultName: resultName,
|
13196 | nextLoc: nextLoc
|
13197 | };
|
13198 |
|
13199 | if (this.method === "next") {
|
13200 |
|
13201 |
|
13202 | this.arg = undefined$1;
|
13203 | }
|
13204 |
|
13205 | return ContinueSentinel;
|
13206 | }
|
13207 | };
|
13208 | })(
|
13209 |
|
13210 |
|
13211 |
|
13212 | (function() {
|
13213 | return this || (typeof self === "object" && self);
|
13214 | })() || Function("return this")()
|
13215 | );
|
13216 | });
|
13217 |
|
13218 | |
13219 |
|
13220 |
|
13221 |
|
13222 |
|
13223 |
|
13224 |
|
13225 |
|
13226 |
|
13227 | var g = (function() {
|
13228 | return this || (typeof self === "object" && self);
|
13229 | })() || Function("return this")();
|
13230 |
|
13231 |
|
13232 |
|
13233 | var hadRuntime = g.regeneratorRuntime &&
|
13234 | Object.getOwnPropertyNames(g).indexOf("regeneratorRuntime") >= 0;
|
13235 |
|
13236 |
|
13237 | var oldRuntime = hadRuntime && g.regeneratorRuntime;
|
13238 |
|
13239 |
|
13240 | g.regeneratorRuntime = undefined;
|
13241 |
|
13242 | var runtimeModule = runtime;
|
13243 |
|
13244 | if (hadRuntime) {
|
13245 |
|
13246 | g.regeneratorRuntime = oldRuntime;
|
13247 | } else {
|
13248 |
|
13249 | try {
|
13250 | delete g.regeneratorRuntime;
|
13251 | } catch(e) {
|
13252 | g.regeneratorRuntime = undefined;
|
13253 | }
|
13254 | }
|
13255 |
|
13256 | var regenerator = runtimeModule;
|
13257 |
|
13258 | |
13259 |
|
13260 |
|
13261 |
|
13262 | var s = 1000;
|
13263 | var m = s * 60;
|
13264 | var h = m * 60;
|
13265 | var d = h * 24;
|
13266 | var w = d * 7;
|
13267 | var y = d * 365.25;
|
13268 |
|
13269 | |
13270 |
|
13271 |
|
13272 |
|
13273 |
|
13274 |
|
13275 |
|
13276 |
|
13277 |
|
13278 |
|
13279 |
|
13280 |
|
13281 |
|
13282 |
|
13283 | var ms = function(val, options) {
|
13284 | options = options || {};
|
13285 | var type = typeof val;
|
13286 | if (type === 'string' && val.length > 0) {
|
13287 | return parse(val);
|
13288 | } else if (type === 'number' && isNaN(val) === false) {
|
13289 | return options.long ? fmtLong(val) : fmtShort(val);
|
13290 | }
|
13291 | throw new Error(
|
13292 | 'val is not a non-empty string or a valid number. val=' +
|
13293 | JSON.stringify(val)
|
13294 | );
|
13295 | };
|
13296 |
|
13297 | |
13298 |
|
13299 |
|
13300 |
|
13301 |
|
13302 |
|
13303 |
|
13304 |
|
13305 | function parse(str) {
|
13306 | str = String(str);
|
13307 | if (str.length > 100) {
|
13308 | return;
|
13309 | }
|
13310 | var match = /^((?:\d+)?\-?\d?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(
|
13311 | str
|
13312 | );
|
13313 | if (!match) {
|
13314 | return;
|
13315 | }
|
13316 | var n = parseFloat(match[1]);
|
13317 | var type = (match[2] || 'ms').toLowerCase();
|
13318 | switch (type) {
|
13319 | case 'years':
|
13320 | case 'year':
|
13321 | case 'yrs':
|
13322 | case 'yr':
|
13323 | case 'y':
|
13324 | return n * y;
|
13325 | case 'weeks':
|
13326 | case 'week':
|
13327 | case 'w':
|
13328 | return n * w;
|
13329 | case 'days':
|
13330 | case 'day':
|
13331 | case 'd':
|
13332 | return n * d;
|
13333 | case 'hours':
|
13334 | case 'hour':
|
13335 | case 'hrs':
|
13336 | case 'hr':
|
13337 | case 'h':
|
13338 | return n * h;
|
13339 | case 'minutes':
|
13340 | case 'minute':
|
13341 | case 'mins':
|
13342 | case 'min':
|
13343 | case 'm':
|
13344 | return n * m;
|
13345 | case 'seconds':
|
13346 | case 'second':
|
13347 | case 'secs':
|
13348 | case 'sec':
|
13349 | case 's':
|
13350 | return n * s;
|
13351 | case 'milliseconds':
|
13352 | case 'millisecond':
|
13353 | case 'msecs':
|
13354 | case 'msec':
|
13355 | case 'ms':
|
13356 | return n;
|
13357 | default:
|
13358 | return undefined;
|
13359 | }
|
13360 | }
|
13361 |
|
13362 | |
13363 |
|
13364 |
|
13365 |
|
13366 |
|
13367 |
|
13368 |
|
13369 |
|
13370 | function fmtShort(ms) {
|
13371 | var msAbs = Math.abs(ms);
|
13372 | if (msAbs >= d) {
|
13373 | return Math.round(ms / d) + 'd';
|
13374 | }
|
13375 | if (msAbs >= h) {
|
13376 | return Math.round(ms / h) + 'h';
|
13377 | }
|
13378 | if (msAbs >= m) {
|
13379 | return Math.round(ms / m) + 'm';
|
13380 | }
|
13381 | if (msAbs >= s) {
|
13382 | return Math.round(ms / s) + 's';
|
13383 | }
|
13384 | return ms + 'ms';
|
13385 | }
|
13386 |
|
13387 | |
13388 |
|
13389 |
|
13390 |
|
13391 |
|
13392 |
|
13393 |
|
13394 |
|
13395 | function fmtLong(ms) {
|
13396 | var msAbs = Math.abs(ms);
|
13397 | if (msAbs >= d) {
|
13398 | return plural(ms, msAbs, d, 'day');
|
13399 | }
|
13400 | if (msAbs >= h) {
|
13401 | return plural(ms, msAbs, h, 'hour');
|
13402 | }
|
13403 | if (msAbs >= m) {
|
13404 | return plural(ms, msAbs, m, 'minute');
|
13405 | }
|
13406 | if (msAbs >= s) {
|
13407 | return plural(ms, msAbs, s, 'second');
|
13408 | }
|
13409 | return ms + ' ms';
|
13410 | }
|
13411 |
|
13412 | |
13413 |
|
13414 |
|
13415 |
|
13416 | function plural(ms, msAbs, n, name) {
|
13417 | var isPlural = msAbs >= n * 1.5;
|
13418 | return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
|
13419 | }
|
13420 |
|
13421 | |
13422 |
|
13423 |
|
13424 |
|
13425 | function setup(env) {
|
13426 | createDebug.debug = createDebug;
|
13427 | createDebug.default = createDebug;
|
13428 | createDebug.coerce = coerce;
|
13429 | createDebug.disable = disable;
|
13430 | createDebug.enable = enable;
|
13431 | createDebug.enabled = enabled;
|
13432 | createDebug.humanize = ms;
|
13433 | Object.keys(env).forEach(function (key) {
|
13434 | createDebug[key] = env[key];
|
13435 | });
|
13436 | |
13437 |
|
13438 |
|
13439 |
|
13440 | createDebug.instances = [];
|
13441 | |
13442 |
|
13443 |
|
13444 |
|
13445 | createDebug.names = [];
|
13446 | createDebug.skips = [];
|
13447 | |
13448 |
|
13449 |
|
13450 |
|
13451 |
|
13452 |
|
13453 | createDebug.formatters = {};
|
13454 | |
13455 |
|
13456 |
|
13457 |
|
13458 |
|
13459 |
|
13460 |
|
13461 | function selectColor(namespace) {
|
13462 | var hash = 0;
|
13463 |
|
13464 | for (var i = 0; i < namespace.length; i++) {
|
13465 | hash = (hash << 5) - hash + namespace.charCodeAt(i);
|
13466 | hash |= 0;
|
13467 | }
|
13468 |
|
13469 | return createDebug.colors[Math.abs(hash) % createDebug.colors.length];
|
13470 | }
|
13471 |
|
13472 | createDebug.selectColor = selectColor;
|
13473 | |
13474 |
|
13475 |
|
13476 |
|
13477 |
|
13478 |
|
13479 |
|
13480 |
|
13481 | function createDebug(namespace) {
|
13482 | var prevTime;
|
13483 |
|
13484 | function debug() {
|
13485 |
|
13486 | if (!debug.enabled) {
|
13487 | return;
|
13488 | }
|
13489 |
|
13490 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
13491 | args[_key] = arguments[_key];
|
13492 | }
|
13493 |
|
13494 | var self = debug;
|
13495 |
|
13496 | var curr = Number(new Date());
|
13497 | var ms = curr - (prevTime || curr);
|
13498 | self.diff = ms;
|
13499 | self.prev = prevTime;
|
13500 | self.curr = curr;
|
13501 | prevTime = curr;
|
13502 | args[0] = createDebug.coerce(args[0]);
|
13503 |
|
13504 | if (typeof args[0] !== 'string') {
|
13505 |
|
13506 | args.unshift('%O');
|
13507 | }
|
13508 |
|
13509 |
|
13510 | var index = 0;
|
13511 | args[0] = args[0].replace(/%([a-zA-Z%])/g, function (match, format) {
|
13512 |
|
13513 | if (match === '%%') {
|
13514 | return match;
|
13515 | }
|
13516 |
|
13517 | index++;
|
13518 | var formatter = createDebug.formatters[format];
|
13519 |
|
13520 | if (typeof formatter === 'function') {
|
13521 | var val = args[index];
|
13522 | match = formatter.call(self, val);
|
13523 |
|
13524 | args.splice(index, 1);
|
13525 | index--;
|
13526 | }
|
13527 |
|
13528 | return match;
|
13529 | });
|
13530 |
|
13531 | createDebug.formatArgs.call(self, args);
|
13532 | var logFn = self.log || createDebug.log;
|
13533 | logFn.apply(self, args);
|
13534 | }
|
13535 |
|
13536 | debug.namespace = namespace;
|
13537 | debug.enabled = createDebug.enabled(namespace);
|
13538 | debug.useColors = createDebug.useColors();
|
13539 | debug.color = selectColor(namespace);
|
13540 | debug.destroy = destroy;
|
13541 | debug.extend = extend;
|
13542 |
|
13543 |
|
13544 |
|
13545 | if (typeof createDebug.init === 'function') {
|
13546 | createDebug.init(debug);
|
13547 | }
|
13548 |
|
13549 | createDebug.instances.push(debug);
|
13550 | return debug;
|
13551 | }
|
13552 |
|
13553 | function destroy() {
|
13554 | var index = createDebug.instances.indexOf(this);
|
13555 |
|
13556 | if (index !== -1) {
|
13557 | createDebug.instances.splice(index, 1);
|
13558 | return true;
|
13559 | }
|
13560 |
|
13561 | return false;
|
13562 | }
|
13563 |
|
13564 | function extend(namespace, delimiter) {
|
13565 | return createDebug(this.namespace + (typeof delimiter === 'undefined' ? ':' : delimiter) + namespace);
|
13566 | }
|
13567 | |
13568 |
|
13569 |
|
13570 |
|
13571 |
|
13572 |
|
13573 |
|
13574 |
|
13575 |
|
13576 | function enable(namespaces) {
|
13577 | createDebug.save(namespaces);
|
13578 | createDebug.names = [];
|
13579 | createDebug.skips = [];
|
13580 | var i;
|
13581 | var split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
|
13582 | var len = split.length;
|
13583 |
|
13584 | for (i = 0; i < len; i++) {
|
13585 | if (!split[i]) {
|
13586 |
|
13587 | continue;
|
13588 | }
|
13589 |
|
13590 | namespaces = split[i].replace(/\*/g, '.*?');
|
13591 |
|
13592 | if (namespaces[0] === '-') {
|
13593 | createDebug.skips.push(new RegExp('^' + namespaces.substr(1) + '$'));
|
13594 | } else {
|
13595 | createDebug.names.push(new RegExp('^' + namespaces + '$'));
|
13596 | }
|
13597 | }
|
13598 |
|
13599 | for (i = 0; i < createDebug.instances.length; i++) {
|
13600 | var instance = createDebug.instances[i];
|
13601 | instance.enabled = createDebug.enabled(instance.namespace);
|
13602 | }
|
13603 | }
|
13604 | |
13605 |
|
13606 |
|
13607 |
|
13608 |
|
13609 |
|
13610 |
|
13611 | function disable() {
|
13612 | createDebug.enable('');
|
13613 | }
|
13614 | |
13615 |
|
13616 |
|
13617 |
|
13618 |
|
13619 |
|
13620 |
|
13621 |
|
13622 |
|
13623 | function enabled(name) {
|
13624 | if (name[name.length - 1] === '*') {
|
13625 | return true;
|
13626 | }
|
13627 |
|
13628 | var i;
|
13629 | var len;
|
13630 |
|
13631 | for (i = 0, len = createDebug.skips.length; i < len; i++) {
|
13632 | if (createDebug.skips[i].test(name)) {
|
13633 | return false;
|
13634 | }
|
13635 | }
|
13636 |
|
13637 | for (i = 0, len = createDebug.names.length; i < len; i++) {
|
13638 | if (createDebug.names[i].test(name)) {
|
13639 | return true;
|
13640 | }
|
13641 | }
|
13642 |
|
13643 | return false;
|
13644 | }
|
13645 | |
13646 |
|
13647 |
|
13648 |
|
13649 |
|
13650 |
|
13651 |
|
13652 |
|
13653 |
|
13654 | function coerce(val) {
|
13655 | if (val instanceof Error) {
|
13656 | return val.stack || val.message;
|
13657 | }
|
13658 |
|
13659 | return val;
|
13660 | }
|
13661 |
|
13662 | createDebug.enable(createDebug.load());
|
13663 | return createDebug;
|
13664 | }
|
13665 |
|
13666 | var common = setup;
|
13667 |
|
13668 | var browser = createCommonjsModule(function (module, exports) {
|
13669 |
|
13670 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
13671 |
|
13672 |
|
13673 |
|
13674 | |
13675 |
|
13676 |
|
13677 | exports.log = log;
|
13678 | exports.formatArgs = formatArgs;
|
13679 | exports.save = save;
|
13680 | exports.load = load;
|
13681 | exports.useColors = useColors;
|
13682 | exports.storage = localstorage();
|
13683 | |
13684 |
|
13685 |
|
13686 |
|
13687 | exports.colors = ['#0000CC', '#0000FF', '#0033CC', '#0033FF', '#0066CC', '#0066FF', '#0099CC', '#0099FF', '#00CC00', '#00CC33', '#00CC66', '#00CC99', '#00CCCC', '#00CCFF', '#3300CC', '#3300FF', '#3333CC', '#3333FF', '#3366CC', '#3366FF', '#3399CC', '#3399FF', '#33CC00', '#33CC33', '#33CC66', '#33CC99', '#33CCCC', '#33CCFF', '#6600CC', '#6600FF', '#6633CC', '#6633FF', '#66CC00', '#66CC33', '#9900CC', '#9900FF', '#9933CC', '#9933FF', '#99CC00', '#99CC33', '#CC0000', '#CC0033', '#CC0066', '#CC0099', '#CC00CC', '#CC00FF', '#CC3300', '#CC3333', '#CC3366', '#CC3399', '#CC33CC', '#CC33FF', '#CC6600', '#CC6633', '#CC9900', '#CC9933', '#CCCC00', '#CCCC33', '#FF0000', '#FF0033', '#FF0066', '#FF0099', '#FF00CC', '#FF00FF', '#FF3300', '#FF3333', '#FF3366', '#FF3399', '#FF33CC', '#FF33FF', '#FF6600', '#FF6633', '#FF9900', '#FF9933', '#FFCC00', '#FFCC33'];
|
13688 | |
13689 |
|
13690 |
|
13691 |
|
13692 |
|
13693 |
|
13694 |
|
13695 |
|
13696 |
|
13697 | function useColors() {
|
13698 |
|
13699 |
|
13700 |
|
13701 | if (typeof window !== 'undefined' && window.process && (window.process.type === 'renderer' || window.process.__nwjs)) {
|
13702 | return true;
|
13703 | }
|
13704 |
|
13705 |
|
13706 | if (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) {
|
13707 | return false;
|
13708 | }
|
13709 |
|
13710 |
|
13711 |
|
13712 | return typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance ||
|
13713 | typeof window !== 'undefined' && window.console && (window.console.firebug || window.console.exception && window.console.table) ||
|
13714 |
|
13715 | typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 ||
|
13716 | typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/);
|
13717 | }
|
13718 | |
13719 |
|
13720 |
|
13721 |
|
13722 |
|
13723 |
|
13724 |
|
13725 | function formatArgs(args) {
|
13726 | args[0] = (this.useColors ? '%c' : '') + this.namespace + (this.useColors ? ' %c' : ' ') + args[0] + (this.useColors ? '%c ' : ' ') + '+' + module.exports.humanize(this.diff);
|
13727 |
|
13728 | if (!this.useColors) {
|
13729 | return;
|
13730 | }
|
13731 |
|
13732 | var c = 'color: ' + this.color;
|
13733 | args.splice(1, 0, c, 'color: inherit');
|
13734 |
|
13735 |
|
13736 |
|
13737 | var index = 0;
|
13738 | var lastC = 0;
|
13739 | args[0].replace(/%[a-zA-Z%]/g, function (match) {
|
13740 | if (match === '%%') {
|
13741 | return;
|
13742 | }
|
13743 |
|
13744 | index++;
|
13745 |
|
13746 | if (match === '%c') {
|
13747 |
|
13748 |
|
13749 | lastC = index;
|
13750 | }
|
13751 | });
|
13752 | args.splice(lastC, 0, c);
|
13753 | }
|
13754 | |
13755 |
|
13756 |
|
13757 |
|
13758 |
|
13759 |
|
13760 |
|
13761 |
|
13762 | function log() {
|
13763 | var _console;
|
13764 |
|
13765 |
|
13766 |
|
13767 | return (typeof console === "undefined" ? "undefined" : _typeof(console)) === 'object' && console.log && (_console = console).log.apply(_console, arguments);
|
13768 | }
|
13769 | |
13770 |
|
13771 |
|
13772 |
|
13773 |
|
13774 |
|
13775 |
|
13776 |
|
13777 | function save(namespaces) {
|
13778 | try {
|
13779 | if (namespaces) {
|
13780 | exports.storage.setItem('debug', namespaces);
|
13781 | } else {
|
13782 | exports.storage.removeItem('debug');
|
13783 | }
|
13784 | } catch (error) {
|
13785 |
|
13786 | }
|
13787 | }
|
13788 | |
13789 |
|
13790 |
|
13791 |
|
13792 |
|
13793 |
|
13794 |
|
13795 |
|
13796 | function load() {
|
13797 | var r;
|
13798 |
|
13799 | try {
|
13800 | r = exports.storage.getItem('debug');
|
13801 | } catch (error) {}
|
13802 |
|
13803 |
|
13804 |
|
13805 |
|
13806 | if (!r && typeof process !== 'undefined' && 'env' in process) {
|
13807 | r = process.env.DEBUG;
|
13808 | }
|
13809 |
|
13810 | return r;
|
13811 | }
|
13812 | |
13813 |
|
13814 |
|
13815 |
|
13816 |
|
13817 |
|
13818 |
|
13819 |
|
13820 |
|
13821 |
|
13822 |
|
13823 |
|
13824 | function localstorage() {
|
13825 | try {
|
13826 |
|
13827 |
|
13828 | return localStorage;
|
13829 | } catch (error) {
|
13830 |
|
13831 | }
|
13832 | }
|
13833 |
|
13834 | module.exports = common(exports);
|
13835 | var formatters = module.exports.formatters;
|
13836 | |
13837 |
|
13838 |
|
13839 |
|
13840 | formatters.j = function (v) {
|
13841 | try {
|
13842 | return JSON.stringify(v);
|
13843 | } catch (error) {
|
13844 | return '[UnexpectedJSONParseError]: ' + error.message;
|
13845 | }
|
13846 | };
|
13847 | });
|
13848 | var browser_1 = browser.log;
|
13849 | var browser_2 = browser.formatArgs;
|
13850 | var browser_3 = browser.save;
|
13851 | var browser_4 = browser.load;
|
13852 | var browser_5 = browser.useColors;
|
13853 | var browser_6 = browser.storage;
|
13854 | var browser_7 = browser.colors;
|
13855 |
|
13856 | var componentEmitter = createCommonjsModule(function (module) {
|
13857 | |
13858 |
|
13859 |
|
13860 | {
|
13861 | module.exports = Emitter;
|
13862 | }
|
13863 | |
13864 |
|
13865 |
|
13866 |
|
13867 |
|
13868 |
|
13869 |
|
13870 | function Emitter(obj) {
|
13871 | if (obj) return mixin(obj);
|
13872 | }
|
13873 | |
13874 |
|
13875 |
|
13876 |
|
13877 |
|
13878 |
|
13879 |
|
13880 |
|
13881 | function mixin(obj) {
|
13882 | for (var key in Emitter.prototype) {
|
13883 | obj[key] = Emitter.prototype[key];
|
13884 | }
|
13885 |
|
13886 | return obj;
|
13887 | }
|
13888 | |
13889 |
|
13890 |
|
13891 |
|
13892 |
|
13893 |
|
13894 |
|
13895 |
|
13896 |
|
13897 |
|
13898 | Emitter.prototype.on = Emitter.prototype.addEventListener = function (event, fn) {
|
13899 | this._callbacks = this._callbacks || {};
|
13900 | (this._callbacks['$' + event] = this._callbacks['$' + event] || []).push(fn);
|
13901 | return this;
|
13902 | };
|
13903 | |
13904 |
|
13905 |
|
13906 |
|
13907 |
|
13908 |
|
13909 |
|
13910 |
|
13911 |
|
13912 |
|
13913 |
|
13914 | Emitter.prototype.once = function (event, fn) {
|
13915 | function on() {
|
13916 | this.off(event, on);
|
13917 | fn.apply(this, arguments);
|
13918 | }
|
13919 |
|
13920 | on.fn = fn;
|
13921 | this.on(event, on);
|
13922 | return this;
|
13923 | };
|
13924 | |
13925 |
|
13926 |
|
13927 |
|
13928 |
|
13929 |
|
13930 |
|
13931 |
|
13932 |
|
13933 |
|
13934 |
|
13935 | Emitter.prototype.off = Emitter.prototype.removeListener = Emitter.prototype.removeAllListeners = Emitter.prototype.removeEventListener = function (event, fn) {
|
13936 | this._callbacks = this._callbacks || {};
|
13937 |
|
13938 | if (0 == arguments.length) {
|
13939 | this._callbacks = {};
|
13940 | return this;
|
13941 | }
|
13942 |
|
13943 |
|
13944 | var callbacks = this._callbacks['$' + event];
|
13945 | if (!callbacks) return this;
|
13946 |
|
13947 | if (1 == arguments.length) {
|
13948 | delete this._callbacks['$' + event];
|
13949 | return this;
|
13950 | }
|
13951 |
|
13952 |
|
13953 | var cb;
|
13954 |
|
13955 | for (var i = 0; i < callbacks.length; i++) {
|
13956 | cb = callbacks[i];
|
13957 |
|
13958 | if (cb === fn || cb.fn === fn) {
|
13959 | callbacks.splice(i, 1);
|
13960 | break;
|
13961 | }
|
13962 | }
|
13963 |
|
13964 |
|
13965 |
|
13966 | if (callbacks.length === 0) {
|
13967 | delete this._callbacks['$' + event];
|
13968 | }
|
13969 |
|
13970 | return this;
|
13971 | };
|
13972 | |
13973 |
|
13974 |
|
13975 |
|
13976 |
|
13977 |
|
13978 |
|
13979 |
|
13980 |
|
13981 | Emitter.prototype.emit = function (event) {
|
13982 | this._callbacks = this._callbacks || {};
|
13983 | var args = new Array(arguments.length - 1),
|
13984 | callbacks = this._callbacks['$' + event];
|
13985 |
|
13986 | for (var i = 1; i < arguments.length; i++) {
|
13987 | args[i - 1] = arguments[i];
|
13988 | }
|
13989 |
|
13990 | if (callbacks) {
|
13991 | callbacks = callbacks.slice(0);
|
13992 |
|
13993 | for (var i = 0, len = callbacks.length; i < len; ++i) {
|
13994 | callbacks[i].apply(this, args);
|
13995 | }
|
13996 | }
|
13997 |
|
13998 | return this;
|
13999 | };
|
14000 | |
14001 |
|
14002 |
|
14003 |
|
14004 |
|
14005 |
|
14006 |
|
14007 |
|
14008 |
|
14009 | Emitter.prototype.listeners = function (event) {
|
14010 | this._callbacks = this._callbacks || {};
|
14011 | return this._callbacks['$' + event] || [];
|
14012 | };
|
14013 | |
14014 |
|
14015 |
|
14016 |
|
14017 |
|
14018 |
|
14019 |
|
14020 |
|
14021 |
|
14022 | Emitter.prototype.hasListeners = function (event) {
|
14023 | return !!this.listeners(event).length;
|
14024 | };
|
14025 | });
|
14026 |
|
14027 | var fastSafeStringify = stringify;
|
14028 | stringify.default = stringify;
|
14029 | stringify.stable = deterministicStringify;
|
14030 | stringify.stableStringify = deterministicStringify;
|
14031 |
|
14032 | var arr = [];
|
14033 | var replacerStack = [];
|
14034 |
|
14035 |
|
14036 | function stringify (obj, replacer, spacer) {
|
14037 | decirc(obj, '', [], undefined);
|
14038 | var res;
|
14039 | if (replacerStack.length === 0) {
|
14040 | res = JSON.stringify(obj, replacer, spacer);
|
14041 | } else {
|
14042 | res = JSON.stringify(obj, replaceGetterValues(replacer), spacer);
|
14043 | }
|
14044 | while (arr.length !== 0) {
|
14045 | var part = arr.pop();
|
14046 | if (part.length === 4) {
|
14047 | Object.defineProperty(part[0], part[1], part[3]);
|
14048 | } else {
|
14049 | part[0][part[1]] = part[2];
|
14050 | }
|
14051 | }
|
14052 | return res
|
14053 | }
|
14054 | function decirc (val, k, stack, parent) {
|
14055 | var i;
|
14056 | if (typeof val === 'object' && val !== null) {
|
14057 | for (i = 0; i < stack.length; i++) {
|
14058 | if (stack[i] === val) {
|
14059 | var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k);
|
14060 | if (propertyDescriptor.get !== undefined) {
|
14061 | if (propertyDescriptor.configurable) {
|
14062 | Object.defineProperty(parent, k, { value: '[Circular]' });
|
14063 | arr.push([parent, k, val, propertyDescriptor]);
|
14064 | } else {
|
14065 | replacerStack.push([val, k]);
|
14066 | }
|
14067 | } else {
|
14068 | parent[k] = '[Circular]';
|
14069 | arr.push([parent, k, val]);
|
14070 | }
|
14071 | return
|
14072 | }
|
14073 | }
|
14074 | stack.push(val);
|
14075 |
|
14076 | if (Array.isArray(val)) {
|
14077 | for (i = 0; i < val.length; i++) {
|
14078 | decirc(val[i], i, stack, val);
|
14079 | }
|
14080 | } else {
|
14081 | var keys = Object.keys(val);
|
14082 | for (i = 0; i < keys.length; i++) {
|
14083 | var key = keys[i];
|
14084 | decirc(val[key], key, stack, val);
|
14085 | }
|
14086 | }
|
14087 | stack.pop();
|
14088 | }
|
14089 | }
|
14090 |
|
14091 |
|
14092 | function compareFunction (a, b) {
|
14093 | if (a < b) {
|
14094 | return -1
|
14095 | }
|
14096 | if (a > b) {
|
14097 | return 1
|
14098 | }
|
14099 | return 0
|
14100 | }
|
14101 |
|
14102 | function deterministicStringify (obj, replacer, spacer) {
|
14103 | var tmp = deterministicDecirc(obj, '', [], undefined) || obj;
|
14104 | var res;
|
14105 | if (replacerStack.length === 0) {
|
14106 | res = JSON.stringify(tmp, replacer, spacer);
|
14107 | } else {
|
14108 | res = JSON.stringify(tmp, replaceGetterValues(replacer), spacer);
|
14109 | }
|
14110 | while (arr.length !== 0) {
|
14111 | var part = arr.pop();
|
14112 | if (part.length === 4) {
|
14113 | Object.defineProperty(part[0], part[1], part[3]);
|
14114 | } else {
|
14115 | part[0][part[1]] = part[2];
|
14116 | }
|
14117 | }
|
14118 | return res
|
14119 | }
|
14120 |
|
14121 | function deterministicDecirc (val, k, stack, parent) {
|
14122 | var i;
|
14123 | if (typeof val === 'object' && val !== null) {
|
14124 | for (i = 0; i < stack.length; i++) {
|
14125 | if (stack[i] === val) {
|
14126 | var propertyDescriptor = Object.getOwnPropertyDescriptor(parent, k);
|
14127 | if (propertyDescriptor.get !== undefined) {
|
14128 | if (propertyDescriptor.configurable) {
|
14129 | Object.defineProperty(parent, k, { value: '[Circular]' });
|
14130 | arr.push([parent, k, val, propertyDescriptor]);
|
14131 | } else {
|
14132 | replacerStack.push([val, k]);
|
14133 | }
|
14134 | } else {
|
14135 | parent[k] = '[Circular]';
|
14136 | arr.push([parent, k, val]);
|
14137 | }
|
14138 | return
|
14139 | }
|
14140 | }
|
14141 | if (typeof val.toJSON === 'function') {
|
14142 | return
|
14143 | }
|
14144 | stack.push(val);
|
14145 |
|
14146 | if (Array.isArray(val)) {
|
14147 | for (i = 0; i < val.length; i++) {
|
14148 | deterministicDecirc(val[i], i, stack, val);
|
14149 | }
|
14150 | } else {
|
14151 |
|
14152 | var tmp = {};
|
14153 | var keys = Object.keys(val).sort(compareFunction);
|
14154 | for (i = 0; i < keys.length; i++) {
|
14155 | var key = keys[i];
|
14156 | deterministicDecirc(val[key], key, stack, val);
|
14157 | tmp[key] = val[key];
|
14158 | }
|
14159 | if (parent !== undefined) {
|
14160 | arr.push([parent, k, val]);
|
14161 | parent[k] = tmp;
|
14162 | } else {
|
14163 | return tmp
|
14164 | }
|
14165 | }
|
14166 | stack.pop();
|
14167 | }
|
14168 | }
|
14169 |
|
14170 |
|
14171 |
|
14172 | function replaceGetterValues (replacer) {
|
14173 | replacer = replacer !== undefined ? replacer : function (k, v) { return v };
|
14174 | return function (key, val) {
|
14175 | if (replacerStack.length > 0) {
|
14176 | for (var i = 0; i < replacerStack.length; i++) {
|
14177 | var part = replacerStack[i];
|
14178 | if (part[1] === key && part[0] === val) {
|
14179 | val = '[Circular]';
|
14180 | replacerStack.splice(i, 1);
|
14181 | break
|
14182 | }
|
14183 | }
|
14184 | }
|
14185 | return replacer.call(this, key, val)
|
14186 | }
|
14187 | }
|
14188 |
|
14189 | function _typeof$1(obj) {
|
14190 | if (typeof Symbol === "function" && _typeof(Symbol.iterator) === "symbol") {
|
14191 | _typeof$1 = function _typeof$1(obj) {
|
14192 | return _typeof(obj);
|
14193 | };
|
14194 | } else {
|
14195 | _typeof$1 = function _typeof$1(obj) {
|
14196 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof(obj);
|
14197 | };
|
14198 | }
|
14199 |
|
14200 | return _typeof$1(obj);
|
14201 | }
|
14202 | |
14203 |
|
14204 |
|
14205 |
|
14206 |
|
14207 |
|
14208 |
|
14209 |
|
14210 |
|
14211 | function isObject(obj) {
|
14212 | return obj !== null && _typeof$1(obj) === 'object';
|
14213 | }
|
14214 |
|
14215 | var isObject_1 = isObject;
|
14216 |
|
14217 | function _typeof$2(obj) {
|
14218 | if (typeof Symbol === "function" && _typeof(Symbol.iterator) === "symbol") {
|
14219 | _typeof$2 = function _typeof$1(obj) {
|
14220 | return _typeof(obj);
|
14221 | };
|
14222 | } else {
|
14223 | _typeof$2 = function _typeof$1(obj) {
|
14224 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof(obj);
|
14225 | };
|
14226 | }
|
14227 |
|
14228 | return _typeof$2(obj);
|
14229 | }
|
14230 | |
14231 |
|
14232 |
|
14233 |
|
14234 | |
14235 |
|
14236 |
|
14237 |
|
14238 |
|
14239 | var requestBase = RequestBase;
|
14240 | |
14241 |
|
14242 |
|
14243 |
|
14244 |
|
14245 |
|
14246 | function RequestBase(obj) {
|
14247 | if (obj) return mixin(obj);
|
14248 | }
|
14249 | |
14250 |
|
14251 |
|
14252 |
|
14253 |
|
14254 |
|
14255 |
|
14256 |
|
14257 |
|
14258 | function mixin(obj) {
|
14259 | for (var key in RequestBase.prototype) {
|
14260 | if (Object.prototype.hasOwnProperty.call(RequestBase.prototype, key)) obj[key] = RequestBase.prototype[key];
|
14261 | }
|
14262 |
|
14263 | return obj;
|
14264 | }
|
14265 | |
14266 |
|
14267 |
|
14268 |
|
14269 |
|
14270 |
|
14271 |
|
14272 |
|
14273 | RequestBase.prototype.clearTimeout = function () {
|
14274 | clearTimeout(this._timer);
|
14275 | clearTimeout(this._responseTimeoutTimer);
|
14276 | clearTimeout(this._uploadTimeoutTimer);
|
14277 | delete this._timer;
|
14278 | delete this._responseTimeoutTimer;
|
14279 | delete this._uploadTimeoutTimer;
|
14280 | return this;
|
14281 | };
|
14282 | |
14283 |
|
14284 |
|
14285 |
|
14286 |
|
14287 |
|
14288 |
|
14289 |
|
14290 |
|
14291 |
|
14292 | RequestBase.prototype.parse = function (fn) {
|
14293 | this._parser = fn;
|
14294 | return this;
|
14295 | };
|
14296 | |
14297 |
|
14298 |
|
14299 |
|
14300 |
|
14301 |
|
14302 |
|
14303 |
|
14304 |
|
14305 |
|
14306 |
|
14307 |
|
14308 |
|
14309 |
|
14310 |
|
14311 |
|
14312 |
|
14313 |
|
14314 |
|
14315 | RequestBase.prototype.responseType = function (val) {
|
14316 | this._responseType = val;
|
14317 | return this;
|
14318 | };
|
14319 | |
14320 |
|
14321 |
|
14322 |
|
14323 |
|
14324 |
|
14325 |
|
14326 |
|
14327 |
|
14328 |
|
14329 | RequestBase.prototype.serialize = function (fn) {
|
14330 | this._serializer = fn;
|
14331 | return this;
|
14332 | };
|
14333 | |
14334 |
|
14335 |
|
14336 |
|
14337 |
|
14338 |
|
14339 |
|
14340 |
|
14341 |
|
14342 |
|
14343 |
|
14344 |
|
14345 |
|
14346 |
|
14347 |
|
14348 | RequestBase.prototype.timeout = function (options) {
|
14349 | if (!options || _typeof$2(options) !== 'object') {
|
14350 | this._timeout = options;
|
14351 | this._responseTimeout = 0;
|
14352 | this._uploadTimeout = 0;
|
14353 | return this;
|
14354 | }
|
14355 |
|
14356 | for (var option in options) {
|
14357 | if (Object.prototype.hasOwnProperty.call(options, option)) {
|
14358 | switch (option) {
|
14359 | case 'deadline':
|
14360 | this._timeout = options.deadline;
|
14361 | break;
|
14362 |
|
14363 | case 'response':
|
14364 | this._responseTimeout = options.response;
|
14365 | break;
|
14366 |
|
14367 | case 'upload':
|
14368 | this._uploadTimeout = options.upload;
|
14369 | break;
|
14370 |
|
14371 | default:
|
14372 | console.warn('Unknown timeout option', option);
|
14373 | }
|
14374 | }
|
14375 | }
|
14376 |
|
14377 | return this;
|
14378 | };
|
14379 | |
14380 |
|
14381 |
|
14382 |
|
14383 |
|
14384 |
|
14385 |
|
14386 |
|
14387 |
|
14388 |
|
14389 |
|
14390 |
|
14391 | RequestBase.prototype.retry = function (count, fn) {
|
14392 |
|
14393 | if (arguments.length === 0 || count === true) count = 1;
|
14394 | if (count <= 0) count = 0;
|
14395 | this._maxRetries = count;
|
14396 | this._retries = 0;
|
14397 | this._retryCallback = fn;
|
14398 | return this;
|
14399 | };
|
14400 |
|
14401 | var ERROR_CODES = ['ECONNRESET', 'ETIMEDOUT', 'EADDRINFO', 'ESOCKETTIMEDOUT'];
|
14402 | |
14403 |
|
14404 |
|
14405 |
|
14406 |
|
14407 |
|
14408 |
|
14409 |
|
14410 |
|
14411 | RequestBase.prototype._shouldRetry = function (err, res) {
|
14412 | if (!this._maxRetries || this._retries++ >= this._maxRetries) {
|
14413 | return false;
|
14414 | }
|
14415 |
|
14416 | if (this._retryCallback) {
|
14417 | try {
|
14418 | var override = this._retryCallback(err, res);
|
14419 |
|
14420 | if (override === true) return true;
|
14421 | if (override === false) return false;
|
14422 | } catch (err2) {
|
14423 | console.error(err2);
|
14424 | }
|
14425 | }
|
14426 |
|
14427 | if (res && res.status && res.status >= 500 && res.status !== 501) return true;
|
14428 |
|
14429 | if (err) {
|
14430 | if (err.code && ERROR_CODES.indexOf(err.code) !== -1) return true;
|
14431 |
|
14432 | if (err.timeout && err.code === 'ECONNABORTED') return true;
|
14433 | if (err.crossDomain) return true;
|
14434 | }
|
14435 |
|
14436 | return false;
|
14437 | };
|
14438 | |
14439 |
|
14440 |
|
14441 |
|
14442 |
|
14443 |
|
14444 |
|
14445 |
|
14446 | RequestBase.prototype._retry = function () {
|
14447 | this.clearTimeout();
|
14448 |
|
14449 | if (this.req) {
|
14450 | this.req = null;
|
14451 | this.req = this.request();
|
14452 | }
|
14453 |
|
14454 | this._aborted = false;
|
14455 | this.timedout = false;
|
14456 | return this._end();
|
14457 | };
|
14458 | |
14459 |
|
14460 |
|
14461 |
|
14462 |
|
14463 |
|
14464 |
|
14465 |
|
14466 |
|
14467 | RequestBase.prototype.then = function (resolve, reject) {
|
14468 | var _this = this;
|
14469 |
|
14470 | if (!this._fullfilledPromise) {
|
14471 | var self = this;
|
14472 |
|
14473 | if (this._endCalled) {
|
14474 | console.warn('Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises');
|
14475 | }
|
14476 |
|
14477 | this._fullfilledPromise = new Promise(function (resolve, reject) {
|
14478 | self.on('abort', function () {
|
14479 | var err = new Error('Aborted');
|
14480 | err.code = 'ABORTED';
|
14481 | err.status = _this.status;
|
14482 | err.method = _this.method;
|
14483 | err.url = _this.url;
|
14484 | reject(err);
|
14485 | });
|
14486 | self.end(function (err, res) {
|
14487 | if (err) reject(err);else resolve(res);
|
14488 | });
|
14489 | });
|
14490 | }
|
14491 |
|
14492 | return this._fullfilledPromise.then(resolve, reject);
|
14493 | };
|
14494 |
|
14495 | RequestBase.prototype.catch = function (cb) {
|
14496 | return this.then(undefined, cb);
|
14497 | };
|
14498 | |
14499 |
|
14500 |
|
14501 |
|
14502 |
|
14503 | RequestBase.prototype.use = function (fn) {
|
14504 | fn(this);
|
14505 | return this;
|
14506 | };
|
14507 |
|
14508 | RequestBase.prototype.ok = function (cb) {
|
14509 | if (typeof cb !== 'function') throw new Error('Callback required');
|
14510 | this._okCallback = cb;
|
14511 | return this;
|
14512 | };
|
14513 |
|
14514 | RequestBase.prototype._isResponseOK = function (res) {
|
14515 | if (!res) {
|
14516 | return false;
|
14517 | }
|
14518 |
|
14519 | if (this._okCallback) {
|
14520 | return this._okCallback(res);
|
14521 | }
|
14522 |
|
14523 | return res.status >= 200 && res.status < 300;
|
14524 | };
|
14525 | |
14526 |
|
14527 |
|
14528 |
|
14529 |
|
14530 |
|
14531 |
|
14532 |
|
14533 |
|
14534 |
|
14535 | RequestBase.prototype.get = function (field) {
|
14536 | return this._header[field.toLowerCase()];
|
14537 | };
|
14538 | |
14539 |
|
14540 |
|
14541 |
|
14542 |
|
14543 |
|
14544 |
|
14545 |
|
14546 |
|
14547 |
|
14548 |
|
14549 |
|
14550 |
|
14551 | RequestBase.prototype.getHeader = RequestBase.prototype.get;
|
14552 | |
14553 |
|
14554 |
|
14555 |
|
14556 |
|
14557 |
|
14558 |
|
14559 |
|
14560 |
|
14561 |
|
14562 |
|
14563 |
|
14564 |
|
14565 |
|
14566 |
|
14567 |
|
14568 |
|
14569 |
|
14570 |
|
14571 |
|
14572 |
|
14573 | RequestBase.prototype.set = function (field, val) {
|
14574 | if (isObject_1(field)) {
|
14575 | for (var key in field) {
|
14576 | if (Object.prototype.hasOwnProperty.call(field, key)) this.set(key, field[key]);
|
14577 | }
|
14578 |
|
14579 | return this;
|
14580 | }
|
14581 |
|
14582 | this._header[field.toLowerCase()] = val;
|
14583 | this.header[field] = val;
|
14584 | return this;
|
14585 | };
|
14586 |
|
14587 | |
14588 |
|
14589 |
|
14590 |
|
14591 |
|
14592 |
|
14593 |
|
14594 |
|
14595 |
|
14596 |
|
14597 |
|
14598 |
|
14599 |
|
14600 |
|
14601 | RequestBase.prototype.unset = function (field) {
|
14602 | delete this._header[field.toLowerCase()];
|
14603 | delete this.header[field];
|
14604 | return this;
|
14605 | };
|
14606 | |
14607 |
|
14608 |
|
14609 |
|
14610 |
|
14611 |
|
14612 |
|
14613 |
|
14614 |
|
14615 |
|
14616 |
|
14617 |
|
14618 |
|
14619 |
|
14620 |
|
14621 |
|
14622 |
|
14623 |
|
14624 |
|
14625 |
|
14626 |
|
14627 | RequestBase.prototype.field = function (name, val) {
|
14628 |
|
14629 | if (name === null || undefined === name) {
|
14630 | throw new Error('.field(name, val) name can not be empty');
|
14631 | }
|
14632 |
|
14633 | if (this._data) {
|
14634 | throw new Error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()");
|
14635 | }
|
14636 |
|
14637 | if (isObject_1(name)) {
|
14638 | for (var key in name) {
|
14639 | if (Object.prototype.hasOwnProperty.call(name, key)) this.field(key, name[key]);
|
14640 | }
|
14641 |
|
14642 | return this;
|
14643 | }
|
14644 |
|
14645 | if (Array.isArray(val)) {
|
14646 | for (var i in val) {
|
14647 | if (Object.prototype.hasOwnProperty.call(val, i)) this.field(name, val[i]);
|
14648 | }
|
14649 |
|
14650 | return this;
|
14651 | }
|
14652 |
|
14653 |
|
14654 | if (val === null || undefined === val) {
|
14655 | throw new Error('.field(name, val) val can not be empty');
|
14656 | }
|
14657 |
|
14658 | if (typeof val === 'boolean') {
|
14659 | val = String(val);
|
14660 | }
|
14661 |
|
14662 | this._getFormData().append(name, val);
|
14663 |
|
14664 | return this;
|
14665 | };
|
14666 | |
14667 |
|
14668 |
|
14669 |
|
14670 |
|
14671 |
|
14672 |
|
14673 |
|
14674 | RequestBase.prototype.abort = function () {
|
14675 | if (this._aborted) {
|
14676 | return this;
|
14677 | }
|
14678 |
|
14679 | this._aborted = true;
|
14680 | if (this.xhr) this.xhr.abort();
|
14681 |
|
14682 | if (this.req) this.req.abort();
|
14683 |
|
14684 | this.clearTimeout();
|
14685 | this.emit('abort');
|
14686 | return this;
|
14687 | };
|
14688 |
|
14689 | RequestBase.prototype._auth = function (user, pass, options, base64Encoder) {
|
14690 | switch (options.type) {
|
14691 | case 'basic':
|
14692 | this.set('Authorization', "Basic ".concat(base64Encoder("".concat(user, ":").concat(pass))));
|
14693 | break;
|
14694 |
|
14695 | case 'auto':
|
14696 | this.username = user;
|
14697 | this.password = pass;
|
14698 | break;
|
14699 |
|
14700 | case 'bearer':
|
14701 |
|
14702 | this.set('Authorization', "Bearer ".concat(user));
|
14703 | break;
|
14704 |
|
14705 | default:
|
14706 | break;
|
14707 | }
|
14708 |
|
14709 | return this;
|
14710 | };
|
14711 | |
14712 |
|
14713 |
|
14714 |
|
14715 |
|
14716 |
|
14717 |
|
14718 |
|
14719 |
|
14720 |
|
14721 |
|
14722 |
|
14723 | RequestBase.prototype.withCredentials = function (on) {
|
14724 |
|
14725 | if (on === undefined) on = true;
|
14726 | this._withCredentials = on;
|
14727 | return this;
|
14728 | };
|
14729 | |
14730 |
|
14731 |
|
14732 |
|
14733 |
|
14734 |
|
14735 |
|
14736 |
|
14737 |
|
14738 | RequestBase.prototype.redirects = function (n) {
|
14739 | this._maxRedirects = n;
|
14740 | return this;
|
14741 | };
|
14742 | |
14743 |
|
14744 |
|
14745 |
|
14746 |
|
14747 |
|
14748 |
|
14749 |
|
14750 |
|
14751 | RequestBase.prototype.maxResponseSize = function (n) {
|
14752 | if (typeof n !== 'number') {
|
14753 | throw new TypeError('Invalid argument');
|
14754 | }
|
14755 |
|
14756 | this._maxResponseSize = n;
|
14757 | return this;
|
14758 | };
|
14759 | |
14760 |
|
14761 |
|
14762 |
|
14763 |
|
14764 |
|
14765 |
|
14766 |
|
14767 |
|
14768 |
|
14769 | RequestBase.prototype.toJSON = function () {
|
14770 | return {
|
14771 | method: this.method,
|
14772 | url: this.url,
|
14773 | data: this._data,
|
14774 | headers: this._header
|
14775 | };
|
14776 | };
|
14777 | |
14778 |
|
14779 |
|
14780 |
|
14781 |
|
14782 |
|
14783 |
|
14784 |
|
14785 |
|
14786 |
|
14787 |
|
14788 |
|
14789 |
|
14790 |
|
14791 |
|
14792 |
|
14793 |
|
14794 |
|
14795 |
|
14796 |
|
14797 |
|
14798 |
|
14799 |
|
14800 |
|
14801 |
|
14802 |
|
14803 |
|
14804 |
|
14805 |
|
14806 |
|
14807 |
|
14808 |
|
14809 |
|
14810 |
|
14811 |
|
14812 |
|
14813 |
|
14814 |
|
14815 |
|
14816 |
|
14817 |
|
14818 |
|
14819 | RequestBase.prototype.send = function (data) {
|
14820 | var isObj = isObject_1(data);
|
14821 | var type = this._header['content-type'];
|
14822 |
|
14823 | if (this._formData) {
|
14824 | throw new Error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()");
|
14825 | }
|
14826 |
|
14827 | if (isObj && !this._data) {
|
14828 | if (Array.isArray(data)) {
|
14829 | this._data = [];
|
14830 | } else if (!this._isHost(data)) {
|
14831 | this._data = {};
|
14832 | }
|
14833 | } else if (data && this._data && this._isHost(this._data)) {
|
14834 | throw new Error("Can't merge these send calls");
|
14835 | }
|
14836 |
|
14837 |
|
14838 | if (isObj && isObject_1(this._data)) {
|
14839 | for (var key in data) {
|
14840 | if (Object.prototype.hasOwnProperty.call(data, key)) this._data[key] = data[key];
|
14841 | }
|
14842 | } else if (typeof data === 'string') {
|
14843 |
|
14844 | if (!type) this.type('form');
|
14845 | type = this._header['content-type'];
|
14846 |
|
14847 | if (type === 'application/x-www-form-urlencoded') {
|
14848 | this._data = this._data ? "".concat(this._data, "&").concat(data) : data;
|
14849 | } else {
|
14850 | this._data = (this._data || '') + data;
|
14851 | }
|
14852 | } else {
|
14853 | this._data = data;
|
14854 | }
|
14855 |
|
14856 | if (!isObj || this._isHost(data)) {
|
14857 | return this;
|
14858 | }
|
14859 |
|
14860 |
|
14861 | if (!type) this.type('json');
|
14862 | return this;
|
14863 | };
|
14864 | |
14865 |
|
14866 |
|
14867 |
|
14868 |
|
14869 |
|
14870 |
|
14871 |
|
14872 |
|
14873 |
|
14874 |
|
14875 |
|
14876 |
|
14877 |
|
14878 |
|
14879 |
|
14880 |
|
14881 |
|
14882 |
|
14883 |
|
14884 |
|
14885 |
|
14886 |
|
14887 |
|
14888 |
|
14889 |
|
14890 |
|
14891 |
|
14892 |
|
14893 | RequestBase.prototype.sortQuery = function (sort) {
|
14894 |
|
14895 | this._sort = typeof sort === 'undefined' ? true : sort;
|
14896 | return this;
|
14897 | };
|
14898 | |
14899 |
|
14900 |
|
14901 |
|
14902 |
|
14903 |
|
14904 |
|
14905 | RequestBase.prototype._finalizeQueryString = function () {
|
14906 | var query = this._query.join('&');
|
14907 |
|
14908 | if (query) {
|
14909 | this.url += (this.url.indexOf('?') >= 0 ? '&' : '?') + query;
|
14910 | }
|
14911 |
|
14912 | this._query.length = 0;
|
14913 |
|
14914 | if (this._sort) {
|
14915 | var index = this.url.indexOf('?');
|
14916 |
|
14917 | if (index >= 0) {
|
14918 | var queryArr = this.url.substring(index + 1).split('&');
|
14919 |
|
14920 | if (typeof this._sort === 'function') {
|
14921 | queryArr.sort(this._sort);
|
14922 | } else {
|
14923 | queryArr.sort();
|
14924 | }
|
14925 |
|
14926 | this.url = this.url.substring(0, index) + '?' + queryArr.join('&');
|
14927 | }
|
14928 | }
|
14929 | };
|
14930 |
|
14931 |
|
14932 | RequestBase.prototype._appendQueryString = function () {
|
14933 | console.warn('Unsupported');
|
14934 | };
|
14935 | |
14936 |
|
14937 |
|
14938 |
|
14939 |
|
14940 |
|
14941 |
|
14942 | RequestBase.prototype._timeoutError = function (reason, timeout, errno) {
|
14943 | if (this._aborted) {
|
14944 | return;
|
14945 | }
|
14946 |
|
14947 | var err = new Error("".concat(reason + timeout, "ms exceeded"));
|
14948 | err.timeout = timeout;
|
14949 | err.code = 'ECONNABORTED';
|
14950 | err.errno = errno;
|
14951 | this.timedout = true;
|
14952 | this.abort();
|
14953 | this.callback(err);
|
14954 | };
|
14955 |
|
14956 | RequestBase.prototype._setTimeouts = function () {
|
14957 | var self = this;
|
14958 |
|
14959 | if (this._timeout && !this._timer) {
|
14960 | this._timer = setTimeout(function () {
|
14961 | self._timeoutError('Timeout of ', self._timeout, 'ETIME');
|
14962 | }, this._timeout);
|
14963 | }
|
14964 |
|
14965 |
|
14966 | if (this._responseTimeout && !this._responseTimeoutTimer) {
|
14967 | this._responseTimeoutTimer = setTimeout(function () {
|
14968 | self._timeoutError('Response timeout of ', self._responseTimeout, 'ETIMEDOUT');
|
14969 | }, this._responseTimeout);
|
14970 | }
|
14971 | };
|
14972 |
|
14973 | |
14974 |
|
14975 |
|
14976 |
|
14977 |
|
14978 |
|
14979 |
|
14980 |
|
14981 | var type = function type(str) {
|
14982 | return str.split(/ *; */).shift();
|
14983 | };
|
14984 | |
14985 |
|
14986 |
|
14987 |
|
14988 |
|
14989 |
|
14990 |
|
14991 |
|
14992 |
|
14993 | var params = function params(str) {
|
14994 | return str.split(/ *; */).reduce(function (obj, str) {
|
14995 | var parts = str.split(/ *= */);
|
14996 | var key = parts.shift();
|
14997 | var val = parts.shift();
|
14998 | if (key && val) obj[key] = val;
|
14999 | return obj;
|
15000 | }, {});
|
15001 | };
|
15002 | |
15003 |
|
15004 |
|
15005 |
|
15006 |
|
15007 |
|
15008 |
|
15009 |
|
15010 |
|
15011 | var parseLinks = function parseLinks(str) {
|
15012 | return str.split(/ *, */).reduce(function (obj, str) {
|
15013 | var parts = str.split(/ *; */);
|
15014 | var url = parts[0].slice(1, -1);
|
15015 | var rel = parts[1].split(/ *= */)[1].slice(1, -1);
|
15016 | obj[rel] = url;
|
15017 | return obj;
|
15018 | }, {});
|
15019 | };
|
15020 | |
15021 |
|
15022 |
|
15023 |
|
15024 |
|
15025 |
|
15026 |
|
15027 |
|
15028 |
|
15029 | var cleanHeader = function cleanHeader(header, changesOrigin) {
|
15030 | delete header['content-type'];
|
15031 | delete header['content-length'];
|
15032 | delete header['transfer-encoding'];
|
15033 | delete header.host;
|
15034 |
|
15035 | if (changesOrigin) {
|
15036 | delete header.authorization;
|
15037 | delete header.cookie;
|
15038 | }
|
15039 |
|
15040 | return header;
|
15041 | };
|
15042 |
|
15043 | var utils = {
|
15044 | type: type,
|
15045 | params: params,
|
15046 | parseLinks: parseLinks,
|
15047 | cleanHeader: cleanHeader
|
15048 | };
|
15049 |
|
15050 | |
15051 |
|
15052 |
|
15053 |
|
15054 | |
15055 |
|
15056 |
|
15057 |
|
15058 |
|
15059 | var responseBase = ResponseBase;
|
15060 | |
15061 |
|
15062 |
|
15063 |
|
15064 |
|
15065 |
|
15066 | function ResponseBase(obj) {
|
15067 | if (obj) return mixin$1(obj);
|
15068 | }
|
15069 | |
15070 |
|
15071 |
|
15072 |
|
15073 |
|
15074 |
|
15075 |
|
15076 |
|
15077 |
|
15078 | function mixin$1(obj) {
|
15079 | for (var key in ResponseBase.prototype) {
|
15080 | if (Object.prototype.hasOwnProperty.call(ResponseBase.prototype, key)) obj[key] = ResponseBase.prototype[key];
|
15081 | }
|
15082 |
|
15083 | return obj;
|
15084 | }
|
15085 | |
15086 |
|
15087 |
|
15088 |
|
15089 |
|
15090 |
|
15091 |
|
15092 |
|
15093 |
|
15094 | ResponseBase.prototype.get = function (field) {
|
15095 | return this.header[field.toLowerCase()];
|
15096 | };
|
15097 | |
15098 |
|
15099 |
|
15100 |
|
15101 |
|
15102 |
|
15103 |
|
15104 |
|
15105 |
|
15106 |
|
15107 |
|
15108 |
|
15109 |
|
15110 | ResponseBase.prototype._setHeaderProperties = function (header) {
|
15111 |
|
15112 |
|
15113 |
|
15114 | var ct = header['content-type'] || '';
|
15115 | this.type = utils.type(ct);
|
15116 |
|
15117 | var params = utils.params(ct);
|
15118 |
|
15119 | for (var key in params) {
|
15120 | if (Object.prototype.hasOwnProperty.call(params, key)) this[key] = params[key];
|
15121 | }
|
15122 |
|
15123 | this.links = {};
|
15124 |
|
15125 | try {
|
15126 | if (header.link) {
|
15127 | this.links = utils.parseLinks(header.link);
|
15128 | }
|
15129 | } catch (err) {
|
15130 | }
|
15131 | };
|
15132 | |
15133 |
|
15134 |
|
15135 |
|
15136 |
|
15137 |
|
15138 |
|
15139 |
|
15140 |
|
15141 |
|
15142 |
|
15143 |
|
15144 |
|
15145 |
|
15146 |
|
15147 |
|
15148 |
|
15149 |
|
15150 |
|
15151 |
|
15152 |
|
15153 |
|
15154 | ResponseBase.prototype._setStatusProperties = function (status) {
|
15155 | var type = status / 100 | 0;
|
15156 |
|
15157 | this.statusCode = status;
|
15158 | this.status = this.statusCode;
|
15159 | this.statusType = type;
|
15160 |
|
15161 | this.info = type === 1;
|
15162 | this.ok = type === 2;
|
15163 | this.redirect = type === 3;
|
15164 | this.clientError = type === 4;
|
15165 | this.serverError = type === 5;
|
15166 | this.error = type === 4 || type === 5 ? this.toError() : false;
|
15167 |
|
15168 | this.created = status === 201;
|
15169 | this.accepted = status === 202;
|
15170 | this.noContent = status === 204;
|
15171 | this.badRequest = status === 400;
|
15172 | this.unauthorized = status === 401;
|
15173 | this.notAcceptable = status === 406;
|
15174 | this.forbidden = status === 403;
|
15175 | this.notFound = status === 404;
|
15176 | this.unprocessableEntity = status === 422;
|
15177 | };
|
15178 |
|
15179 | function _toConsumableArray$1(arr) {
|
15180 | return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _nonIterableSpread$1();
|
15181 | }
|
15182 |
|
15183 | function _nonIterableSpread$1() {
|
15184 | throw new TypeError("Invalid attempt to spread non-iterable instance");
|
15185 | }
|
15186 |
|
15187 | function _iterableToArray$1(iter) {
|
15188 | if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
|
15189 | }
|
15190 |
|
15191 | function _arrayWithoutHoles$1(arr) {
|
15192 | if (Array.isArray(arr)) {
|
15193 | for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
|
15194 | arr2[i] = arr[i];
|
15195 | }
|
15196 |
|
15197 | return arr2;
|
15198 | }
|
15199 | }
|
15200 |
|
15201 | function Agent() {
|
15202 | this._defaults = [];
|
15203 | }
|
15204 |
|
15205 | ['use', 'on', 'once', 'set', 'query', 'type', 'accept', 'auth', 'withCredentials', 'sortQuery', 'retry', 'ok', 'redirects', 'timeout', 'buffer', 'serialize', 'parse', 'ca', 'key', 'pfx', 'cert'].forEach(function (fn) {
|
15206 |
|
15207 | Agent.prototype[fn] = function () {
|
15208 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
15209 | args[_key] = arguments[_key];
|
15210 | }
|
15211 |
|
15212 | this._defaults.push({
|
15213 | fn: fn,
|
15214 | args: args
|
15215 | });
|
15216 |
|
15217 | return this;
|
15218 | };
|
15219 | });
|
15220 |
|
15221 | Agent.prototype._setDefaults = function (req) {
|
15222 | this._defaults.forEach(function (def) {
|
15223 | req[def.fn].apply(req, _toConsumableArray$1(def.args));
|
15224 | });
|
15225 | };
|
15226 |
|
15227 | var agentBase = Agent;
|
15228 |
|
15229 | var client = createCommonjsModule(function (module, exports) {
|
15230 |
|
15231 | function _typeof$1(obj) {
|
15232 | if (typeof Symbol === "function" && _typeof(Symbol.iterator) === "symbol") {
|
15233 | _typeof$1 = function _typeof$1(obj) {
|
15234 | return _typeof(obj);
|
15235 | };
|
15236 | } else {
|
15237 | _typeof$1 = function _typeof$1(obj) {
|
15238 | return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof(obj);
|
15239 | };
|
15240 | }
|
15241 |
|
15242 | return _typeof$1(obj);
|
15243 | }
|
15244 | |
15245 |
|
15246 |
|
15247 |
|
15248 |
|
15249 | var root;
|
15250 |
|
15251 | if (typeof window !== 'undefined') {
|
15252 |
|
15253 | root = window;
|
15254 | } else if (typeof self === 'undefined') {
|
15255 |
|
15256 | console.warn('Using browser-only version of superagent in non-browser environment');
|
15257 | root = void 0;
|
15258 | } else {
|
15259 |
|
15260 | root = self;
|
15261 | }
|
15262 | |
15263 |
|
15264 |
|
15265 |
|
15266 |
|
15267 | function noop() {}
|
15268 | |
15269 |
|
15270 |
|
15271 |
|
15272 |
|
15273 | module.exports = function (method, url) {
|
15274 |
|
15275 | if (typeof url === 'function') {
|
15276 | return new exports.Request('GET', method).end(url);
|
15277 | }
|
15278 |
|
15279 |
|
15280 | if (arguments.length === 1) {
|
15281 | return new exports.Request('GET', method);
|
15282 | }
|
15283 |
|
15284 | return new exports.Request(method, url);
|
15285 | };
|
15286 |
|
15287 | exports = module.exports;
|
15288 | var request = exports;
|
15289 | exports.Request = Request;
|
15290 | |
15291 |
|
15292 |
|
15293 |
|
15294 | request.getXHR = function () {
|
15295 | if (root.XMLHttpRequest && (!root.location || root.location.protocol !== 'file:' || !root.ActiveXObject)) {
|
15296 | return new XMLHttpRequest();
|
15297 | }
|
15298 |
|
15299 | try {
|
15300 | return new ActiveXObject('Microsoft.XMLHTTP');
|
15301 | } catch (err) {}
|
15302 |
|
15303 | try {
|
15304 | return new ActiveXObject('Msxml2.XMLHTTP.6.0');
|
15305 | } catch (err) {}
|
15306 |
|
15307 | try {
|
15308 | return new ActiveXObject('Msxml2.XMLHTTP.3.0');
|
15309 | } catch (err) {}
|
15310 |
|
15311 | try {
|
15312 | return new ActiveXObject('Msxml2.XMLHTTP');
|
15313 | } catch (err) {}
|
15314 |
|
15315 | throw new Error('Browser-only version of superagent could not find XHR');
|
15316 | };
|
15317 | |
15318 |
|
15319 |
|
15320 |
|
15321 |
|
15322 |
|
15323 |
|
15324 |
|
15325 |
|
15326 | var trim = ''.trim ? function (s) {
|
15327 | return s.trim();
|
15328 | } : function (s) {
|
15329 | return s.replace(/(^\s*|\s*$)/g, '');
|
15330 | };
|
15331 | |
15332 |
|
15333 |
|
15334 |
|
15335 |
|
15336 |
|
15337 |
|
15338 |
|
15339 | function serialize(obj) {
|
15340 | if (!isObject_1(obj)) return obj;
|
15341 | var pairs = [];
|
15342 |
|
15343 | for (var key in obj) {
|
15344 | if (Object.prototype.hasOwnProperty.call(obj, key)) pushEncodedKeyValuePair(pairs, key, obj[key]);
|
15345 | }
|
15346 |
|
15347 | return pairs.join('&');
|
15348 | }
|
15349 | |
15350 |
|
15351 |
|
15352 |
|
15353 |
|
15354 |
|
15355 |
|
15356 |
|
15357 |
|
15358 |
|
15359 | function pushEncodedKeyValuePair(pairs, key, val) {
|
15360 | if (val === undefined) return;
|
15361 |
|
15362 | if (val === null) {
|
15363 | pairs.push(encodeURIComponent(key));
|
15364 | return;
|
15365 | }
|
15366 |
|
15367 | if (Array.isArray(val)) {
|
15368 | val.forEach(function (v) {
|
15369 | pushEncodedKeyValuePair(pairs, key, v);
|
15370 | });
|
15371 | } else if (isObject_1(val)) {
|
15372 | for (var subkey in val) {
|
15373 | if (Object.prototype.hasOwnProperty.call(val, subkey)) pushEncodedKeyValuePair(pairs, "".concat(key, "[").concat(subkey, "]"), val[subkey]);
|
15374 | }
|
15375 | } else {
|
15376 | pairs.push(encodeURIComponent(key) + '=' + encodeURIComponent(val));
|
15377 | }
|
15378 | }
|
15379 | |
15380 |
|
15381 |
|
15382 |
|
15383 |
|
15384 | request.serializeObject = serialize;
|
15385 | |
15386 |
|
15387 |
|
15388 |
|
15389 |
|
15390 |
|
15391 |
|
15392 |
|
15393 | function parseString(str) {
|
15394 | var obj = {};
|
15395 | var pairs = str.split('&');
|
15396 | var pair;
|
15397 | var pos;
|
15398 |
|
15399 | for (var i = 0, len = pairs.length; i < len; ++i) {
|
15400 | pair = pairs[i];
|
15401 | pos = pair.indexOf('=');
|
15402 |
|
15403 | if (pos === -1) {
|
15404 | obj[decodeURIComponent(pair)] = '';
|
15405 | } else {
|
15406 | obj[decodeURIComponent(pair.slice(0, pos))] = decodeURIComponent(pair.slice(pos + 1));
|
15407 | }
|
15408 | }
|
15409 |
|
15410 | return obj;
|
15411 | }
|
15412 | |
15413 |
|
15414 |
|
15415 |
|
15416 |
|
15417 | request.parseString = parseString;
|
15418 | |
15419 |
|
15420 |
|
15421 |
|
15422 |
|
15423 |
|
15424 |
|
15425 | request.types = {
|
15426 | html: 'text/html',
|
15427 | json: 'application/json',
|
15428 | xml: 'text/xml',
|
15429 | urlencoded: 'application/x-www-form-urlencoded',
|
15430 | form: 'application/x-www-form-urlencoded',
|
15431 | 'form-data': 'application/x-www-form-urlencoded'
|
15432 | };
|
15433 | |
15434 |
|
15435 |
|
15436 |
|
15437 |
|
15438 |
|
15439 |
|
15440 |
|
15441 |
|
15442 | request.serialize = {
|
15443 | 'application/x-www-form-urlencoded': serialize,
|
15444 | 'application/json': fastSafeStringify
|
15445 | };
|
15446 | |
15447 |
|
15448 |
|
15449 |
|
15450 |
|
15451 |
|
15452 |
|
15453 |
|
15454 |
|
15455 | request.parse = {
|
15456 | 'application/x-www-form-urlencoded': parseString,
|
15457 | 'application/json': JSON.parse
|
15458 | };
|
15459 | |
15460 |
|
15461 |
|
15462 |
|
15463 |
|
15464 |
|
15465 |
|
15466 |
|
15467 |
|
15468 | function parseHeader(str) {
|
15469 | var lines = str.split(/\r?\n/);
|
15470 | var fields = {};
|
15471 | var index;
|
15472 | var line;
|
15473 | var field;
|
15474 | var val;
|
15475 |
|
15476 | for (var i = 0, len = lines.length; i < len; ++i) {
|
15477 | line = lines[i];
|
15478 | index = line.indexOf(':');
|
15479 |
|
15480 | if (index === -1) {
|
15481 |
|
15482 | continue;
|
15483 | }
|
15484 |
|
15485 | field = line.slice(0, index).toLowerCase();
|
15486 | val = trim(line.slice(index + 1));
|
15487 | fields[field] = val;
|
15488 | }
|
15489 |
|
15490 | return fields;
|
15491 | }
|
15492 | |
15493 |
|
15494 |
|
15495 |
|
15496 |
|
15497 |
|
15498 |
|
15499 |
|
15500 |
|
15501 | function isJSON(mime) {
|
15502 |
|
15503 |
|
15504 | return /[/+]json($|[^-\w])/.test(mime);
|
15505 | }
|
15506 | |
15507 |
|
15508 |
|
15509 |
|
15510 |
|
15511 |
|
15512 |
|
15513 |
|
15514 |
|
15515 |
|
15516 |
|
15517 |
|
15518 |
|
15519 |
|
15520 |
|
15521 |
|
15522 |
|
15523 |
|
15524 |
|
15525 |
|
15526 |
|
15527 |
|
15528 |
|
15529 |
|
15530 |
|
15531 |
|
15532 |
|
15533 |
|
15534 |
|
15535 |
|
15536 |
|
15537 |
|
15538 |
|
15539 |
|
15540 |
|
15541 |
|
15542 |
|
15543 |
|
15544 |
|
15545 |
|
15546 |
|
15547 |
|
15548 |
|
15549 |
|
15550 |
|
15551 |
|
15552 |
|
15553 | function Response(req) {
|
15554 | this.req = req;
|
15555 | this.xhr = this.req.xhr;
|
15556 |
|
15557 | this.text = this.req.method !== 'HEAD' && (this.xhr.responseType === '' || this.xhr.responseType === 'text') || typeof this.xhr.responseType === 'undefined' ? this.xhr.responseText : null;
|
15558 | this.statusText = this.req.xhr.statusText;
|
15559 | var status = this.xhr.status;
|
15560 |
|
15561 | if (status === 1223) {
|
15562 | status = 204;
|
15563 | }
|
15564 |
|
15565 | this._setStatusProperties(status);
|
15566 |
|
15567 | this.headers = parseHeader(this.xhr.getAllResponseHeaders());
|
15568 | this.header = this.headers;
|
15569 |
|
15570 |
|
15571 |
|
15572 | this.header['content-type'] = this.xhr.getResponseHeader('content-type');
|
15573 |
|
15574 | this._setHeaderProperties(this.header);
|
15575 |
|
15576 | if (this.text === null && req._responseType) {
|
15577 | this.body = this.xhr.response;
|
15578 | } else {
|
15579 | this.body = this.req.method === 'HEAD' ? null : this._parseBody(this.text ? this.text : this.xhr.response);
|
15580 | }
|
15581 | }
|
15582 |
|
15583 |
|
15584 | responseBase(Response.prototype);
|
15585 | |
15586 |
|
15587 |
|
15588 |
|
15589 |
|
15590 |
|
15591 |
|
15592 |
|
15593 |
|
15594 |
|
15595 |
|
15596 | Response.prototype._parseBody = function (str) {
|
15597 | var parse = request.parse[this.type];
|
15598 |
|
15599 | if (this.req._parser) {
|
15600 | return this.req._parser(this, str);
|
15601 | }
|
15602 |
|
15603 | if (!parse && isJSON(this.type)) {
|
15604 | parse = request.parse['application/json'];
|
15605 | }
|
15606 |
|
15607 | return parse && str && (str.length > 0 || str instanceof Object) ? parse(str) : null;
|
15608 | };
|
15609 | |
15610 |
|
15611 |
|
15612 |
|
15613 |
|
15614 |
|
15615 |
|
15616 |
|
15617 | Response.prototype.toError = function () {
|
15618 | var req = this.req;
|
15619 | var method = req.method;
|
15620 | var url = req.url;
|
15621 | var msg = "cannot ".concat(method, " ").concat(url, " (").concat(this.status, ")");
|
15622 | var err = new Error(msg);
|
15623 | err.status = this.status;
|
15624 | err.method = method;
|
15625 | err.url = url;
|
15626 | return err;
|
15627 | };
|
15628 | |
15629 |
|
15630 |
|
15631 |
|
15632 |
|
15633 | request.Response = Response;
|
15634 | |
15635 |
|
15636 |
|
15637 |
|
15638 |
|
15639 |
|
15640 |
|
15641 |
|
15642 | function Request(method, url) {
|
15643 | var self = this;
|
15644 | this._query = this._query || [];
|
15645 | this.method = method;
|
15646 | this.url = url;
|
15647 | this.header = {};
|
15648 |
|
15649 | this._header = {};
|
15650 |
|
15651 | this.on('end', function () {
|
15652 | var err = null;
|
15653 | var res = null;
|
15654 |
|
15655 | try {
|
15656 | res = new Response(self);
|
15657 | } catch (err2) {
|
15658 | err = new Error('Parser is unable to parse the response');
|
15659 | err.parse = true;
|
15660 | err.original = err2;
|
15661 |
|
15662 | if (self.xhr) {
|
15663 |
|
15664 | err.rawResponse = typeof self.xhr.responseType === 'undefined' ? self.xhr.responseText : self.xhr.response;
|
15665 |
|
15666 | err.status = self.xhr.status ? self.xhr.status : null;
|
15667 | err.statusCode = err.status;
|
15668 | } else {
|
15669 | err.rawResponse = null;
|
15670 | err.status = null;
|
15671 | }
|
15672 |
|
15673 | return self.callback(err);
|
15674 | }
|
15675 |
|
15676 | self.emit('response', res);
|
15677 | var new_err;
|
15678 |
|
15679 | try {
|
15680 | if (!self._isResponseOK(res)) {
|
15681 | new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
|
15682 | }
|
15683 | } catch (err2) {
|
15684 | new_err = err2;
|
15685 | }
|
15686 |
|
15687 |
|
15688 | if (new_err) {
|
15689 | new_err.original = err;
|
15690 | new_err.response = res;
|
15691 | new_err.status = res.status;
|
15692 | self.callback(new_err, res);
|
15693 | } else {
|
15694 | self.callback(null, res);
|
15695 | }
|
15696 | });
|
15697 | }
|
15698 | |
15699 |
|
15700 |
|
15701 |
|
15702 |
|
15703 |
|
15704 | componentEmitter(Request.prototype);
|
15705 |
|
15706 | requestBase(Request.prototype);
|
15707 | |
15708 |
|
15709 |
|
15710 |
|
15711 |
|
15712 |
|
15713 |
|
15714 |
|
15715 |
|
15716 |
|
15717 |
|
15718 |
|
15719 |
|
15720 |
|
15721 |
|
15722 |
|
15723 |
|
15724 |
|
15725 |
|
15726 |
|
15727 |
|
15728 |
|
15729 | Request.prototype.type = function (type) {
|
15730 | this.set('Content-Type', request.types[type] || type);
|
15731 | return this;
|
15732 | };
|
15733 | |
15734 |
|
15735 |
|
15736 |
|
15737 |
|
15738 |
|
15739 |
|
15740 |
|
15741 |
|
15742 |
|
15743 |
|
15744 |
|
15745 |
|
15746 |
|
15747 |
|
15748 |
|
15749 |
|
15750 |
|
15751 |
|
15752 |
|
15753 |
|
15754 | Request.prototype.accept = function (type) {
|
15755 | this.set('Accept', request.types[type] || type);
|
15756 | return this;
|
15757 | };
|
15758 | |
15759 |
|
15760 |
|
15761 |
|
15762 |
|
15763 |
|
15764 |
|
15765 |
|
15766 |
|
15767 |
|
15768 |
|
15769 | Request.prototype.auth = function (user, pass, options) {
|
15770 | if (arguments.length === 1) pass = '';
|
15771 |
|
15772 | if (_typeof$1(pass) === 'object' && pass !== null) {
|
15773 |
|
15774 | options = pass;
|
15775 | pass = '';
|
15776 | }
|
15777 |
|
15778 | if (!options) {
|
15779 | options = {
|
15780 | type: typeof btoa === 'function' ? 'basic' : 'auto'
|
15781 | };
|
15782 | }
|
15783 |
|
15784 | var encoder = function encoder(string) {
|
15785 | if (typeof btoa === 'function') {
|
15786 | return btoa(string);
|
15787 | }
|
15788 |
|
15789 | throw new Error('Cannot use basic auth, btoa is not a function');
|
15790 | };
|
15791 |
|
15792 | return this._auth(user, pass, options, encoder);
|
15793 | };
|
15794 | |
15795 |
|
15796 |
|
15797 |
|
15798 |
|
15799 |
|
15800 |
|
15801 |
|
15802 |
|
15803 |
|
15804 |
|
15805 |
|
15806 |
|
15807 |
|
15808 |
|
15809 | Request.prototype.query = function (val) {
|
15810 | if (typeof val !== 'string') val = serialize(val);
|
15811 | if (val) this._query.push(val);
|
15812 | return this;
|
15813 | };
|
15814 | |
15815 |
|
15816 |
|
15817 |
|
15818 |
|
15819 |
|
15820 |
|
15821 |
|
15822 |
|
15823 |
|
15824 |
|
15825 |
|
15826 |
|
15827 |
|
15828 |
|
15829 |
|
15830 |
|
15831 |
|
15832 | Request.prototype.attach = function (field, file, options) {
|
15833 | if (file) {
|
15834 | if (this._data) {
|
15835 | throw new Error("superagent can't mix .send() and .attach()");
|
15836 | }
|
15837 |
|
15838 | this._getFormData().append(field, file, options || file.name);
|
15839 | }
|
15840 |
|
15841 | return this;
|
15842 | };
|
15843 |
|
15844 | Request.prototype._getFormData = function () {
|
15845 | if (!this._formData) {
|
15846 | this._formData = new root.FormData();
|
15847 | }
|
15848 |
|
15849 | return this._formData;
|
15850 | };
|
15851 | |
15852 |
|
15853 |
|
15854 |
|
15855 |
|
15856 |
|
15857 |
|
15858 |
|
15859 |
|
15860 |
|
15861 | Request.prototype.callback = function (err, res) {
|
15862 | if (this._shouldRetry(err, res)) {
|
15863 | return this._retry();
|
15864 | }
|
15865 |
|
15866 | var fn = this._callback;
|
15867 | this.clearTimeout();
|
15868 |
|
15869 | if (err) {
|
15870 | if (this._maxRetries) err.retries = this._retries - 1;
|
15871 | this.emit('error', err);
|
15872 | }
|
15873 |
|
15874 | fn(err, res);
|
15875 | };
|
15876 | |
15877 |
|
15878 |
|
15879 |
|
15880 |
|
15881 |
|
15882 |
|
15883 | Request.prototype.crossDomainError = function () {
|
15884 | var err = new Error('Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.');
|
15885 | err.crossDomain = true;
|
15886 | err.status = this.status;
|
15887 | err.method = this.method;
|
15888 | err.url = this.url;
|
15889 | this.callback(err);
|
15890 | };
|
15891 |
|
15892 |
|
15893 | Request.prototype.agent = function () {
|
15894 | console.warn('This is not supported in browser version of superagent');
|
15895 | return this;
|
15896 | };
|
15897 |
|
15898 | Request.prototype.buffer = Request.prototype.ca;
|
15899 | Request.prototype.ca = Request.prototype.agent;
|
15900 |
|
15901 | Request.prototype.write = function () {
|
15902 | throw new Error('Streaming is not supported in browser version of superagent');
|
15903 | };
|
15904 |
|
15905 | Request.prototype.pipe = Request.prototype.write;
|
15906 | |
15907 |
|
15908 |
|
15909 |
|
15910 |
|
15911 |
|
15912 |
|
15913 |
|
15914 |
|
15915 | Request.prototype._isHost = function (obj) {
|
15916 |
|
15917 | return obj && _typeof$1(obj) === 'object' && !Array.isArray(obj) && Object.prototype.toString.call(obj) !== '[object Object]';
|
15918 | };
|
15919 | |
15920 |
|
15921 |
|
15922 |
|
15923 |
|
15924 |
|
15925 |
|
15926 |
|
15927 |
|
15928 |
|
15929 | Request.prototype.end = function (fn) {
|
15930 | if (this._endCalled) {
|
15931 | console.warn('Warning: .end() was called twice. This is not supported in superagent');
|
15932 | }
|
15933 |
|
15934 | this._endCalled = true;
|
15935 |
|
15936 | this._callback = fn || noop;
|
15937 |
|
15938 | this._finalizeQueryString();
|
15939 |
|
15940 | this._end();
|
15941 | };
|
15942 |
|
15943 | Request.prototype._setUploadTimeout = function () {
|
15944 | var self = this;
|
15945 |
|
15946 | if (this._uploadTimeout && !this._uploadTimeoutTimer) {
|
15947 | this._uploadTimeoutTimer = setTimeout(function () {
|
15948 | self._timeoutError('Upload timeout of ', self._uploadTimeout, 'ETIMEDOUT');
|
15949 | }, this._uploadTimeout);
|
15950 | }
|
15951 | };
|
15952 |
|
15953 |
|
15954 | Request.prototype._end = function () {
|
15955 | if (this._aborted) return this.callback(new Error('The request has been aborted even before .end() was called'));
|
15956 | var self = this;
|
15957 | this.xhr = request.getXHR();
|
15958 | var xhr = this.xhr;
|
15959 | var data = this._formData || this._data;
|
15960 |
|
15961 | this._setTimeouts();
|
15962 |
|
15963 |
|
15964 | xhr.onreadystatechange = function () {
|
15965 | var readyState = xhr.readyState;
|
15966 |
|
15967 | if (readyState >= 2 && self._responseTimeoutTimer) {
|
15968 | clearTimeout(self._responseTimeoutTimer);
|
15969 | }
|
15970 |
|
15971 | if (readyState !== 4) {
|
15972 | return;
|
15973 | }
|
15974 |
|
15975 |
|
15976 |
|
15977 | var status;
|
15978 |
|
15979 | try {
|
15980 | status = xhr.status;
|
15981 | } catch (err) {
|
15982 | status = 0;
|
15983 | }
|
15984 |
|
15985 | if (!status) {
|
15986 | if (self.timedout || self._aborted) return;
|
15987 | return self.crossDomainError();
|
15988 | }
|
15989 |
|
15990 | self.emit('end');
|
15991 | };
|
15992 |
|
15993 |
|
15994 | var handleProgress = function handleProgress(direction, e) {
|
15995 | if (e.total > 0) {
|
15996 | e.percent = e.loaded / e.total * 100;
|
15997 |
|
15998 | if (e.percent === 100) {
|
15999 | clearTimeout(self._uploadTimeoutTimer);
|
16000 | }
|
16001 | }
|
16002 |
|
16003 | e.direction = direction;
|
16004 | self.emit('progress', e);
|
16005 | };
|
16006 |
|
16007 | if (this.hasListeners('progress')) {
|
16008 | try {
|
16009 | xhr.addEventListener('progress', handleProgress.bind(null, 'download'));
|
16010 |
|
16011 | if (xhr.upload) {
|
16012 | xhr.upload.addEventListener('progress', handleProgress.bind(null, 'upload'));
|
16013 | }
|
16014 | } catch (err) {
|
16015 |
|
16016 |
|
16017 | }
|
16018 | }
|
16019 |
|
16020 | if (xhr.upload) {
|
16021 | this._setUploadTimeout();
|
16022 | }
|
16023 |
|
16024 |
|
16025 | try {
|
16026 | if (this.username && this.password) {
|
16027 | xhr.open(this.method, this.url, true, this.username, this.password);
|
16028 | } else {
|
16029 | xhr.open(this.method, this.url, true);
|
16030 | }
|
16031 | } catch (err) {
|
16032 |
|
16033 | return this.callback(err);
|
16034 | }
|
16035 |
|
16036 |
|
16037 | if (this._withCredentials) xhr.withCredentials = true;
|
16038 |
|
16039 | if (!this._formData && this.method !== 'GET' && this.method !== 'HEAD' && typeof data !== 'string' && !this._isHost(data)) {
|
16040 |
|
16041 | var contentType = this._header['content-type'];
|
16042 |
|
16043 | var _serialize = this._serializer || request.serialize[contentType ? contentType.split(';')[0] : ''];
|
16044 |
|
16045 | if (!_serialize && isJSON(contentType)) {
|
16046 | _serialize = request.serialize['application/json'];
|
16047 | }
|
16048 |
|
16049 | if (_serialize) data = _serialize(data);
|
16050 | }
|
16051 |
|
16052 |
|
16053 | for (var field in this.header) {
|
16054 | if (this.header[field] === null) continue;
|
16055 | if (Object.prototype.hasOwnProperty.call(this.header, field)) xhr.setRequestHeader(field, this.header[field]);
|
16056 | }
|
16057 |
|
16058 | if (this._responseType) {
|
16059 | xhr.responseType = this._responseType;
|
16060 | }
|
16061 |
|
16062 |
|
16063 | this.emit('request', this);
|
16064 |
|
16065 |
|
16066 | xhr.send(typeof data === 'undefined' ? null : data);
|
16067 | };
|
16068 |
|
16069 | request.agent = function () {
|
16070 | return new agentBase();
|
16071 | };
|
16072 |
|
16073 | ['GET', 'POST', 'OPTIONS', 'PATCH', 'PUT', 'DELETE'].forEach(function (method) {
|
16074 | agentBase.prototype[method.toLowerCase()] = function (url, fn) {
|
16075 | var req = new request.Request(method, url);
|
16076 |
|
16077 | this._setDefaults(req);
|
16078 |
|
16079 | if (fn) {
|
16080 | req.end(fn);
|
16081 | }
|
16082 |
|
16083 | return req;
|
16084 | };
|
16085 | });
|
16086 | agentBase.prototype.del = agentBase.prototype.delete;
|
16087 | |
16088 |
|
16089 |
|
16090 |
|
16091 |
|
16092 |
|
16093 |
|
16094 |
|
16095 |
|
16096 |
|
16097 | request.get = function (url, data, fn) {
|
16098 | var req = request('GET', url);
|
16099 |
|
16100 | if (typeof data === 'function') {
|
16101 | fn = data;
|
16102 | data = null;
|
16103 | }
|
16104 |
|
16105 | if (data) req.query(data);
|
16106 | if (fn) req.end(fn);
|
16107 | return req;
|
16108 | };
|
16109 | |
16110 |
|
16111 |
|
16112 |
|
16113 |
|
16114 |
|
16115 |
|
16116 |
|
16117 |
|
16118 |
|
16119 |
|
16120 | request.head = function (url, data, fn) {
|
16121 | var req = request('HEAD', url);
|
16122 |
|
16123 | if (typeof data === 'function') {
|
16124 | fn = data;
|
16125 | data = null;
|
16126 | }
|
16127 |
|
16128 | if (data) req.query(data);
|
16129 | if (fn) req.end(fn);
|
16130 | return req;
|
16131 | };
|
16132 | |
16133 |
|
16134 |
|
16135 |
|
16136 |
|
16137 |
|
16138 |
|
16139 |
|
16140 |
|
16141 |
|
16142 |
|
16143 | request.options = function (url, data, fn) {
|
16144 | var req = request('OPTIONS', url);
|
16145 |
|
16146 | if (typeof data === 'function') {
|
16147 | fn = data;
|
16148 | data = null;
|
16149 | }
|
16150 |
|
16151 | if (data) req.send(data);
|
16152 | if (fn) req.end(fn);
|
16153 | return req;
|
16154 | };
|
16155 | |
16156 |
|
16157 |
|
16158 |
|
16159 |
|
16160 |
|
16161 |
|
16162 |
|
16163 |
|
16164 |
|
16165 |
|
16166 | function del(url, data, fn) {
|
16167 | var req = request('DELETE', url);
|
16168 |
|
16169 | if (typeof data === 'function') {
|
16170 | fn = data;
|
16171 | data = null;
|
16172 | }
|
16173 |
|
16174 | if (data) req.send(data);
|
16175 | if (fn) req.end(fn);
|
16176 | return req;
|
16177 | }
|
16178 |
|
16179 | request.del = del;
|
16180 | request.delete = del;
|
16181 | |
16182 |
|
16183 |
|
16184 |
|
16185 |
|
16186 |
|
16187 |
|
16188 |
|
16189 |
|
16190 |
|
16191 | request.patch = function (url, data, fn) {
|
16192 | var req = request('PATCH', url);
|
16193 |
|
16194 | if (typeof data === 'function') {
|
16195 | fn = data;
|
16196 | data = null;
|
16197 | }
|
16198 |
|
16199 | if (data) req.send(data);
|
16200 | if (fn) req.end(fn);
|
16201 | return req;
|
16202 | };
|
16203 | |
16204 |
|
16205 |
|
16206 |
|
16207 |
|
16208 |
|
16209 |
|
16210 |
|
16211 |
|
16212 |
|
16213 |
|
16214 | request.post = function (url, data, fn) {
|
16215 | var req = request('POST', url);
|
16216 |
|
16217 | if (typeof data === 'function') {
|
16218 | fn = data;
|
16219 | data = null;
|
16220 | }
|
16221 |
|
16222 | if (data) req.send(data);
|
16223 | if (fn) req.end(fn);
|
16224 | return req;
|
16225 | };
|
16226 | |
16227 |
|
16228 |
|
16229 |
|
16230 |
|
16231 |
|
16232 |
|
16233 |
|
16234 |
|
16235 |
|
16236 |
|
16237 | request.put = function (url, data, fn) {
|
16238 | var req = request('PUT', url);
|
16239 |
|
16240 | if (typeof data === 'function') {
|
16241 | fn = data;
|
16242 | data = null;
|
16243 | }
|
16244 |
|
16245 | if (data) req.send(data);
|
16246 | if (fn) req.end(fn);
|
16247 | return req;
|
16248 | };
|
16249 | });
|
16250 | var client_1 = client.Request;
|
16251 |
|
16252 | |
16253 |
|
16254 |
|
16255 |
|
16256 |
|
16257 |
|
16258 |
|
16259 |
|
16260 | function copyArray(source, array) {
|
16261 | var index = -1,
|
16262 | length = source.length;
|
16263 |
|
16264 | array || (array = Array(length));
|
16265 | while (++index < length) {
|
16266 | array[index] = source[index];
|
16267 | }
|
16268 | return array;
|
16269 | }
|
16270 |
|
16271 | var _copyArray = copyArray;
|
16272 |
|
16273 |
|
16274 | var nativeFloor = Math.floor,
|
16275 | nativeRandom = Math.random;
|
16276 |
|
16277 | |
16278 |
|
16279 |
|
16280 |
|
16281 |
|
16282 |
|
16283 |
|
16284 |
|
16285 |
|
16286 | function baseRandom(lower, upper) {
|
16287 | return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
|
16288 | }
|
16289 |
|
16290 | var _baseRandom = baseRandom;
|
16291 |
|
16292 | |
16293 |
|
16294 |
|
16295 |
|
16296 |
|
16297 |
|
16298 |
|
16299 |
|
16300 | function shuffleSelf(array, size) {
|
16301 | var index = -1,
|
16302 | length = array.length,
|
16303 | lastIndex = length - 1;
|
16304 |
|
16305 | size = size === undefined ? length : size;
|
16306 | while (++index < size) {
|
16307 | var rand = _baseRandom(index, lastIndex),
|
16308 | value = array[rand];
|
16309 |
|
16310 | array[rand] = array[index];
|
16311 | array[index] = value;
|
16312 | }
|
16313 | array.length = size;
|
16314 | return array;
|
16315 | }
|
16316 |
|
16317 | var _shuffleSelf = shuffleSelf;
|
16318 |
|
16319 | |
16320 |
|
16321 |
|
16322 |
|
16323 |
|
16324 |
|
16325 |
|
16326 | function arrayShuffle(array) {
|
16327 | return _shuffleSelf(_copyArray(array));
|
16328 | }
|
16329 |
|
16330 | var _arrayShuffle = arrayShuffle;
|
16331 |
|
16332 | |
16333 |
|
16334 |
|
16335 |
|
16336 |
|
16337 |
|
16338 |
|
16339 |
|
16340 |
|
16341 | function arrayMap(array, iteratee) {
|
16342 | var index = -1,
|
16343 | length = array == null ? 0 : array.length,
|
16344 | result = Array(length);
|
16345 |
|
16346 | while (++index < length) {
|
16347 | result[index] = iteratee(array[index], index, array);
|
16348 | }
|
16349 | return result;
|
16350 | }
|
16351 |
|
16352 | var _arrayMap = arrayMap;
|
16353 |
|
16354 | |
16355 |
|
16356 |
|
16357 |
|
16358 |
|
16359 |
|
16360 |
|
16361 |
|
16362 |
|
16363 |
|
16364 | function baseValues(object, props) {
|
16365 | return _arrayMap(props, function(key) {
|
16366 | return object[key];
|
16367 | });
|
16368 | }
|
16369 |
|
16370 | var _baseValues = baseValues;
|
16371 |
|
16372 | |
16373 |
|
16374 |
|
16375 |
|
16376 |
|
16377 |
|
16378 |
|
16379 |
|
16380 |
|
16381 | function baseTimes(n, iteratee) {
|
16382 | var index = -1,
|
16383 | result = Array(n);
|
16384 |
|
16385 | while (++index < n) {
|
16386 | result[index] = iteratee(index);
|
16387 | }
|
16388 | return result;
|
16389 | }
|
16390 |
|
16391 | var _baseTimes = baseTimes;
|
16392 |
|
16393 |
|
16394 | var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal;
|
16395 |
|
16396 | var _freeGlobal = freeGlobal;
|
16397 |
|
16398 |
|
16399 | var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
16400 |
|
16401 |
|
16402 | var root = _freeGlobal || freeSelf || Function('return this')();
|
16403 |
|
16404 | var _root = root;
|
16405 |
|
16406 |
|
16407 | var Symbol$1 = _root.Symbol;
|
16408 |
|
16409 | var _Symbol = Symbol$1;
|
16410 |
|
16411 |
|
16412 | var objectProto = Object.prototype;
|
16413 |
|
16414 |
|
16415 | var hasOwnProperty$1 = objectProto.hasOwnProperty;
|
16416 |
|
16417 | |
16418 |
|
16419 |
|
16420 |
|
16421 |
|
16422 | var nativeObjectToString = objectProto.toString;
|
16423 |
|
16424 |
|
16425 | var symToStringTag = _Symbol ? _Symbol.toStringTag : undefined;
|
16426 |
|
16427 | |
16428 |
|
16429 |
|
16430 |
|
16431 |
|
16432 |
|
16433 |
|
16434 | function getRawTag(value) {
|
16435 | var isOwn = hasOwnProperty$1.call(value, symToStringTag),
|
16436 | tag = value[symToStringTag];
|
16437 |
|
16438 | try {
|
16439 | value[symToStringTag] = undefined;
|
16440 | var unmasked = true;
|
16441 | } catch (e) {}
|
16442 |
|
16443 | var result = nativeObjectToString.call(value);
|
16444 | if (unmasked) {
|
16445 | if (isOwn) {
|
16446 | value[symToStringTag] = tag;
|
16447 | } else {
|
16448 | delete value[symToStringTag];
|
16449 | }
|
16450 | }
|
16451 | return result;
|
16452 | }
|
16453 |
|
16454 | var _getRawTag = getRawTag;
|
16455 |
|
16456 |
|
16457 | var objectProto$1 = Object.prototype;
|
16458 |
|
16459 | |
16460 |
|
16461 |
|
16462 |
|
16463 |
|
16464 | var nativeObjectToString$1 = objectProto$1.toString;
|
16465 |
|
16466 | |
16467 |
|
16468 |
|
16469 |
|
16470 |
|
16471 |
|
16472 |
|
16473 | function objectToString(value) {
|
16474 | return nativeObjectToString$1.call(value);
|
16475 | }
|
16476 |
|
16477 | var _objectToString = objectToString;
|
16478 |
|
16479 |
|
16480 | var nullTag = '[object Null]',
|
16481 | undefinedTag = '[object Undefined]';
|
16482 |
|
16483 |
|
16484 | var symToStringTag$1 = _Symbol ? _Symbol.toStringTag : undefined;
|
16485 |
|
16486 | |
16487 |
|
16488 |
|
16489 |
|
16490 |
|
16491 |
|
16492 |
|
16493 | function baseGetTag(value) {
|
16494 | if (value == null) {
|
16495 | return value === undefined ? undefinedTag : nullTag;
|
16496 | }
|
16497 | return (symToStringTag$1 && symToStringTag$1 in Object(value))
|
16498 | ? _getRawTag(value)
|
16499 | : _objectToString(value);
|
16500 | }
|
16501 |
|
16502 | var _baseGetTag = baseGetTag;
|
16503 |
|
16504 | |
16505 |
|
16506 |
|
16507 |
|
16508 |
|
16509 |
|
16510 |
|
16511 |
|
16512 |
|
16513 |
|
16514 |
|
16515 |
|
16516 |
|
16517 |
|
16518 |
|
16519 |
|
16520 |
|
16521 |
|
16522 |
|
16523 |
|
16524 |
|
16525 |
|
16526 |
|
16527 |
|
16528 | function isObjectLike(value) {
|
16529 | return value != null && typeof value == 'object';
|
16530 | }
|
16531 |
|
16532 | var isObjectLike_1 = isObjectLike;
|
16533 |
|
16534 |
|
16535 | var argsTag = '[object Arguments]';
|
16536 |
|
16537 | |
16538 |
|
16539 |
|
16540 |
|
16541 |
|
16542 |
|
16543 |
|
16544 | function baseIsArguments(value) {
|
16545 | return isObjectLike_1(value) && _baseGetTag(value) == argsTag;
|
16546 | }
|
16547 |
|
16548 | var _baseIsArguments = baseIsArguments;
|
16549 |
|
16550 |
|
16551 | var objectProto$2 = Object.prototype;
|
16552 |
|
16553 |
|
16554 | var hasOwnProperty$2 = objectProto$2.hasOwnProperty;
|
16555 |
|
16556 |
|
16557 | var propertyIsEnumerable = objectProto$2.propertyIsEnumerable;
|
16558 |
|
16559 | |
16560 |
|
16561 |
|
16562 |
|
16563 |
|
16564 |
|
16565 |
|
16566 |
|
16567 |
|
16568 |
|
16569 |
|
16570 |
|
16571 |
|
16572 |
|
16573 |
|
16574 |
|
16575 |
|
16576 |
|
16577 | var isArguments = _baseIsArguments(function() { return arguments; }()) ? _baseIsArguments : function(value) {
|
16578 | return isObjectLike_1(value) && hasOwnProperty$2.call(value, 'callee') &&
|
16579 | !propertyIsEnumerable.call(value, 'callee');
|
16580 | };
|
16581 |
|
16582 | var isArguments_1 = isArguments;
|
16583 |
|
16584 | |
16585 |
|
16586 |
|
16587 |
|
16588 |
|
16589 |
|
16590 |
|
16591 |
|
16592 |
|
16593 |
|
16594 |
|
16595 |
|
16596 |
|
16597 |
|
16598 |
|
16599 |
|
16600 |
|
16601 |
|
16602 |
|
16603 |
|
16604 |
|
16605 |
|
16606 |
|
16607 | var isArray = Array.isArray;
|
16608 |
|
16609 | var isArray_1 = isArray;
|
16610 |
|
16611 | |
16612 |
|
16613 |
|
16614 |
|
16615 |
|
16616 |
|
16617 |
|
16618 |
|
16619 |
|
16620 |
|
16621 |
|
16622 |
|
16623 |
|
16624 | function stubFalse() {
|
16625 | return false;
|
16626 | }
|
16627 |
|
16628 | var stubFalse_1 = stubFalse;
|
16629 |
|
16630 | var isBuffer_1 = createCommonjsModule(function (module, exports) {
|
16631 |
|
16632 | var freeExports = exports && !exports.nodeType && exports;
|
16633 |
|
16634 |
|
16635 | var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
|
16636 |
|
16637 |
|
16638 | var moduleExports = freeModule && freeModule.exports === freeExports;
|
16639 |
|
16640 |
|
16641 | var Buffer = moduleExports ? _root.Buffer : undefined;
|
16642 |
|
16643 |
|
16644 | var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
|
16645 |
|
16646 | |
16647 |
|
16648 |
|
16649 |
|
16650 |
|
16651 |
|
16652 |
|
16653 |
|
16654 |
|
16655 |
|
16656 |
|
16657 |
|
16658 |
|
16659 |
|
16660 |
|
16661 |
|
16662 |
|
16663 | var isBuffer = nativeIsBuffer || stubFalse_1;
|
16664 |
|
16665 | module.exports = isBuffer;
|
16666 | });
|
16667 |
|
16668 |
|
16669 | var MAX_SAFE_INTEGER = 9007199254740991;
|
16670 |
|
16671 |
|
16672 | var reIsUint = /^(?:0|[1-9]\d*)$/;
|
16673 |
|
16674 | |
16675 |
|
16676 |
|
16677 |
|
16678 |
|
16679 |
|
16680 |
|
16681 |
|
16682 | function isIndex(value, length) {
|
16683 | var type = typeof value;
|
16684 | length = length == null ? MAX_SAFE_INTEGER : length;
|
16685 |
|
16686 | return !!length &&
|
16687 | (type == 'number' ||
|
16688 | (type != 'symbol' && reIsUint.test(value))) &&
|
16689 | (value > -1 && value % 1 == 0 && value < length);
|
16690 | }
|
16691 |
|
16692 | var _isIndex = isIndex;
|
16693 |
|
16694 |
|
16695 | var MAX_SAFE_INTEGER$1 = 9007199254740991;
|
16696 |
|
16697 | |
16698 |
|
16699 |
|
16700 |
|
16701 |
|
16702 |
|
16703 |
|
16704 |
|
16705 |
|
16706 |
|
16707 |
|
16708 |
|
16709 |
|
16710 |
|
16711 |
|
16712 |
|
16713 |
|
16714 |
|
16715 |
|
16716 |
|
16717 |
|
16718 |
|
16719 |
|
16720 |
|
16721 |
|
16722 |
|
16723 | function isLength(value) {
|
16724 | return typeof value == 'number' &&
|
16725 | value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER$1;
|
16726 | }
|
16727 |
|
16728 | var isLength_1 = isLength;
|
16729 |
|
16730 |
|
16731 | var argsTag$1 = '[object Arguments]',
|
16732 | arrayTag = '[object Array]',
|
16733 | boolTag = '[object Boolean]',
|
16734 | dateTag = '[object Date]',
|
16735 | errorTag = '[object Error]',
|
16736 | funcTag = '[object Function]',
|
16737 | mapTag = '[object Map]',
|
16738 | numberTag = '[object Number]',
|
16739 | objectTag = '[object Object]',
|
16740 | regexpTag = '[object RegExp]',
|
16741 | setTag = '[object Set]',
|
16742 | stringTag = '[object String]',
|
16743 | weakMapTag = '[object WeakMap]';
|
16744 |
|
16745 | var arrayBufferTag = '[object ArrayBuffer]',
|
16746 | dataViewTag = '[object DataView]',
|
16747 | float32Tag = '[object Float32Array]',
|
16748 | float64Tag = '[object Float64Array]',
|
16749 | int8Tag = '[object Int8Array]',
|
16750 | int16Tag = '[object Int16Array]',
|
16751 | int32Tag = '[object Int32Array]',
|
16752 | uint8Tag = '[object Uint8Array]',
|
16753 | uint8ClampedTag = '[object Uint8ClampedArray]',
|
16754 | uint16Tag = '[object Uint16Array]',
|
16755 | uint32Tag = '[object Uint32Array]';
|
16756 |
|
16757 |
|
16758 | var typedArrayTags = {};
|
16759 | typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
|
16760 | typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
|
16761 | typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
|
16762 | typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
|
16763 | typedArrayTags[uint32Tag] = true;
|
16764 | typedArrayTags[argsTag$1] = typedArrayTags[arrayTag] =
|
16765 | typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
|
16766 | typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
|
16767 | typedArrayTags[errorTag] = typedArrayTags[funcTag] =
|
16768 | typedArrayTags[mapTag] = typedArrayTags[numberTag] =
|
16769 | typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
|
16770 | typedArrayTags[setTag] = typedArrayTags[stringTag] =
|
16771 | typedArrayTags[weakMapTag] = false;
|
16772 |
|
16773 | |
16774 |
|
16775 |
|
16776 |
|
16777 |
|
16778 |
|
16779 |
|
16780 | function baseIsTypedArray(value) {
|
16781 | return isObjectLike_1(value) &&
|
16782 | isLength_1(value.length) && !!typedArrayTags[_baseGetTag(value)];
|
16783 | }
|
16784 |
|
16785 | var _baseIsTypedArray = baseIsTypedArray;
|
16786 |
|
16787 | |
16788 |
|
16789 |
|
16790 |
|
16791 |
|
16792 |
|
16793 |
|
16794 | function baseUnary(func) {
|
16795 | return function(value) {
|
16796 | return func(value);
|
16797 | };
|
16798 | }
|
16799 |
|
16800 | var _baseUnary = baseUnary;
|
16801 |
|
16802 | var _nodeUtil = createCommonjsModule(function (module, exports) {
|
16803 |
|
16804 | var freeExports = exports && !exports.nodeType && exports;
|
16805 |
|
16806 |
|
16807 | var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
|
16808 |
|
16809 |
|
16810 | var moduleExports = freeModule && freeModule.exports === freeExports;
|
16811 |
|
16812 |
|
16813 | var freeProcess = moduleExports && _freeGlobal.process;
|
16814 |
|
16815 |
|
16816 | var nodeUtil = (function() {
|
16817 | try {
|
16818 |
|
16819 | var types = freeModule && freeModule.require && freeModule.require('util').types;
|
16820 |
|
16821 | if (types) {
|
16822 | return types;
|
16823 | }
|
16824 |
|
16825 |
|
16826 | return freeProcess && freeProcess.binding && freeProcess.binding('util');
|
16827 | } catch (e) {}
|
16828 | }());
|
16829 |
|
16830 | module.exports = nodeUtil;
|
16831 | });
|
16832 |
|
16833 |
|
16834 | var nodeIsTypedArray = _nodeUtil && _nodeUtil.isTypedArray;
|
16835 |
|
16836 | |
16837 |
|
16838 |
|
16839 |
|
16840 |
|
16841 |
|
16842 |
|
16843 |
|
16844 |
|
16845 |
|
16846 |
|
16847 |
|
16848 |
|
16849 |
|
16850 |
|
16851 |
|
16852 |
|
16853 | var isTypedArray = nodeIsTypedArray ? _baseUnary(nodeIsTypedArray) : _baseIsTypedArray;
|
16854 |
|
16855 | var isTypedArray_1 = isTypedArray;
|
16856 |
|
16857 |
|
16858 | var objectProto$3 = Object.prototype;
|
16859 |
|
16860 |
|
16861 | var hasOwnProperty$3 = objectProto$3.hasOwnProperty;
|
16862 |
|
16863 | |
16864 |
|
16865 |
|
16866 |
|
16867 |
|
16868 |
|
16869 |
|
16870 |
|
16871 | function arrayLikeKeys(value, inherited) {
|
16872 | var isArr = isArray_1(value),
|
16873 | isArg = !isArr && isArguments_1(value),
|
16874 | isBuff = !isArr && !isArg && isBuffer_1(value),
|
16875 | isType = !isArr && !isArg && !isBuff && isTypedArray_1(value),
|
16876 | skipIndexes = isArr || isArg || isBuff || isType,
|
16877 | result = skipIndexes ? _baseTimes(value.length, String) : [],
|
16878 | length = result.length;
|
16879 |
|
16880 | for (var key in value) {
|
16881 | if ((inherited || hasOwnProperty$3.call(value, key)) &&
|
16882 | !(skipIndexes && (
|
16883 |
|
16884 | key == 'length' ||
|
16885 |
|
16886 | (isBuff && (key == 'offset' || key == 'parent')) ||
|
16887 |
|
16888 | (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
|
16889 |
|
16890 | _isIndex(key, length)
|
16891 | ))) {
|
16892 | result.push(key);
|
16893 | }
|
16894 | }
|
16895 | return result;
|
16896 | }
|
16897 |
|
16898 | var _arrayLikeKeys = arrayLikeKeys;
|
16899 |
|
16900 |
|
16901 | var objectProto$4 = Object.prototype;
|
16902 |
|
16903 | |
16904 |
|
16905 |
|
16906 |
|
16907 |
|
16908 |
|
16909 |
|
16910 | function isPrototype(value) {
|
16911 | var Ctor = value && value.constructor,
|
16912 | proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto$4;
|
16913 |
|
16914 | return value === proto;
|
16915 | }
|
16916 |
|
16917 | var _isPrototype = isPrototype;
|
16918 |
|
16919 | |
16920 |
|
16921 |
|
16922 |
|
16923 |
|
16924 |
|
16925 |
|
16926 |
|
16927 | function overArg(func, transform) {
|
16928 | return function(arg) {
|
16929 | return func(transform(arg));
|
16930 | };
|
16931 | }
|
16932 |
|
16933 | var _overArg = overArg;
|
16934 |
|
16935 |
|
16936 | var nativeKeys = _overArg(Object.keys, Object);
|
16937 |
|
16938 | var _nativeKeys = nativeKeys;
|
16939 |
|
16940 |
|
16941 | var objectProto$5 = Object.prototype;
|
16942 |
|
16943 |
|
16944 | var hasOwnProperty$4 = objectProto$5.hasOwnProperty;
|
16945 |
|
16946 | |
16947 |
|
16948 |
|
16949 |
|
16950 |
|
16951 |
|
16952 |
|
16953 | function baseKeys(object) {
|
16954 | if (!_isPrototype(object)) {
|
16955 | return _nativeKeys(object);
|
16956 | }
|
16957 | var result = [];
|
16958 | for (var key in Object(object)) {
|
16959 | if (hasOwnProperty$4.call(object, key) && key != 'constructor') {
|
16960 | result.push(key);
|
16961 | }
|
16962 | }
|
16963 | return result;
|
16964 | }
|
16965 |
|
16966 | var _baseKeys = baseKeys;
|
16967 |
|
16968 | |
16969 |
|
16970 |
|
16971 |
|
16972 |
|
16973 |
|
16974 |
|
16975 |
|
16976 |
|
16977 |
|
16978 |
|
16979 |
|
16980 |
|
16981 |
|
16982 |
|
16983 |
|
16984 |
|
16985 |
|
16986 |
|
16987 |
|
16988 |
|
16989 |
|
16990 |
|
16991 |
|
16992 |
|
16993 | function isObject$1(value) {
|
16994 | var type = typeof value;
|
16995 | return value != null && (type == 'object' || type == 'function');
|
16996 | }
|
16997 |
|
16998 | var isObject_1$1 = isObject$1;
|
16999 |
|
17000 |
|
17001 | var asyncTag = '[object AsyncFunction]',
|
17002 | funcTag$1 = '[object Function]',
|
17003 | genTag = '[object GeneratorFunction]',
|
17004 | proxyTag = '[object Proxy]';
|
17005 |
|
17006 | |
17007 |
|
17008 |
|
17009 |
|
17010 |
|
17011 |
|
17012 |
|
17013 |
|
17014 |
|
17015 |
|
17016 |
|
17017 |
|
17018 |
|
17019 |
|
17020 |
|
17021 |
|
17022 |
|
17023 | function isFunction(value) {
|
17024 | if (!isObject_1$1(value)) {
|
17025 | return false;
|
17026 | }
|
17027 |
|
17028 |
|
17029 | var tag = _baseGetTag(value);
|
17030 | return tag == funcTag$1 || tag == genTag || tag == asyncTag || tag == proxyTag;
|
17031 | }
|
17032 |
|
17033 | var isFunction_1 = isFunction;
|
17034 |
|
17035 | |
17036 |
|
17037 |
|
17038 |
|
17039 |
|
17040 |
|
17041 |
|
17042 |
|
17043 |
|
17044 |
|
17045 |
|
17046 |
|
17047 |
|
17048 |
|
17049 |
|
17050 |
|
17051 |
|
17052 |
|
17053 |
|
17054 |
|
17055 |
|
17056 |
|
17057 |
|
17058 |
|
17059 |
|
17060 | function isArrayLike(value) {
|
17061 | return value != null && isLength_1(value.length) && !isFunction_1(value);
|
17062 | }
|
17063 |
|
17064 | var isArrayLike_1 = isArrayLike;
|
17065 |
|
17066 | |
17067 |
|
17068 |
|
17069 |
|
17070 |
|
17071 |
|
17072 |
|
17073 |
|
17074 |
|
17075 |
|
17076 |
|
17077 |
|
17078 |
|
17079 |
|
17080 |
|
17081 |
|
17082 |
|
17083 |
|
17084 |
|
17085 |
|
17086 |
|
17087 |
|
17088 |
|
17089 |
|
17090 |
|
17091 |
|
17092 |
|
17093 |
|
17094 | function keys(object) {
|
17095 | return isArrayLike_1(object) ? _arrayLikeKeys(object) : _baseKeys(object);
|
17096 | }
|
17097 |
|
17098 | var keys_1 = keys;
|
17099 |
|
17100 | |
17101 |
|
17102 |
|
17103 |
|
17104 |
|
17105 |
|
17106 |
|
17107 |
|
17108 |
|
17109 |
|
17110 |
|
17111 |
|
17112 |
|
17113 |
|
17114 |
|
17115 |
|
17116 |
|
17117 |
|
17118 |
|
17119 |
|
17120 |
|
17121 |
|
17122 |
|
17123 |
|
17124 |
|
17125 |
|
17126 | function values(object) {
|
17127 | return object == null ? [] : _baseValues(object, keys_1(object));
|
17128 | }
|
17129 |
|
17130 | var values_1 = values;
|
17131 |
|
17132 | |
17133 |
|
17134 |
|
17135 |
|
17136 |
|
17137 |
|
17138 |
|
17139 | function baseShuffle(collection) {
|
17140 | return _shuffleSelf(values_1(collection));
|
17141 | }
|
17142 |
|
17143 | var _baseShuffle = baseShuffle;
|
17144 |
|
17145 | |
17146 |
|
17147 |
|
17148 |
|
17149 |
|
17150 |
|
17151 |
|
17152 |
|
17153 |
|
17154 |
|
17155 |
|
17156 |
|
17157 |
|
17158 |
|
17159 |
|
17160 | function shuffle(collection) {
|
17161 | var func = isArray_1(collection) ? _arrayShuffle : _baseShuffle;
|
17162 | return func(collection);
|
17163 | }
|
17164 |
|
17165 | var shuffle_1 = shuffle;
|
17166 |
|
17167 | var stateMachine = createCommonjsModule(function (module, exports) {
|
17168 | |
17169 |
|
17170 |
|
17171 |
|
17172 |
|
17173 |
|
17174 |
|
17175 |
|
17176 |
|
17177 | (function () {
|
17178 |
|
17179 | var StateMachine = {
|
17180 |
|
17181 |
|
17182 |
|
17183 | VERSION: "2.4.0",
|
17184 |
|
17185 |
|
17186 |
|
17187 | Result: {
|
17188 | SUCCEEDED: 1,
|
17189 | NOTRANSITION: 2,
|
17190 | CANCELLED: 3,
|
17191 | PENDING: 4
|
17192 | },
|
17193 |
|
17194 | Error: {
|
17195 | INVALID_TRANSITION: 100,
|
17196 | PENDING_TRANSITION: 200,
|
17197 | INVALID_CALLBACK: 300
|
17198 | },
|
17199 |
|
17200 | WILDCARD: '*',
|
17201 | ASYNC: 'async',
|
17202 |
|
17203 |
|
17204 |
|
17205 | create: function(cfg, target) {
|
17206 |
|
17207 | var initial = (typeof cfg.initial == 'string') ? { state: cfg.initial } : cfg.initial;
|
17208 | var terminal = cfg.terminal || cfg['final'];
|
17209 | var fsm = target || cfg.target || {};
|
17210 | var events = cfg.events || [];
|
17211 | var callbacks = cfg.callbacks || {};
|
17212 | var map = {};
|
17213 | var transitions = {};
|
17214 |
|
17215 | var add = function(e) {
|
17216 | var from = Array.isArray(e.from) ? e.from : (e.from ? [e.from] : [StateMachine.WILDCARD]);
|
17217 | map[e.name] = map[e.name] || {};
|
17218 | for (var n = 0 ; n < from.length ; n++) {
|
17219 | transitions[from[n]] = transitions[from[n]] || [];
|
17220 | transitions[from[n]].push(e.name);
|
17221 |
|
17222 | map[e.name][from[n]] = e.to || from[n];
|
17223 | }
|
17224 | if (e.to)
|
17225 | transitions[e.to] = transitions[e.to] || [];
|
17226 | };
|
17227 |
|
17228 | if (initial) {
|
17229 | initial.event = initial.event || 'startup';
|
17230 | add({ name: initial.event, from: 'none', to: initial.state });
|
17231 | }
|
17232 |
|
17233 | for(var n = 0 ; n < events.length ; n++)
|
17234 | add(events[n]);
|
17235 |
|
17236 | for(var name in map) {
|
17237 | if (map.hasOwnProperty(name))
|
17238 | fsm[name] = StateMachine.buildEvent(name, map[name]);
|
17239 | }
|
17240 |
|
17241 | for(var name in callbacks) {
|
17242 | if (callbacks.hasOwnProperty(name))
|
17243 | fsm[name] = callbacks[name];
|
17244 | }
|
17245 |
|
17246 | fsm.current = 'none';
|
17247 | fsm.is = function(state) { return Array.isArray(state) ? (state.indexOf(this.current) >= 0) : (this.current === state); };
|
17248 | fsm.can = function(event) { return !this.transition && (map[event] !== undefined) && (map[event].hasOwnProperty(this.current) || map[event].hasOwnProperty(StateMachine.WILDCARD)); };
|
17249 | fsm.cannot = function(event) { return !this.can(event); };
|
17250 | fsm.transitions = function() { return (transitions[this.current] || []).concat(transitions[StateMachine.WILDCARD] || []); };
|
17251 | fsm.isFinished = function() { return this.is(terminal); };
|
17252 | fsm.error = cfg.error || function(name, from, to, args, error, msg, e) { throw e || msg; };
|
17253 | fsm.states = function() { return Object.keys(transitions).sort() };
|
17254 |
|
17255 | if (initial && !initial.defer)
|
17256 | fsm[initial.event]();
|
17257 |
|
17258 | return fsm;
|
17259 |
|
17260 | },
|
17261 |
|
17262 |
|
17263 |
|
17264 | doCallback: function(fsm, func, name, from, to, args) {
|
17265 | if (func) {
|
17266 | try {
|
17267 | return func.apply(fsm, [name, from, to].concat(args));
|
17268 | }
|
17269 | catch(e) {
|
17270 | return fsm.error(name, from, to, args, StateMachine.Error.INVALID_CALLBACK, "an exception occurred in a caller-provided callback function", e);
|
17271 | }
|
17272 | }
|
17273 | },
|
17274 |
|
17275 | beforeAnyEvent: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onbeforeevent'], name, from, to, args); },
|
17276 | afterAnyEvent: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onafterevent'] || fsm['onevent'], name, from, to, args); },
|
17277 | leaveAnyState: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onleavestate'], name, from, to, args); },
|
17278 | enterAnyState: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onenterstate'] || fsm['onstate'], name, from, to, args); },
|
17279 | changeState: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onchangestate'], name, from, to, args); },
|
17280 |
|
17281 | beforeThisEvent: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onbefore' + name], name, from, to, args); },
|
17282 | afterThisEvent: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onafter' + name] || fsm['on' + name], name, from, to, args); },
|
17283 | leaveThisState: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onleave' + from], name, from, to, args); },
|
17284 | enterThisState: function(fsm, name, from, to, args) { return StateMachine.doCallback(fsm, fsm['onenter' + to] || fsm['on' + to], name, from, to, args); },
|
17285 |
|
17286 | beforeEvent: function(fsm, name, from, to, args) {
|
17287 | if ((false === StateMachine.beforeThisEvent(fsm, name, from, to, args)) ||
|
17288 | (false === StateMachine.beforeAnyEvent( fsm, name, from, to, args)))
|
17289 | return false;
|
17290 | },
|
17291 |
|
17292 | afterEvent: function(fsm, name, from, to, args) {
|
17293 | StateMachine.afterThisEvent(fsm, name, from, to, args);
|
17294 | StateMachine.afterAnyEvent( fsm, name, from, to, args);
|
17295 | },
|
17296 |
|
17297 | leaveState: function(fsm, name, from, to, args) {
|
17298 | var specific = StateMachine.leaveThisState(fsm, name, from, to, args),
|
17299 | general = StateMachine.leaveAnyState( fsm, name, from, to, args);
|
17300 | if ((false === specific) || (false === general))
|
17301 | return false;
|
17302 | else if ((StateMachine.ASYNC === specific) || (StateMachine.ASYNC === general))
|
17303 | return StateMachine.ASYNC;
|
17304 | },
|
17305 |
|
17306 | enterState: function(fsm, name, from, to, args) {
|
17307 | StateMachine.enterThisState(fsm, name, from, to, args);
|
17308 | StateMachine.enterAnyState( fsm, name, from, to, args);
|
17309 | },
|
17310 |
|
17311 |
|
17312 |
|
17313 | buildEvent: function(name, map) {
|
17314 | return function() {
|
17315 |
|
17316 | var from = this.current;
|
17317 | var to = map[from] || (map[StateMachine.WILDCARD] != StateMachine.WILDCARD ? map[StateMachine.WILDCARD] : from) || from;
|
17318 | var args = Array.prototype.slice.call(arguments);
|
17319 |
|
17320 | if (this.transition)
|
17321 | return this.error(name, from, to, args, StateMachine.Error.PENDING_TRANSITION, "event " + name + " inappropriate because previous transition did not complete");
|
17322 |
|
17323 | if (this.cannot(name))
|
17324 | return this.error(name, from, to, args, StateMachine.Error.INVALID_TRANSITION, "event " + name + " inappropriate in current state " + this.current);
|
17325 |
|
17326 | if (false === StateMachine.beforeEvent(this, name, from, to, args))
|
17327 | return StateMachine.Result.CANCELLED;
|
17328 |
|
17329 | if (from === to) {
|
17330 | StateMachine.afterEvent(this, name, from, to, args);
|
17331 | return StateMachine.Result.NOTRANSITION;
|
17332 | }
|
17333 |
|
17334 |
|
17335 | var fsm = this;
|
17336 | this.transition = function() {
|
17337 | fsm.transition = null;
|
17338 | fsm.current = to;
|
17339 | StateMachine.enterState( fsm, name, from, to, args);
|
17340 | StateMachine.changeState(fsm, name, from, to, args);
|
17341 | StateMachine.afterEvent( fsm, name, from, to, args);
|
17342 | return StateMachine.Result.SUCCEEDED;
|
17343 | };
|
17344 | this.transition.cancel = function() {
|
17345 | fsm.transition = null;
|
17346 | StateMachine.afterEvent(fsm, name, from, to, args);
|
17347 | };
|
17348 |
|
17349 | var leave = StateMachine.leaveState(this, name, from, to, args);
|
17350 | if (false === leave) {
|
17351 | this.transition = null;
|
17352 | return StateMachine.Result.CANCELLED;
|
17353 | }
|
17354 | else if (StateMachine.ASYNC === leave) {
|
17355 | return StateMachine.Result.PENDING;
|
17356 | }
|
17357 | else {
|
17358 | if (this.transition)
|
17359 | return this.transition();
|
17360 | }
|
17361 |
|
17362 | };
|
17363 | }
|
17364 |
|
17365 | };
|
17366 |
|
17367 |
|
17368 |
|
17369 |
|
17370 |
|
17371 |
|
17372 | {
|
17373 | if (module.exports) {
|
17374 | exports = module.exports = StateMachine;
|
17375 | }
|
17376 | exports.StateMachine = StateMachine;
|
17377 | }
|
17378 |
|
17379 | }());
|
17380 | });
|
17381 | var stateMachine_1 = stateMachine.StateMachine;
|
17382 |
|
17383 |
|
17384 | var getPrototype = _overArg(Object.getPrototypeOf, Object);
|
17385 |
|
17386 | var _getPrototype = getPrototype;
|
17387 |
|
17388 |
|
17389 | var objectTag$1 = '[object Object]';
|
17390 |
|
17391 |
|
17392 | var funcProto = Function.prototype,
|
17393 | objectProto$6 = Object.prototype;
|
17394 |
|
17395 |
|
17396 | var funcToString = funcProto.toString;
|
17397 |
|
17398 |
|
17399 | var hasOwnProperty$5 = objectProto$6.hasOwnProperty;
|
17400 |
|
17401 |
|
17402 | var objectCtorString = funcToString.call(Object);
|
17403 |
|
17404 | |
17405 |
|
17406 |
|
17407 |
|
17408 |
|
17409 |
|
17410 |
|
17411 |
|
17412 |
|
17413 |
|
17414 |
|
17415 |
|
17416 |
|
17417 |
|
17418 |
|
17419 |
|
17420 |
|
17421 |
|
17422 |
|
17423 |
|
17424 |
|
17425 |
|
17426 |
|
17427 |
|
17428 |
|
17429 |
|
17430 |
|
17431 |
|
17432 | function isPlainObject(value) {
|
17433 | if (!isObjectLike_1(value) || _baseGetTag(value) != objectTag$1) {
|
17434 | return false;
|
17435 | }
|
17436 | var proto = _getPrototype(value);
|
17437 | if (proto === null) {
|
17438 | return true;
|
17439 | }
|
17440 | var Ctor = hasOwnProperty$5.call(proto, 'constructor') && proto.constructor;
|
17441 | return typeof Ctor == 'function' && Ctor instanceof Ctor &&
|
17442 | funcToString.call(Ctor) == objectCtorString;
|
17443 | }
|
17444 |
|
17445 | var isPlainObject_1 = isPlainObject;
|
17446 |
|
17447 |
|
17448 | var global$1 = typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : {};
|
17449 |
|
17450 | var EXPIRED = Symbol('expired');
|
17451 | var debug = browser('LC:Expirable');
|
17452 |
|
17453 | var Expirable =
|
17454 |
|
17455 | function () {
|
17456 | function Expirable(value, ttl) {
|
17457 | this.originalValue = value;
|
17458 |
|
17459 | if (typeof ttl === 'number') {
|
17460 | this.expiredAt = Date.now() + ttl;
|
17461 | }
|
17462 | }
|
17463 |
|
17464 | _createClass(Expirable, [{
|
17465 | key: "value",
|
17466 | get: function get() {
|
17467 | var expired = this.expiredAt && this.expiredAt <= Date.now();
|
17468 | if (expired) debug("expired: ".concat(this.originalValue));
|
17469 | return expired ? EXPIRED : this.originalValue;
|
17470 | }
|
17471 | }]);
|
17472 |
|
17473 | return Expirable;
|
17474 | }();
|
17475 | Expirable.EXPIRED = EXPIRED;
|
17476 |
|
17477 | var debug$1 = browser('LC:Cache');
|
17478 |
|
17479 | var Cache =
|
17480 |
|
17481 | function () {
|
17482 | function Cache() {
|
17483 | var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'anonymous';
|
17484 | this.name = name;
|
17485 | this._map = {};
|
17486 | }
|
17487 |
|
17488 | var _proto = Cache.prototype;
|
17489 |
|
17490 | _proto.get = function get(key) {
|
17491 | var cache = this._map[key];
|
17492 |
|
17493 | if (cache) {
|
17494 | var value = cache.value;
|
17495 |
|
17496 | if (value !== Expirable.EXPIRED) {
|
17497 | debug$1('[%s] hit: %s', this.name, key);
|
17498 | return value;
|
17499 | }
|
17500 |
|
17501 | delete this._map[key];
|
17502 | }
|
17503 |
|
17504 | debug$1("[".concat(this.name, "] missed: ").concat(key));
|
17505 | return null;
|
17506 | };
|
17507 |
|
17508 | _proto.set = function set(key, value, ttl) {
|
17509 | debug$1('[%s] set: %s %d', this.name, key, ttl);
|
17510 | this._map[key] = new Expirable(value, ttl);
|
17511 | };
|
17512 |
|
17513 | return Cache;
|
17514 | }();
|
17515 |
|
17516 | var debug$2 = {
|
17517 | enable: function enable() {
|
17518 | var namespaces = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'LC*';
|
17519 | return browser.enable(namespaces);
|
17520 | },
|
17521 | disable: browser.disable
|
17522 | };
|
17523 | var tryAll = function tryAll(promiseConstructors) {
|
17524 | var promise = new Promise(promiseConstructors[0]);
|
17525 |
|
17526 | if (promiseConstructors.length === 1) {
|
17527 | return promise;
|
17528 | }
|
17529 |
|
17530 | return promise.catch(function () {
|
17531 | return tryAll(promiseConstructors.slice(1));
|
17532 | });
|
17533 | };
|
17534 |
|
17535 | var tap = function tap(interceptor) {
|
17536 | return function (value) {
|
17537 | return interceptor(value), value;
|
17538 | };
|
17539 | };
|
17540 | var isIE10 = global$1.navigator && global$1.navigator.userAgent && global$1.navigator.userAgent.indexOf('MSIE 10.') !== -1;
|
17541 | var map = new WeakMap();
|
17542 |
|
17543 | var internal = function internal(object) {
|
17544 | if (!map.has(object)) {
|
17545 | map.set(object, {});
|
17546 | }
|
17547 |
|
17548 | return map.get(object);
|
17549 | };
|
17550 | var compact = function compact(obj, filter) {
|
17551 | if (!isPlainObject_1(obj)) return obj;
|
17552 | var object = Object.assign({}, obj);
|
17553 |
|
17554 | for (var prop in object) {
|
17555 | if ({}.hasOwnProperty.call(object, prop)) {
|
17556 | var value = object[prop];
|
17557 |
|
17558 | if (value === filter) {
|
17559 | delete object[prop];
|
17560 | } else {
|
17561 | object[prop] = compact(value, filter);
|
17562 | }
|
17563 | }
|
17564 | }
|
17565 |
|
17566 | return object;
|
17567 | };
|
17568 |
|
17569 | var removeNull = function removeNull(obj) {
|
17570 | return compact(obj, null);
|
17571 | };
|
17572 |
|
17573 | var trim = function trim(message) {
|
17574 | return removeNull(JSON.parse(JSON.stringify(message)));
|
17575 | };
|
17576 | var ensureArray = function ensureArray(target) {
|
17577 | if (Array.isArray(target)) {
|
17578 | return target;
|
17579 | }
|
17580 |
|
17581 | if (target === undefined || target === null) {
|
17582 | return [];
|
17583 | }
|
17584 |
|
17585 | return [target];
|
17586 | };
|
17587 | var isWeapp =
|
17588 | (typeof wx === "undefined" ? "undefined" : _typeof(wx)) === 'object' && typeof wx.connectSocket === 'function';
|
17589 | var isCNApp = function isCNApp(appId) {
|
17590 | return appId.slice(-9) !== '-MdYXbMMI';
|
17591 | };
|
17592 |
|
17593 | var _class;
|
17594 | var debug$3 = browser('LC:WebSocketPlus');
|
17595 | var OPEN$1 = 'open';
|
17596 | var DISCONNECT = 'disconnect';
|
17597 | var RECONNECT = 'reconnect';
|
17598 | var RETRY = 'retry';
|
17599 | var SCHEDULE = 'schedule';
|
17600 | var OFFLINE = 'offline';
|
17601 | var ONLINE = 'online';
|
17602 | var ERROR = 'error';
|
17603 | var MESSAGE = 'message';
|
17604 | var HEARTBEAT_TIME = 180000;
|
17605 | var TIMEOUT_TIME = 380000;
|
17606 |
|
17607 | var DEFAULT_RETRY_STRATEGY = function DEFAULT_RETRY_STRATEGY(attempt) {
|
17608 | return Math.min(1000 * Math.pow(2, attempt), 300000);
|
17609 | };
|
17610 |
|
17611 | var requireConnected = function requireConnected(target, name, descriptor) {
|
17612 | return Object.assign({}, descriptor, {
|
17613 | value: function requireConnectedWrapper() {
|
17614 | var _descriptor$value;
|
17615 |
|
17616 | this.checkConnectionAvailability(name);
|
17617 |
|
17618 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
17619 | args[_key] = arguments[_key];
|
17620 | }
|
17621 |
|
17622 | return (_descriptor$value = descriptor.value).call.apply(_descriptor$value, [this].concat(args));
|
17623 | }
|
17624 | });
|
17625 | };
|
17626 |
|
17627 | var WebSocketPlus = (_class =
|
17628 |
|
17629 | function (_EventEmitter) {
|
17630 | _inheritsLoose(WebSocketPlus, _EventEmitter);
|
17631 |
|
17632 | _createClass(WebSocketPlus, [{
|
17633 | key: "urls",
|
17634 | get: function get() {
|
17635 | return this._urls;
|
17636 | },
|
17637 | set: function set(urls) {
|
17638 | this._urls = ensureArray(urls);
|
17639 | }
|
17640 | }]);
|
17641 |
|
17642 | function WebSocketPlus(getUrls, protocol) {
|
17643 | var _this;
|
17644 |
|
17645 | if (typeof websocket === 'undefined') {
|
17646 | throw new Error('WebSocket is undefined. Polyfill is required in this runtime.');
|
17647 | }
|
17648 |
|
17649 | _this = _EventEmitter.call(this) || this;
|
17650 |
|
17651 | _this.init();
|
17652 |
|
17653 | _this._protocol = protocol;
|
17654 | Promise.resolve(typeof getUrls === 'function' ? getUrls() : getUrls).then(ensureArray).then(function (urls) {
|
17655 | _this._urls = urls;
|
17656 | return _this._open();
|
17657 | }).then(function () {
|
17658 | _this.__postponeTimeoutTimer = _this._postponeTimeoutTimer.bind(_assertThisInitialized(_this));
|
17659 |
|
17660 | if (global$1.addEventListener) {
|
17661 | _this.__pause = function () {
|
17662 | if (_this.can('pause')) _this.pause();
|
17663 | };
|
17664 |
|
17665 | _this.__resume = function () {
|
17666 | if (_this.can('resume')) _this.resume();
|
17667 | };
|
17668 |
|
17669 | global$1.addEventListener('offline', _this.__pause);
|
17670 | global$1.addEventListener('online', _this.__resume);
|
17671 | }
|
17672 |
|
17673 | _this.open();
|
17674 | }).catch(_this.throw.bind(_assertThisInitialized(_this)));
|
17675 | return _this;
|
17676 | }
|
17677 |
|
17678 | var _proto = WebSocketPlus.prototype;
|
17679 |
|
17680 | _proto._open = function _open() {
|
17681 | var _this2 = this;
|
17682 |
|
17683 | return this._createWs(this._urls, this._protocol).then(function (ws) {
|
17684 | var _this2$_urls = _toArray(_this2._urls),
|
17685 | first = _this2$_urls[0],
|
17686 | reset = _this2$_urls.slice(1);
|
17687 |
|
17688 | _this2._urls = [].concat(_toConsumableArray(reset), [first]);
|
17689 | return ws;
|
17690 | });
|
17691 | };
|
17692 |
|
17693 | _proto._createWs = function _createWs(urls, protocol) {
|
17694 | var _this3 = this;
|
17695 |
|
17696 | return tryAll(urls.map(function (url) {
|
17697 | return function (resolve, reject) {
|
17698 | debug$3("connect [".concat(url, "] ").concat(protocol));
|
17699 | var ws = protocol ? new websocket(url, protocol) : new websocket(url);
|
17700 | ws.binaryType = _this3.binaryType || 'arraybuffer';
|
17701 |
|
17702 | ws.onopen = function () {
|
17703 | return resolve(ws);
|
17704 | };
|
17705 |
|
17706 | ws.onclose = function (error) {
|
17707 | if (error instanceof Error) {
|
17708 | return reject(error);
|
17709 | }
|
17710 |
|
17711 |
|
17712 | return reject(new Error("Failed to connect [".concat(url, "]")));
|
17713 | };
|
17714 |
|
17715 | ws.onerror = ws.onclose;
|
17716 | };
|
17717 | })).then(function (ws) {
|
17718 | _this3._ws = ws;
|
17719 | _this3._ws.onclose = _this3._handleClose.bind(_this3);
|
17720 | _this3._ws.onmessage = _this3._handleMessage.bind(_this3);
|
17721 | return ws;
|
17722 | });
|
17723 | };
|
17724 |
|
17725 | _proto._destroyWs = function _destroyWs() {
|
17726 | var ws = this._ws;
|
17727 | if (!ws) return;
|
17728 | ws.onopen = null;
|
17729 | ws.onclose = null;
|
17730 | ws.onerror = null;
|
17731 | ws.onmessage = null;
|
17732 | this._ws = null;
|
17733 | ws.close();
|
17734 | }
|
17735 | ;
|
17736 |
|
17737 | _proto.onbeforeevent = function onbeforeevent(event, from, to) {
|
17738 | for (var _len2 = arguments.length, payload = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
|
17739 | payload[_key2 - 3] = arguments[_key2];
|
17740 | }
|
17741 |
|
17742 | debug$3("".concat(event, ": ").concat(from, " -> ").concat(to, " %o"), payload);
|
17743 | };
|
17744 |
|
17745 | _proto.onopen = function onopen() {
|
17746 | this.emit(OPEN$1);
|
17747 | };
|
17748 |
|
17749 | _proto.onconnected = function onconnected() {
|
17750 | this._startConnectionKeeper();
|
17751 | };
|
17752 |
|
17753 | _proto.onleaveconnected = function onleaveconnected(event, from, to) {
|
17754 | this._stopConnectionKeeper();
|
17755 |
|
17756 | this._destroyWs();
|
17757 |
|
17758 | if (to === 'offline' || to === 'disconnected') {
|
17759 | this.emit(DISCONNECT);
|
17760 | }
|
17761 | };
|
17762 |
|
17763 | _proto.onpause = function onpause() {
|
17764 | this.emit(OFFLINE);
|
17765 | };
|
17766 |
|
17767 | _proto.onbeforeresume = function onbeforeresume() {
|
17768 | this.emit(ONLINE);
|
17769 | };
|
17770 |
|
17771 | _proto.onreconnect = function onreconnect() {
|
17772 | this.emit(RECONNECT);
|
17773 | };
|
17774 |
|
17775 | _proto.ondisconnected = function ondisconnected(event, from, to) {
|
17776 | var _this4 = this;
|
17777 |
|
17778 | var attempt = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
17779 | var delay = DEFAULT_RETRY_STRATEGY.call(null, attempt);
|
17780 | debug$3("schedule attempt=".concat(attempt, " delay=").concat(delay));
|
17781 | this.emit(SCHEDULE, attempt, delay);
|
17782 |
|
17783 | if (this.__scheduledRetry) {
|
17784 | clearTimeout(this.__scheduledRetry);
|
17785 | }
|
17786 |
|
17787 | this.__scheduledRetry = setTimeout(function () {
|
17788 | if (_this4.is('disconnected')) {
|
17789 | _this4.retry(attempt);
|
17790 | }
|
17791 | }, delay);
|
17792 | };
|
17793 |
|
17794 | _proto.onretry = function onretry(event, from, to) {
|
17795 | var _this5 = this;
|
17796 |
|
17797 | var attempt = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
|
17798 | this.emit(RETRY, attempt);
|
17799 |
|
17800 | this._open().then(function () {
|
17801 | return _this5.can('reconnect') ? _this5.reconnect() : _this5._destroyWs();
|
17802 | }, function () {
|
17803 | return _this5.can('fail') && _this5.fail(attempt + 1);
|
17804 | });
|
17805 | };
|
17806 |
|
17807 | _proto.onerror = function onerror(event, from, to, error) {
|
17808 | this.emit(ERROR, error);
|
17809 | };
|
17810 |
|
17811 | _proto.onclose = function onclose() {
|
17812 | if (global$1.removeEventListener) {
|
17813 | if (this.__pause) global$1.removeEventListener('offline', this.__pause);
|
17814 | if (this.__resume) global$1.removeEventListener('online', this.__resume);
|
17815 | }
|
17816 | };
|
17817 |
|
17818 | _proto.checkConnectionAvailability = function checkConnectionAvailability() {
|
17819 | var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'API';
|
17820 |
|
17821 | if (!this.is('connected')) {
|
17822 | var currentState = this.current;
|
17823 | console.warn("".concat(name, " should not be called when the connection is ").concat(currentState));
|
17824 |
|
17825 | if (this.is('disconnected') || this.is('reconnecting')) {
|
17826 | console.warn('disconnect and reconnect event should be handled to avoid such calls.');
|
17827 | }
|
17828 |
|
17829 | throw new Error('Connection unavailable');
|
17830 | }
|
17831 | }
|
17832 | ;
|
17833 |
|
17834 | _proto.
|
17835 | _ping = function _ping() {
|
17836 | debug$3('ping');
|
17837 |
|
17838 | try {
|
17839 | this.ping();
|
17840 | } catch (error) {
|
17841 | console.warn("websocket ping error: ".concat(error.message));
|
17842 | }
|
17843 | };
|
17844 |
|
17845 | _proto.ping = function ping() {
|
17846 | if (this._ws.ping) {
|
17847 | this._ws.ping();
|
17848 | } else {
|
17849 | console.warn("The WebSocket implement does not support sending ping frame.\n Override ping method to use application defined ping/pong mechanism.");
|
17850 | }
|
17851 | };
|
17852 |
|
17853 | _proto._postponeTimeoutTimer = function _postponeTimeoutTimer() {
|
17854 | var _this6 = this;
|
17855 |
|
17856 | debug$3('_postponeTimeoutTimer');
|
17857 |
|
17858 | this._clearTimeoutTimers();
|
17859 |
|
17860 | this._timeoutTimer = setTimeout(function () {
|
17861 | debug$3('timeout');
|
17862 |
|
17863 | _this6.disconnect();
|
17864 | }, TIMEOUT_TIME);
|
17865 | };
|
17866 |
|
17867 | _proto._clearTimeoutTimers = function _clearTimeoutTimers() {
|
17868 | if (this._timeoutTimer) {
|
17869 | clearTimeout(this._timeoutTimer);
|
17870 | }
|
17871 | };
|
17872 |
|
17873 | _proto._startConnectionKeeper = function _startConnectionKeeper() {
|
17874 | debug$3('start connection keeper');
|
17875 | this._heartbeatTimer = setInterval(this._ping.bind(this), HEARTBEAT_TIME);
|
17876 | var addListener = this._ws.addListener || this._ws.addEventListener;
|
17877 |
|
17878 | if (!addListener) {
|
17879 | debug$3('connection keeper disabled due to the lack of #addEventListener.');
|
17880 | return;
|
17881 | }
|
17882 |
|
17883 | addListener.call(this._ws, 'message', this.__postponeTimeoutTimer);
|
17884 | addListener.call(this._ws, 'pong', this.__postponeTimeoutTimer);
|
17885 |
|
17886 | this._postponeTimeoutTimer();
|
17887 | };
|
17888 |
|
17889 | _proto._stopConnectionKeeper = function _stopConnectionKeeper() {
|
17890 | debug$3('stop connection keeper');
|
17891 |
|
17892 | var removeListener = this._ws.removeListener || this._ws.removeEventListener;
|
17893 |
|
17894 | if (removeListener) {
|
17895 | removeListener.call(this._ws, 'message', this.__postponeTimeoutTimer);
|
17896 | removeListener.call(this._ws, 'pong', this.__postponeTimeoutTimer);
|
17897 |
|
17898 | this._clearTimeoutTimers();
|
17899 | }
|
17900 |
|
17901 | if (this._heartbeatTimer) {
|
17902 | clearInterval(this._heartbeatTimer);
|
17903 | }
|
17904 | };
|
17905 |
|
17906 | _proto._handleClose = function _handleClose(event) {
|
17907 | debug$3("ws closed [".concat(event.code, "] ").concat(event.reason));
|
17908 |
|
17909 | if (this.isFinished()) return;
|
17910 | this.handleClose(event);
|
17911 | };
|
17912 |
|
17913 | _proto.handleClose = function handleClose() {
|
17914 |
|
17915 | this.disconnect();
|
17916 | }
|
17917 | ;
|
17918 |
|
17919 | _proto.
|
17920 | send = function send(data) {
|
17921 | debug$3('send', data);
|
17922 |
|
17923 | this._ws.send(data);
|
17924 | };
|
17925 |
|
17926 | _proto._handleMessage = function _handleMessage(event) {
|
17927 | debug$3('message', event.data);
|
17928 | this.handleMessage(event.data);
|
17929 | };
|
17930 |
|
17931 | _proto.handleMessage = function handleMessage(message) {
|
17932 | this.emit(MESSAGE, message);
|
17933 | };
|
17934 |
|
17935 | return WebSocketPlus;
|
17936 | }(eventemitter3), (_applyDecoratedDescriptor(_class.prototype, "_ping", [requireConnected], Object.getOwnPropertyDescriptor(_class.prototype, "_ping"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "send", [requireConnected], Object.getOwnPropertyDescriptor(_class.prototype, "send"), _class.prototype)), _class);
|
17937 | stateMachine.create({
|
17938 | target: WebSocketPlus.prototype,
|
17939 | initial: {
|
17940 | state: 'initialized',
|
17941 | event: 'init',
|
17942 | defer: true
|
17943 | },
|
17944 | terminal: 'closed',
|
17945 | events: [{
|
17946 | name: 'open',
|
17947 | from: 'initialized',
|
17948 | to: 'connected'
|
17949 | }, {
|
17950 | name: 'disconnect',
|
17951 | from: 'connected',
|
17952 | to: 'disconnected'
|
17953 | }, {
|
17954 | name: 'retry',
|
17955 | from: 'disconnected',
|
17956 | to: 'reconnecting'
|
17957 | }, {
|
17958 | name: 'fail',
|
17959 | from: 'reconnecting',
|
17960 | to: 'disconnected'
|
17961 | }, {
|
17962 | name: 'reconnect',
|
17963 | from: 'reconnecting',
|
17964 | to: 'connected'
|
17965 | }, {
|
17966 | name: 'pause',
|
17967 | from: ['connected', 'disconnected', 'reconnecting'],
|
17968 | to: 'offline'
|
17969 | }, {}, {
|
17970 | name: 'resume',
|
17971 | from: 'offline',
|
17972 | to: 'disconnected'
|
17973 | }, {
|
17974 | name: 'close',
|
17975 | from: ['connected', 'disconnected', 'reconnecting', 'offline'],
|
17976 | to: 'closed'
|
17977 | }, {
|
17978 | name: 'throw',
|
17979 | from: '*',
|
17980 | to: 'error'
|
17981 | }]
|
17982 | });
|
17983 |
|
17984 | var error = Object.freeze({
|
17985 | 1000: {
|
17986 | name: 'CLOSE_NORMAL'
|
17987 | },
|
17988 | 1006: {
|
17989 | name: 'CLOSE_ABNORMAL'
|
17990 | },
|
17991 | 4100: {
|
17992 | name: 'APP_NOT_AVAILABLE',
|
17993 | message: 'App not exists or realtime message service is disabled.'
|
17994 | },
|
17995 | 4102: {
|
17996 | name: 'SIGNATURE_FAILED',
|
17997 | message: 'Login signature mismatch.'
|
17998 | },
|
17999 | 4103: {
|
18000 | name: 'INVALID_LOGIN',
|
18001 | message: 'Malformed clientId.'
|
18002 | },
|
18003 | 4105: {
|
18004 | name: 'SESSION_REQUIRED',
|
18005 | message: 'Message sent before session opened.'
|
18006 | },
|
18007 | 4107: {
|
18008 | name: 'READ_TIMEOUT'
|
18009 | },
|
18010 | 4108: {
|
18011 | name: 'LOGIN_TIMEOUT'
|
18012 | },
|
18013 | 4109: {
|
18014 | name: 'FRAME_TOO_LONG'
|
18015 | },
|
18016 | 4110: {
|
18017 | name: 'INVALID_ORIGIN',
|
18018 | message: 'Access denied by domain whitelist.'
|
18019 | },
|
18020 | 4111: {
|
18021 | name: 'SESSION_CONFLICT'
|
18022 | },
|
18023 | 4112: {
|
18024 | name: 'SESSION_TOKEN_EXPIRED'
|
18025 | },
|
18026 | 4113: {
|
18027 | name: 'APP_QUOTA_EXCEEDED',
|
18028 | message: 'The daily active users limit exceeded.'
|
18029 | },
|
18030 | 4116: {
|
18031 | name: 'MESSAGE_SENT_QUOTA_EXCEEDED',
|
18032 | message: 'Command sent too fast.'
|
18033 | },
|
18034 | 4200: {
|
18035 | name: 'INTERNAL_ERROR',
|
18036 | message: 'Internal error, please contact LeanCloud for support.'
|
18037 | },
|
18038 | 4301: {
|
18039 | name: 'CONVERSATION_API_FAILED',
|
18040 | message: 'Upstream Conversatoin API failed, see error.detail for details.'
|
18041 | },
|
18042 | 4302: {
|
18043 | name: 'CONVERSATION_SIGNATURE_FAILED',
|
18044 | message: 'Conversation action signature mismatch.'
|
18045 | },
|
18046 | 4303: {
|
18047 | name: 'CONVERSATION_NOT_FOUND'
|
18048 | },
|
18049 | 4304: {
|
18050 | name: 'CONVERSATION_FULL'
|
18051 | },
|
18052 | 4305: {
|
18053 | name: 'CONVERSATION_REJECTED_BY_APP',
|
18054 | message: 'Conversation action rejected by hook.'
|
18055 | },
|
18056 | 4306: {
|
18057 | name: 'CONVERSATION_UPDATE_FAILED'
|
18058 | },
|
18059 | 4307: {
|
18060 | name: 'CONVERSATION_READ_ONLY'
|
18061 | },
|
18062 | 4308: {
|
18063 | name: 'CONVERSATION_NOT_ALLOWED'
|
18064 | },
|
18065 | 4309: {
|
18066 | name: 'CONVERSATION_UPDATE_REJECTED',
|
18067 | message: 'Conversation update rejected because the client is not a member.'
|
18068 | },
|
18069 | 4310: {
|
18070 | name: 'CONVERSATION_QUERY_FAILED',
|
18071 | message: 'Conversation query failed because it is too expansive.'
|
18072 | },
|
18073 | 4311: {
|
18074 | name: 'CONVERSATION_LOG_FAILED'
|
18075 | },
|
18076 | 4312: {
|
18077 | name: 'CONVERSATION_LOG_REJECTED',
|
18078 | message: 'Message query rejected because the client is not a member of the conversation.'
|
18079 | },
|
18080 | 4313: {
|
18081 | name: 'SYSTEM_CONVERSATION_REQUIRED'
|
18082 | },
|
18083 | 4314: {
|
18084 | name: 'NORMAL_CONVERSATION_REQUIRED'
|
18085 | },
|
18086 | 4315: {
|
18087 | name: 'CONVERSATION_BLACKLISTED',
|
18088 | message: 'Blacklisted in the conversation.'
|
18089 | },
|
18090 | 4316: {
|
18091 | name: 'TRANSIENT_CONVERSATION_REQUIRED'
|
18092 | },
|
18093 | 4317: {
|
18094 | name: 'CONVERSATION_MEMBERSHIP_REQUIRED'
|
18095 | },
|
18096 | 4318: {
|
18097 | name: 'CONVERSATION_API_QUOTA_EXCEEDED',
|
18098 | message: 'LeanCloud API quota exceeded. You may upgrade your plan.'
|
18099 | },
|
18100 | 4323: {
|
18101 | name: 'TEMPORARY_CONVERSATION_EXPIRED',
|
18102 | message: 'Temporary conversation expired or does not exist.'
|
18103 | },
|
18104 | 4401: {
|
18105 | name: 'INVALID_MESSAGING_TARGET',
|
18106 | message: 'Conversation does not exist or client is not a member.'
|
18107 | },
|
18108 | 4402: {
|
18109 | name: 'MESSAGE_REJECTED_BY_APP',
|
18110 | message: 'Message rejected by hook.'
|
18111 | },
|
18112 | 4403: {
|
18113 | name: 'MESSAGE_OWNERSHIP_REQUIRED'
|
18114 | },
|
18115 | 4404: {
|
18116 | name: 'MESSAGE_NOT_FOUND'
|
18117 | },
|
18118 | 4405: {
|
18119 | name: 'MESSAGE_UPDATE_REJECTED_BY_APP',
|
18120 | message: 'Message update rejected by hook.'
|
18121 | },
|
18122 | 4406: {
|
18123 | name: 'MESSAGE_EDIT_DISABLED'
|
18124 | },
|
18125 | 4407: {
|
18126 | name: 'MESSAGE_RECALL_DISABLED'
|
18127 | },
|
18128 | 5130: {
|
18129 | name: 'OWNER_PROMOTION_NOT_ALLOWED',
|
18130 | message: "Updating a member's role to owner is not allowed."
|
18131 | }
|
18132 | });
|
18133 | var ErrorCode = Object.freeze(Object.keys(error).reduce(function (result, code) {
|
18134 | return Object.assign(result, _defineProperty({}, error[code].name, Number(code)));
|
18135 | }, {}));
|
18136 | var createError = function createError(_ref) {
|
18137 | var code = _ref.code,
|
18138 | reason = _ref.reason,
|
18139 | appCode = _ref.appCode,
|
18140 | detail = _ref.detail,
|
18141 | errorMessage = _ref.error;
|
18142 | var message = reason || detail || errorMessage;
|
18143 | var name = reason;
|
18144 |
|
18145 | if (!message && error[code]) {
|
18146 | name = error[code].name;
|
18147 | message = error[code].message || name;
|
18148 | }
|
18149 |
|
18150 | if (!message) {
|
18151 | message = "Unknow Error: ".concat(code);
|
18152 | }
|
18153 |
|
18154 | var err = new Error(message);
|
18155 | return Object.assign(err, {
|
18156 | code: code,
|
18157 | appCode: appCode,
|
18158 | detail: detail,
|
18159 | name: name
|
18160 | });
|
18161 | };
|
18162 |
|
18163 | var debug$4 = browser('LC:Connection');
|
18164 | var COMMAND_TIMEOUT = 20000;
|
18165 | var EXPIRE = Symbol('expire');
|
18166 |
|
18167 | var Connection =
|
18168 |
|
18169 | function (_WebSocketPlus) {
|
18170 | _inheritsLoose(Connection, _WebSocketPlus);
|
18171 |
|
18172 | function Connection(getUrl, _ref) {
|
18173 | var _this;
|
18174 |
|
18175 | var format = _ref.format,
|
18176 | version = _ref.version;
|
18177 | debug$4('initializing Connection');
|
18178 | var protocolString = "lc.".concat(format, ".").concat(version);
|
18179 |
|
18180 | if (!isWeapp) {
|
18181 | _this = _WebSocketPlus.call(this, getUrl, protocolString) || this;
|
18182 | } else {
|
18183 | _this = _WebSocketPlus.call(this, getUrl().then(function (urls) {
|
18184 | return urls.map(function (url) {
|
18185 | return "".concat(url).concat(url.indexOf('?') === -1 ? '?' : '&', "subprotocol=").concat(encodeURIComponent(protocolString));
|
18186 | });
|
18187 | })) || this;
|
18188 | }
|
18189 |
|
18190 | _this._protocalFormat = format;
|
18191 | _this._commands = {};
|
18192 | _this._serialId = 0;
|
18193 | return _assertThisInitialized(_this);
|
18194 | }
|
18195 |
|
18196 | var _proto = Connection.prototype;
|
18197 |
|
18198 | _proto.send =
|
18199 |
|
18200 | function () {
|
18201 | var _send = _asyncToGenerator(
|
18202 |
|
18203 | regenerator.mark(function _callee(command) {
|
18204 | var _this2 = this;
|
18205 |
|
18206 | var waitingForRespond,
|
18207 | serialId,
|
18208 | message,
|
18209 | _args = arguments;
|
18210 | return regenerator.wrap(function _callee$(_context) {
|
18211 | while (1) {
|
18212 | switch (_context.prev = _context.next) {
|
18213 | case 0:
|
18214 | waitingForRespond = _args.length > 1 && _args[1] !== undefined ? _args[1] : true;
|
18215 |
|
18216 | if (waitingForRespond) {
|
18217 | this._serialId += 1;
|
18218 | serialId = this._serialId;
|
18219 | command.i = serialId;
|
18220 | }
|
18221 |
|
18222 | if (debug$4.enabled) debug$4('↑ %O sent', trim(command));
|
18223 |
|
18224 | if (this._protocalFormat === 'proto2base64') {
|
18225 | message = command.toBase64();
|
18226 | } else if (command.toArrayBuffer) {
|
18227 | message = command.toArrayBuffer();
|
18228 | }
|
18229 |
|
18230 | if (message) {
|
18231 | _context.next = 6;
|
18232 | break;
|
18233 | }
|
18234 |
|
18235 | throw new TypeError("".concat(command, " is not a GenericCommand"));
|
18236 |
|
18237 | case 6:
|
18238 | _WebSocketPlus.prototype.send.call(this, message);
|
18239 |
|
18240 | if (waitingForRespond) {
|
18241 | _context.next = 9;
|
18242 | break;
|
18243 | }
|
18244 |
|
18245 | return _context.abrupt("return", undefined);
|
18246 |
|
18247 | case 9:
|
18248 | return _context.abrupt("return", new Promise(function (resolve, reject) {
|
18249 | _this2._commands[serialId] = {
|
18250 | resolve: resolve,
|
18251 | reject: reject,
|
18252 | timeout: setTimeout(function () {
|
18253 | if (_this2._commands[serialId]) {
|
18254 | if (debug$4.enabled) debug$4('✗ %O timeout', trim(command));
|
18255 | reject(createError({
|
18256 | error: "Command Timeout [cmd:".concat(command.cmd, " op:").concat(command.op, "]"),
|
18257 | name: 'COMMAND_TIMEOUT'
|
18258 | }));
|
18259 | delete _this2._commands[serialId];
|
18260 | }
|
18261 | }, COMMAND_TIMEOUT)
|
18262 | };
|
18263 | }));
|
18264 |
|
18265 | case 10:
|
18266 | case "end":
|
18267 | return _context.stop();
|
18268 | }
|
18269 | }
|
18270 | }, _callee, this);
|
18271 | }));
|
18272 |
|
18273 | function send(_x) {
|
18274 | return _send.apply(this, arguments);
|
18275 | }
|
18276 |
|
18277 | return send;
|
18278 | }();
|
18279 |
|
18280 | _proto.handleMessage = function handleMessage(msg) {
|
18281 | var message;
|
18282 |
|
18283 | try {
|
18284 | message = GenericCommand.decode(msg);
|
18285 | if (debug$4.enabled) debug$4('↓ %O received', trim(message));
|
18286 | } catch (e) {
|
18287 | console.warn('Decode message failed:', e.message, msg);
|
18288 | return;
|
18289 | }
|
18290 |
|
18291 | var serialId = message.i;
|
18292 |
|
18293 | if (serialId) {
|
18294 | if (this._commands[serialId]) {
|
18295 | clearTimeout(this._commands[serialId].timeout);
|
18296 |
|
18297 | if (message.cmd === CommandType.error) {
|
18298 | this._commands[serialId].reject(createError(message.errorMessage));
|
18299 | } else {
|
18300 | this._commands[serialId].resolve(message);
|
18301 | }
|
18302 |
|
18303 | delete this._commands[serialId];
|
18304 | } else {
|
18305 | console.warn("Unexpected command received with serialId [".concat(serialId, "],\n which have timed out or never been requested."));
|
18306 | }
|
18307 | } else {
|
18308 | switch (message.cmd) {
|
18309 | case CommandType.error:
|
18310 | {
|
18311 | this.emit(ERROR, createError(message.errorMessage));
|
18312 | return;
|
18313 | }
|
18314 |
|
18315 | case CommandType.goaway:
|
18316 | {
|
18317 | this.emit(EXPIRE);
|
18318 | return;
|
18319 | }
|
18320 |
|
18321 | default:
|
18322 | {
|
18323 | this.emit(MESSAGE, message);
|
18324 | }
|
18325 | }
|
18326 | }
|
18327 | };
|
18328 |
|
18329 | _proto.ping = function ping() {
|
18330 | return this.send(new GenericCommand({
|
18331 | cmd: CommandType.echo
|
18332 | })).catch(function (error) {
|
18333 | return debug$4('ping failed:', error);
|
18334 | });
|
18335 | };
|
18336 |
|
18337 | return Connection;
|
18338 | }(WebSocketPlus);
|
18339 |
|
18340 | var applyDecorators = function applyDecorators(decorators, target) {
|
18341 | if (decorators) {
|
18342 | decorators.forEach(function (decorator) {
|
18343 | try {
|
18344 | decorator(target);
|
18345 | } catch (error) {
|
18346 | if (decorator._pluginName) {
|
18347 | error.message += "[".concat(decorator._pluginName, "]");
|
18348 | }
|
18349 |
|
18350 | throw error;
|
18351 | }
|
18352 | });
|
18353 | }
|
18354 | };
|
18355 | var applyDispatcher = function applyDispatcher(dispatchers, payload) {
|
18356 | return ensureArray(dispatchers).reduce(function (resultPromise, dispatcher) {
|
18357 | return resultPromise.then(function (shouldDispatch) {
|
18358 | return shouldDispatch === false ? false : dispatcher.apply(void 0, _toConsumableArray(payload));
|
18359 | }).catch(function (error) {
|
18360 | if (dispatcher._pluginName) {
|
18361 |
|
18362 | error.message += "[".concat(dispatcher._pluginName, "]");
|
18363 | }
|
18364 |
|
18365 | throw error;
|
18366 | });
|
18367 | }, Promise.resolve(true));
|
18368 | };
|
18369 |
|
18370 | var version = "5.0.0-beta.0";
|
18371 |
|
18372 | var debug$5 = browser('LC:Realtime');
|
18373 | var debugRequest = browser('LC:request');
|
18374 | var routerCache = new Cache('push-router');
|
18375 |
|
18376 | var Realtime =
|
18377 |
|
18378 | function (_EventEmitter) {
|
18379 | _inheritsLoose(Realtime, _EventEmitter);
|
18380 |
|
18381 | |
18382 |
|
18383 |
|
18384 |
|
18385 |
|
18386 |
|
18387 |
|
18388 |
|
18389 |
|
18390 |
|
18391 |
|
18392 |
|
18393 |
|
18394 | function Realtime(_ref) {
|
18395 | var _this2;
|
18396 |
|
18397 | var plugins = _ref.plugins,
|
18398 | options = _objectWithoutProperties(_ref, ["plugins"]);
|
18399 |
|
18400 | debug$5('initializing Realtime %s %O', version, options);
|
18401 | _this2 = _EventEmitter.call(this) || this;
|
18402 |
|
18403 | if (typeof options.appId !== 'string') {
|
18404 | throw new TypeError("appId [".concat(options.appId, "] is not a string"));
|
18405 | }
|
18406 |
|
18407 | if (typeof options.appKey !== 'string') {
|
18408 | throw new TypeError("appKey [".concat(options.appKey, "] is not a string"));
|
18409 | }
|
18410 |
|
18411 | if (isCNApp(options.appId)) {
|
18412 | if (!options.server) {
|
18413 | throw new TypeError("server option is required for apps from CN region");
|
18414 | }
|
18415 | }
|
18416 |
|
18417 | _this2._options = Object.assign({
|
18418 | appId: undefined,
|
18419 | appKey: undefined,
|
18420 | pushOfflineMessages: false,
|
18421 | noBinary: false,
|
18422 | ssl: true,
|
18423 | RTMServerName: process.env.RTM_SERVER_NAME
|
18424 |
|
18425 | }, options);
|
18426 | _this2._cache = new Cache('endpoints');
|
18427 |
|
18428 | var _this = internal(_assertThisInitialized(_this2));
|
18429 |
|
18430 | _this.clients = new Set();
|
18431 | _this.pendingClients = new Set();
|
18432 | var mergedPlugins = [].concat(_toConsumableArray(ensureArray(Realtime.__preRegisteredPlugins)), _toConsumableArray(ensureArray(plugins)));
|
18433 | debug$5('Using plugins %o', mergedPlugins.map(function (plugin) {
|
18434 | return plugin.name;
|
18435 | }));
|
18436 | _this2._plugins = mergedPlugins.reduce(function (result, plugin) {
|
18437 |
|
18438 | for (var hook in plugin) {
|
18439 | if ({}.hasOwnProperty.call(plugin, hook) && hook !== 'name') {
|
18440 | if (plugin.name) {
|
18441 | ensureArray(plugin[hook]).forEach(function (value) {
|
18442 |
|
18443 | value._pluginName = plugin.name;
|
18444 | });
|
18445 | }
|
18446 |
|
18447 |
|
18448 | result[hook] = ensureArray(result[hook]).concat(plugin[hook]);
|
18449 | }
|
18450 | }
|
18451 |
|
18452 | return result;
|
18453 | }, {});
|
18454 |
|
18455 | applyDecorators(_this2._plugins.onRealtimeCreate, _assertThisInitialized(_this2));
|
18456 | return _this2;
|
18457 | }
|
18458 |
|
18459 | var _proto = Realtime.prototype;
|
18460 |
|
18461 | _proto._request =
|
18462 |
|
18463 | function () {
|
18464 | var _request2 = _asyncToGenerator(
|
18465 |
|
18466 | regenerator.mark(function _callee(_ref2) {
|
18467 | var method, _ref2$version, version, path, query, headers, _ref2$data, data, _this$_options, appId, server, _ref3, api, url;
|
18468 |
|
18469 | return regenerator.wrap(function _callee$(_context) {
|
18470 | while (1) {
|
18471 | switch (_context.prev = _context.next) {
|
18472 | case 0:
|
18473 | method = _ref2.method, _ref2$version = _ref2.version, version = _ref2$version === void 0 ? '1.1' : _ref2$version, path = _ref2.path, query = _ref2.query, headers = _ref2.headers, _ref2$data = _ref2.data, data = _ref2$data === void 0 ? {} : _ref2$data;
|
18474 | _this$_options = this._options, appId = _this$_options.appId, server = _this$_options.server;
|
18475 | _context.next = 4;
|
18476 | return this.constructor._getServerUrls({
|
18477 | appId: appId,
|
18478 | server: server
|
18479 | });
|
18480 |
|
18481 | case 4:
|
18482 | _ref3 = _context.sent;
|
18483 | api = _ref3.api;
|
18484 | url = "".concat(api, "/").concat(version).concat(path);
|
18485 | debugRequest('Req: %O %O %O', method, url, {
|
18486 | query: query,
|
18487 | headers: headers,
|
18488 | data: data
|
18489 | });
|
18490 | return _context.abrupt("return", client(method, url).set(_objectSpread({
|
18491 | 'X-LC-Id': this._options.appId,
|
18492 | 'X-LC-Key': this._options.appKey
|
18493 | }, headers)).query(query).send(data).then(function (response) {
|
18494 | debugRequest('Res: %O %O %O', url, response.status, response.body);
|
18495 | return response.body;
|
18496 | }, function (error) {
|
18497 | debugRequest('Error: %O %O %O', url, error.response.status, error.response.body);
|
18498 |
|
18499 | if (error.response && error.response.body && error.response.body.code) {
|
18500 | throw createError(error.response.body);
|
18501 | }
|
18502 |
|
18503 | throw error;
|
18504 | }));
|
18505 |
|
18506 | case 9:
|
18507 | case "end":
|
18508 | return _context.stop();
|
18509 | }
|
18510 | }
|
18511 | }, _callee, this);
|
18512 | }));
|
18513 |
|
18514 | function _request(_x) {
|
18515 | return _request2.apply(this, arguments);
|
18516 | }
|
18517 |
|
18518 | return _request;
|
18519 | }();
|
18520 |
|
18521 | _proto._open = function _open() {
|
18522 | var _this3 = this;
|
18523 |
|
18524 | if (this._openPromise) return this._openPromise;
|
18525 | var format = 'protobuf2';
|
18526 |
|
18527 | if (this._options.noBinary) {
|
18528 |
|
18529 | format = 'proto2base64';
|
18530 | }
|
18531 |
|
18532 | var version = 3;
|
18533 |
|
18534 | if (this._options.pushOfflineMessages) {
|
18535 |
|
18536 | version = 1;
|
18537 | }
|
18538 |
|
18539 | var protocol = {
|
18540 | format: format,
|
18541 | version: version
|
18542 | };
|
18543 | this._openPromise = new Promise(function (resolve, reject) {
|
18544 | debug$5('No connection established, create a new one.');
|
18545 | var connection = new Connection(function () {
|
18546 | return _this3._getRTMServers(_this3._options);
|
18547 | }, protocol);
|
18548 | connection.on(OPEN$1, function () {
|
18549 | return resolve(connection);
|
18550 | }).on(ERROR, reject).on(EXPIRE,
|
18551 |
|
18552 | _asyncToGenerator(
|
18553 |
|
18554 | regenerator.mark(function _callee2() {
|
18555 | return regenerator.wrap(function _callee2$(_context2) {
|
18556 | while (1) {
|
18557 | switch (_context2.prev = _context2.next) {
|
18558 | case 0:
|
18559 | debug$5('Connection expired. Refresh endpoints.');
|
18560 |
|
18561 | _this3._cache.set('endpoints', null, 0);
|
18562 |
|
18563 | _context2.next = 4;
|
18564 | return _this3._getRTMServers(_this3._options);
|
18565 |
|
18566 | case 4:
|
18567 | connection.urls = _context2.sent;
|
18568 | connection.disconnect();
|
18569 |
|
18570 | case 6:
|
18571 | case "end":
|
18572 | return _context2.stop();
|
18573 | }
|
18574 | }
|
18575 | }, _callee2, this);
|
18576 | }))).on(MESSAGE, _this3._dispatchCommand.bind(_this3));
|
18577 | |
18578 |
|
18579 |
|
18580 |
|
18581 |
|
18582 |
|
18583 |
|
18584 | |
18585 |
|
18586 |
|
18587 |
|
18588 |
|
18589 |
|
18590 |
|
18591 | |
18592 |
|
18593 |
|
18594 |
|
18595 |
|
18596 |
|
18597 | |
18598 |
|
18599 |
|
18600 |
|
18601 |
|
18602 |
|
18603 | |
18604 |
|
18605 |
|
18606 |
|
18607 |
|
18608 |
|
18609 |
|
18610 | |
18611 |
|
18612 |
|
18613 |
|
18614 |
|
18615 |
|
18616 |
|
18617 |
|
18618 | |
18619 |
|
18620 |
|
18621 |
|
18622 |
|
18623 |
|
18624 |
|
18625 | |
18626 |
|
18627 |
|
18628 |
|
18629 |
|
18630 |
|
18631 |
|
18632 | |
18633 |
|
18634 |
|
18635 |
|
18636 |
|
18637 |
|
18638 |
|
18639 | |
18640 |
|
18641 |
|
18642 |
|
18643 |
|
18644 |
|
18645 |
|
18646 | |
18647 |
|
18648 |
|
18649 |
|
18650 |
|
18651 |
|
18652 |
|
18653 |
|
18654 | [DISCONNECT, RECONNECT, RETRY, SCHEDULE, OFFLINE, ONLINE].forEach(function (event) {
|
18655 | return connection.on(event, function () {
|
18656 | for (var _len = arguments.length, payload = new Array(_len), _key = 0; _key < _len; _key++) {
|
18657 | payload[_key] = arguments[_key];
|
18658 | }
|
18659 |
|
18660 | debug$5("".concat(event, " event emitted. %o"), payload);
|
18661 |
|
18662 | _this3.emit.apply(_this3, [event].concat(payload));
|
18663 |
|
18664 | if (event !== RECONNECT) {
|
18665 | internal(_this3).clients.forEach(function (client) {
|
18666 | client.emit.apply(client, [event].concat(payload));
|
18667 | });
|
18668 | }
|
18669 | });
|
18670 | });
|
18671 |
|
18672 | connection.handleClose = function handleClose(event) {
|
18673 | var isFatal = [ErrorCode.APP_NOT_AVAILABLE, ErrorCode.INVALID_LOGIN, ErrorCode.INVALID_ORIGIN].some(function (errorCode) {
|
18674 | return errorCode === event.code;
|
18675 | });
|
18676 |
|
18677 | if (isFatal) {
|
18678 |
|
18679 | this.throw(createError(event));
|
18680 | } else {
|
18681 |
|
18682 | this.disconnect();
|
18683 | }
|
18684 | };
|
18685 |
|
18686 | internal(_this3).connection = connection;
|
18687 | });
|
18688 | return this._openPromise;
|
18689 | };
|
18690 |
|
18691 | _proto._getRTMServers =
|
18692 |
|
18693 | function () {
|
18694 | var _getRTMServers2 = _asyncToGenerator(
|
18695 |
|
18696 | regenerator.mark(function _callee3(options) {
|
18697 | var info, cachedEndPoints;
|
18698 | return regenerator.wrap(function _callee3$(_context3) {
|
18699 | while (1) {
|
18700 | switch (_context3.prev = _context3.next) {
|
18701 | case 0:
|
18702 | if (!options.RTMServers) {
|
18703 | _context3.next = 2;
|
18704 | break;
|
18705 | }
|
18706 |
|
18707 | return _context3.abrupt("return", shuffle_1(ensureArray(options.RTMServers)));
|
18708 |
|
18709 | case 2:
|
18710 | cachedEndPoints = this._cache.get('endpoints');
|
18711 |
|
18712 | if (!cachedEndPoints) {
|
18713 | _context3.next = 9;
|
18714 | break;
|
18715 | }
|
18716 |
|
18717 | _context3.next = 6;
|
18718 | return cachedEndPoints;
|
18719 |
|
18720 | case 6:
|
18721 | info = _context3.sent;
|
18722 | _context3.next = 13;
|
18723 | break;
|
18724 |
|
18725 | case 9:
|
18726 | _context3.next = 11;
|
18727 | return this.constructor._fetchRTMServers(options);
|
18728 |
|
18729 | case 11:
|
18730 | info = _context3.sent;
|
18731 |
|
18732 | this._cache.set('endpoints', info, info.ttl * 1000);
|
18733 |
|
18734 | case 13:
|
18735 | debug$5('endpoint info: %O', info);
|
18736 | return _context3.abrupt("return", [info.server, info.secondary]);
|
18737 |
|
18738 | case 15:
|
18739 | case "end":
|
18740 | return _context3.stop();
|
18741 | }
|
18742 | }
|
18743 | }, _callee3, this);
|
18744 | }));
|
18745 |
|
18746 | function _getRTMServers(_x2) {
|
18747 | return _getRTMServers2.apply(this, arguments);
|
18748 | }
|
18749 |
|
18750 | return _getRTMServers;
|
18751 | }();
|
18752 |
|
18753 | Realtime._getServerUrls =
|
18754 |
|
18755 | function () {
|
18756 | var _getServerUrls2 = _asyncToGenerator(
|
18757 |
|
18758 | regenerator.mark(function _callee4(_ref5) {
|
18759 | var appId, server, cachedRouter, defaultProtocol;
|
18760 | return regenerator.wrap(function _callee4$(_context4) {
|
18761 | while (1) {
|
18762 | switch (_context4.prev = _context4.next) {
|
18763 | case 0:
|
18764 | appId = _ref5.appId, server = _ref5.server;
|
18765 | debug$5('fetch server urls');
|
18766 |
|
18767 | if (!server) {
|
18768 | _context4.next = 6;
|
18769 | break;
|
18770 | }
|
18771 |
|
18772 | if (!(typeof server !== 'string')) {
|
18773 | _context4.next = 5;
|
18774 | break;
|
18775 | }
|
18776 |
|
18777 | return _context4.abrupt("return", server);
|
18778 |
|
18779 | case 5:
|
18780 | return _context4.abrupt("return", {
|
18781 | RTMRouter: server,
|
18782 | api: server
|
18783 | });
|
18784 |
|
18785 | case 6:
|
18786 | cachedRouter = routerCache.get(appId);
|
18787 |
|
18788 | if (!cachedRouter) {
|
18789 | _context4.next = 9;
|
18790 | break;
|
18791 | }
|
18792 |
|
18793 | return _context4.abrupt("return", cachedRouter);
|
18794 |
|
18795 | case 9:
|
18796 | defaultProtocol = 'https://';
|
18797 | return _context4.abrupt("return", client.get('https://app-router.com/2/route').query({
|
18798 | appId: appId
|
18799 | }).timeout(20000).then(function (res) {
|
18800 | return res.body;
|
18801 | }).then(tap(debug$5)).then(function (_ref6) {
|
18802 | var RTMRouterServer = _ref6.rtm_router_server,
|
18803 | APIServer = _ref6.api_server,
|
18804 | _ref6$ttl = _ref6.ttl,
|
18805 | ttl = _ref6$ttl === void 0 ? 3600 : _ref6$ttl;
|
18806 |
|
18807 | if (!RTMRouterServer) {
|
18808 | throw new Error('rtm router not exists');
|
18809 | }
|
18810 |
|
18811 | var serverUrls = {
|
18812 | RTMRouter: "".concat(defaultProtocol).concat(RTMRouterServer),
|
18813 | api: "".concat(defaultProtocol).concat(APIServer)
|
18814 | };
|
18815 | routerCache.set(appId, serverUrls, ttl * 1000);
|
18816 | return serverUrls;
|
18817 | }).catch(function () {
|
18818 | var id = appId.slice(0, 8).toLowerCase();
|
18819 | var domain = 'lncldglobal.com';
|
18820 | return {
|
18821 | RTMRouter: "".concat(defaultProtocol).concat(id, ".rtm.").concat(domain),
|
18822 | api: "".concat(defaultProtocol).concat(id, ".api.").concat(domain)
|
18823 | };
|
18824 | }));
|
18825 |
|
18826 | case 11:
|
18827 | case "end":
|
18828 | return _context4.stop();
|
18829 | }
|
18830 | }
|
18831 | }, _callee4, this);
|
18832 | }));
|
18833 |
|
18834 | function _getServerUrls(_x3) {
|
18835 | return _getServerUrls2.apply(this, arguments);
|
18836 | }
|
18837 |
|
18838 | return _getServerUrls;
|
18839 | }();
|
18840 |
|
18841 | Realtime._fetchRTMServers = function _fetchRTMServers(_ref7) {
|
18842 | var appId = _ref7.appId,
|
18843 | ssl = _ref7.ssl,
|
18844 | server = _ref7.server,
|
18845 | RTMServerName = _ref7.RTMServerName;
|
18846 | debug$5('fetch endpoint info');
|
18847 | return this._getServerUrls({
|
18848 | appId: appId,
|
18849 | server: server
|
18850 | }).then(tap(debug$5)).then(function (_ref8) {
|
18851 | var RTMRouter = _ref8.RTMRouter;
|
18852 | return client.get("".concat(RTMRouter, "/v1/route")).query({
|
18853 | appId: appId,
|
18854 | secure: ssl,
|
18855 | features: isWeapp ? 'wechat' : undefined,
|
18856 | server: RTMServerName,
|
18857 | _t: Date.now()
|
18858 | }).timeout(20000).then(function (res) {
|
18859 | return res.body;
|
18860 | }).then(tap(debug$5));
|
18861 | });
|
18862 | };
|
18863 |
|
18864 | _proto._close = function _close() {
|
18865 | if (this._openPromise) {
|
18866 | this._openPromise.then(function (connection) {
|
18867 | return connection.close();
|
18868 | });
|
18869 | }
|
18870 |
|
18871 | delete this._openPromise;
|
18872 | }
|
18873 | |
18874 |
|
18875 |
|
18876 |
|
18877 |
|
18878 | ;
|
18879 |
|
18880 | _proto.retry = function retry() {
|
18881 | var _internal = internal(this),
|
18882 | connection = _internal.connection;
|
18883 |
|
18884 | if (!connection) {
|
18885 | throw new Error('no connection established');
|
18886 | }
|
18887 |
|
18888 | if (connection.cannot('retry')) {
|
18889 | throw new Error("retrying not allowed when not disconnected. the connection is now ".concat(connection.current));
|
18890 | }
|
18891 |
|
18892 | return connection.retry();
|
18893 | }
|
18894 | |
18895 |
|
18896 |
|
18897 |
|
18898 |
|
18899 |
|
18900 |
|
18901 |
|
18902 | ;
|
18903 |
|
18904 | _proto.pause = function pause() {
|
18905 |
|
18906 |
|
18907 | var _internal2 = internal(this),
|
18908 | connection = _internal2.connection;
|
18909 |
|
18910 | if (!connection) return;
|
18911 | if (connection.can('pause')) connection.pause();
|
18912 | }
|
18913 | |
18914 |
|
18915 |
|
18916 |
|
18917 |
|
18918 |
|
18919 |
|
18920 | ;
|
18921 |
|
18922 | _proto.resume = function resume() {
|
18923 |
|
18924 | var _internal3 = internal(this),
|
18925 | connection = _internal3.connection;
|
18926 |
|
18927 | if (!connection) return;
|
18928 | if (connection.can('resume')) connection.resume();
|
18929 | };
|
18930 |
|
18931 | _proto._registerPending = function _registerPending(value) {
|
18932 | internal(this).pendingClients.add(value);
|
18933 | };
|
18934 |
|
18935 | _proto._deregisterPending = function _deregisterPending(client) {
|
18936 | internal(this).pendingClients.delete(client);
|
18937 | };
|
18938 |
|
18939 | _proto._register = function _register(client) {
|
18940 | internal(this).clients.add(client);
|
18941 | };
|
18942 |
|
18943 | _proto._deregister = function _deregister(client) {
|
18944 | var _this = internal(this);
|
18945 |
|
18946 | _this.clients.delete(client);
|
18947 |
|
18948 | if (_this.clients.size + _this.pendingClients.size === 0) {
|
18949 | this._close();
|
18950 | }
|
18951 | };
|
18952 |
|
18953 | _proto._dispatchCommand = function _dispatchCommand(command) {
|
18954 | return applyDispatcher(this._plugins.beforeCommandDispatch, [command, this]).then(function (shouldDispatch) {
|
18955 |
|
18956 | if (shouldDispatch) return debug$5('[WARN] Unexpected message received: %O', trim(command));
|
18957 | return false;
|
18958 | });
|
18959 | };
|
18960 |
|
18961 | return Realtime;
|
18962 | }(eventemitter3);
|
18963 |
|
18964 | var polyfilledPromise = Promise;
|
18965 |
|
18966 | exports.Protocals = message;
|
18967 | exports.Promise = polyfilledPromise;
|
18968 | exports.EventEmitter = eventemitter3;
|
18969 | exports.Realtime = Realtime;
|
18970 | exports.debug = debug$2;
|
18971 |
|
18972 | Object.defineProperty(exports, '__esModule', { value: true });
|
18973 |
|
18974 | }));
|
18975 |
|