oicq-icalingua-plus-plus 1.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +373 -0
- package/README.md +73 -0
- package/bin/oicq +2 -0
- package/http-api/README.md +187 -0
- package/http-api/api.js +217 -0
- package/http-api/config.sample.js +44 -0
- package/http-api/core.js +480 -0
- package/http-api/cq-notice.js +39 -0
- package/http-api/filter.js +128 -0
- package/http-api/index.js +39 -0
- package/index.d.ts +1214 -0
- package/index.js +34 -0
- package/lib/algo/jce/index.js +63 -0
- package/lib/algo/jce/jce.js +341 -0
- package/lib/algo/pb.js +159 -0
- package/lib/algo/protobuf.min.js +8 -0
- package/lib/algo/tea.js +121 -0
- package/lib/client-ext.js +312 -0
- package/lib/client-net.js +147 -0
- package/lib/client.js +594 -0
- package/lib/common.js +252 -0
- package/lib/core/friendlist.js +415 -0
- package/lib/core/nessy.js +148 -0
- package/lib/core/ref.d.ts +1 -0
- package/lib/core/sysmsg.js +388 -0
- package/lib/core/troop.js +586 -0
- package/lib/device.js +181 -0
- package/lib/exception.js +57 -0
- package/lib/message/builder.js +1093 -0
- package/lib/message/chat.js +276 -0
- package/lib/message/face.js +293 -0
- package/lib/message/file.js +425 -0
- package/lib/message/history.js +73 -0
- package/lib/message/image.js +533 -0
- package/lib/message/multi.js +242 -0
- package/lib/message/music.js +172 -0
- package/lib/message/parser.js +774 -0
- package/lib/message/ptt.js +389 -0
- package/lib/oicq.js +427 -0
- package/lib/onlinepush.js +616 -0
- package/lib/ref.d.ts +177 -0
- package/lib/service.js +204 -0
- package/lib/wtlogin/ecdh.js +15 -0
- package/lib/wtlogin/login-password.js +215 -0
- package/lib/wtlogin/login-qrcode.js +249 -0
- package/lib/wtlogin/tlv.js +331 -0
- package/lib/wtlogin/writer.js +88 -0
- package/lib/wtlogin/wt.js +422 -0
- package/package.json +50 -0
- package/util.js +115 -0
package/index.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { Client } = require("./lib/oicq");
|
|
3
|
+
const { segment, cqcode } = require("./util");
|
|
4
|
+
const { checkUin, NOOP } = require("./lib/common");
|
|
5
|
+
|
|
6
|
+
const constants = {
|
|
7
|
+
PLATFORM_ANDROID: 1,
|
|
8
|
+
PLATFORM_APAD: 2,
|
|
9
|
+
PLATFORM_WATCH: 3,
|
|
10
|
+
PLATFORM_IMAC: 4,
|
|
11
|
+
PLATFORM_IPAD: 5,
|
|
12
|
+
STATUS_ONLINE: 11,
|
|
13
|
+
STATUS_ABSENT: 31,
|
|
14
|
+
STATUS_INVISIBLE: 41,
|
|
15
|
+
STATUS_BUSY: 50,
|
|
16
|
+
STATUS_QME: 60,
|
|
17
|
+
STATUS_NODISTURB: 70,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = {
|
|
21
|
+
Client, createClient,
|
|
22
|
+
segment, cqcode,
|
|
23
|
+
/** @deprecated */
|
|
24
|
+
setGlobalConfig: NOOP,
|
|
25
|
+
constants,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const ERROR_UIN = new Error("Argument uin is not an OICQ account.");
|
|
29
|
+
function createClient(uin, config) {
|
|
30
|
+
uin = parseInt(uin);
|
|
31
|
+
if (!checkUin(uin))
|
|
32
|
+
throw ERROR_UIN;
|
|
33
|
+
return new Client(uin, config);
|
|
34
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* jce组包解包
|
|
3
|
+
*/
|
|
4
|
+
"use strict";
|
|
5
|
+
const jce = require("./jce");
|
|
6
|
+
const WRAPPER = {
|
|
7
|
+
version: 1,
|
|
8
|
+
pkt_type: 2,
|
|
9
|
+
msg_type: 3,
|
|
10
|
+
req_id: 4,
|
|
11
|
+
service: 5,
|
|
12
|
+
method: 6,
|
|
13
|
+
payload: 7,
|
|
14
|
+
timeout: 8,
|
|
15
|
+
context: 9,
|
|
16
|
+
status: 10,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {Buffer} blob
|
|
21
|
+
*/
|
|
22
|
+
function decode(blob) {
|
|
23
|
+
const wrapper = jce.decode(blob);
|
|
24
|
+
const map = jce.decode(wrapper[7])[0];
|
|
25
|
+
let nested = map[Object.keys(map)[0]];
|
|
26
|
+
if (nested instanceof Buffer === false)
|
|
27
|
+
nested = nested[Object.keys(nested)[0]];
|
|
28
|
+
return jce.decode(nested)[0];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {object} map
|
|
33
|
+
* @param {typeof WRAPPER} extra
|
|
34
|
+
*/
|
|
35
|
+
function encodeWrapper(map, extra) {
|
|
36
|
+
const body = {
|
|
37
|
+
version: 3,
|
|
38
|
+
pkt_type: 0,
|
|
39
|
+
msg_type: 0,
|
|
40
|
+
req_id: 0,
|
|
41
|
+
service: "",
|
|
42
|
+
method: "",
|
|
43
|
+
payload: jce.encode([map]),
|
|
44
|
+
timeout: 0,
|
|
45
|
+
context: {},
|
|
46
|
+
status: {},
|
|
47
|
+
...extra
|
|
48
|
+
};
|
|
49
|
+
return jce.encode(body, WRAPPER);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {object|Array} nested
|
|
54
|
+
* @param {object|undefined} struct
|
|
55
|
+
*/
|
|
56
|
+
function encodeStruct(nested, struct) {
|
|
57
|
+
return jce.encode([jce.encodeNested(nested, struct)]);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = {
|
|
61
|
+
decode, decodeNested: jce.decode,
|
|
62
|
+
encode: jce.encode, encodeWrapper, encodeStruct, encodeNested: jce.encodeNested,
|
|
63
|
+
};
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const Readable = require("stream").Readable;
|
|
3
|
+
class JceError extends Error { }
|
|
4
|
+
const BUF0 = Buffer.alloc(0);
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @typedef {{[k: string]: number}} JceStruct jce data struct
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const TYPE_INT8 = 0;
|
|
11
|
+
const TYPE_INT16 = 1;
|
|
12
|
+
const TYPE_INT32 = 2;
|
|
13
|
+
const TYPE_INT64 = 3;
|
|
14
|
+
const TYPE_FLOAT = 4;
|
|
15
|
+
const TYPE_DOUBLE = 5;
|
|
16
|
+
const TYPE_STRING1 = 6;
|
|
17
|
+
const TYPE_STRING4 = 7;
|
|
18
|
+
const TYPE_MAP = 8;
|
|
19
|
+
const TYPE_LIST = 9;
|
|
20
|
+
const TYPE_STRUCT_BEGIN = 10;
|
|
21
|
+
const TYPE_STRUCT_END = 11;
|
|
22
|
+
const TYPE_ZERO = 12;
|
|
23
|
+
const TYPE_SIMPLE_LIST = 13;
|
|
24
|
+
|
|
25
|
+
const TAG_MAP_K = 0;
|
|
26
|
+
const TAG_MAP_V = 1;
|
|
27
|
+
const TAG_LIST_E = 0;
|
|
28
|
+
const TAG_BYTES = 0;
|
|
29
|
+
const TAG_LENGTH = 0;
|
|
30
|
+
const TAG_STRUCT_END = 0;
|
|
31
|
+
|
|
32
|
+
const FLAG_STRUCT_END = Symbol("FLAG_STRUCT_END");
|
|
33
|
+
|
|
34
|
+
let _encoding = "utf8";
|
|
35
|
+
|
|
36
|
+
class Struct extends null { }
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {Readable} stream
|
|
40
|
+
*/
|
|
41
|
+
function readHead(stream) {
|
|
42
|
+
const head = stream.read(1).readUInt8();
|
|
43
|
+
const type = head & 0xf;
|
|
44
|
+
let tag = (head & 0xf0) >> 4;
|
|
45
|
+
if (tag === 0xf) {
|
|
46
|
+
tag = stream.read(1).readUInt8();
|
|
47
|
+
}
|
|
48
|
+
return {tag, type};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @param {Readable} stream
|
|
53
|
+
* @param {number} type UInt8 0~13
|
|
54
|
+
*/
|
|
55
|
+
function readBody(stream, type) {
|
|
56
|
+
let len;
|
|
57
|
+
switch(type) {
|
|
58
|
+
case TYPE_ZERO:
|
|
59
|
+
return 0;
|
|
60
|
+
case TYPE_INT8:
|
|
61
|
+
return stream.read(1).readInt8();
|
|
62
|
+
case TYPE_INT16:
|
|
63
|
+
return stream.read(2).readInt16BE();
|
|
64
|
+
case TYPE_INT32:
|
|
65
|
+
return stream.read(4).readInt32BE();
|
|
66
|
+
case TYPE_INT64:
|
|
67
|
+
let value = stream.read(8).readBigInt64BE();
|
|
68
|
+
if (value >= Number.MIN_SAFE_INTEGER && value <= Number.MAX_SAFE_INTEGER)
|
|
69
|
+
value = Number(value);
|
|
70
|
+
return value;
|
|
71
|
+
case TYPE_STRING1:
|
|
72
|
+
len = stream.read(1).readUInt8();
|
|
73
|
+
return len > 0 ? stream.read(len).toString(_encoding) : "";
|
|
74
|
+
case TYPE_STRING4:
|
|
75
|
+
len = stream.read(4).readUInt32BE();
|
|
76
|
+
return len > 0 ? stream.read(len).toString(_encoding) : "";
|
|
77
|
+
case TYPE_SIMPLE_LIST:
|
|
78
|
+
readHead(stream);
|
|
79
|
+
len = readElement(stream).value;
|
|
80
|
+
return len > 0 ? stream.read(len) : BUF0;
|
|
81
|
+
case TYPE_LIST:
|
|
82
|
+
len = readElement(stream).value;
|
|
83
|
+
const list = [];
|
|
84
|
+
while(len > 0) {
|
|
85
|
+
list.push(readElement(stream).value);
|
|
86
|
+
--len;
|
|
87
|
+
}
|
|
88
|
+
return list;
|
|
89
|
+
case TYPE_MAP:
|
|
90
|
+
len = readElement(stream).value;
|
|
91
|
+
const map = Object.create(null);
|
|
92
|
+
while(len > 0) {
|
|
93
|
+
map[readElement(stream).value] = readElement(stream).value;
|
|
94
|
+
--len;
|
|
95
|
+
}
|
|
96
|
+
return map;
|
|
97
|
+
case TYPE_STRUCT_BEGIN:
|
|
98
|
+
return readStruct(stream);
|
|
99
|
+
case TYPE_STRUCT_END:
|
|
100
|
+
return FLAG_STRUCT_END;
|
|
101
|
+
case TYPE_FLOAT:
|
|
102
|
+
return stream.read(4).readFloatBE();
|
|
103
|
+
case TYPE_DOUBLE:
|
|
104
|
+
return stream.read(8).readDoubleBE();
|
|
105
|
+
default:
|
|
106
|
+
throw new JceError("unknown jce type: " + type);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* @param {Readable} stream
|
|
112
|
+
*/
|
|
113
|
+
function readStruct(stream) {
|
|
114
|
+
const struct = Object.create(Struct.prototype);
|
|
115
|
+
while(stream.readableLength) {
|
|
116
|
+
const {tag, value} = readElement(stream);
|
|
117
|
+
if (value === FLAG_STRUCT_END) {
|
|
118
|
+
return struct;
|
|
119
|
+
} else {
|
|
120
|
+
struct[tag] = value;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @param {Readable} stream
|
|
127
|
+
*/
|
|
128
|
+
function readElement(stream) {
|
|
129
|
+
const head = readHead(stream);
|
|
130
|
+
const value = readBody(stream, head.type);
|
|
131
|
+
return {
|
|
132
|
+
tag: head.tag, value
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//------------------------------------------------------------------
|
|
137
|
+
|
|
138
|
+
class Nested {
|
|
139
|
+
constructor(data) {
|
|
140
|
+
this.data = data;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @param {Number} type UInt8 0~13
|
|
146
|
+
* @param {Number} tag UInt8
|
|
147
|
+
* @returns {Buffer}
|
|
148
|
+
*/
|
|
149
|
+
function createHead(type, tag) {
|
|
150
|
+
if (tag < 15) {
|
|
151
|
+
return Buffer.from([(tag<<4)|type]);
|
|
152
|
+
} else if (tag < 256) {
|
|
153
|
+
return Buffer.from([0xf0|type, tag]);
|
|
154
|
+
} else {
|
|
155
|
+
throw new JceError("Tag must be less than 256");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @param {Number} type UInt8 0~13
|
|
161
|
+
* @param {Number|BigInt|String|Buffer|Array|Object} value
|
|
162
|
+
* @returns {Buffer}
|
|
163
|
+
*/
|
|
164
|
+
function createBody(type, value) {
|
|
165
|
+
var body, len;
|
|
166
|
+
switch (type) {
|
|
167
|
+
case TYPE_INT8:
|
|
168
|
+
return Buffer.from([parseInt(value)]);
|
|
169
|
+
case TYPE_INT16:
|
|
170
|
+
body = Buffer.allocUnsafe(2);
|
|
171
|
+
body.writeInt16BE(parseInt(value));
|
|
172
|
+
return body;
|
|
173
|
+
case TYPE_INT32:
|
|
174
|
+
body = Buffer.allocUnsafe(4);
|
|
175
|
+
body.writeInt32BE(parseInt(value));
|
|
176
|
+
return body;
|
|
177
|
+
case TYPE_INT64:
|
|
178
|
+
body = Buffer.allocUnsafe(8);
|
|
179
|
+
body.writeBigInt64BE(BigInt(value));
|
|
180
|
+
return body;
|
|
181
|
+
case TYPE_FLOAT:
|
|
182
|
+
body = Buffer.allocUnsafe(4);
|
|
183
|
+
body.writeFloatBE(value);
|
|
184
|
+
return body;
|
|
185
|
+
case TYPE_DOUBLE:
|
|
186
|
+
body = Buffer.allocUnsafe(8);
|
|
187
|
+
body.writeDoubleBE(value);
|
|
188
|
+
return body;
|
|
189
|
+
case TYPE_STRING1:
|
|
190
|
+
len = Buffer.from([value.length]);
|
|
191
|
+
return Buffer.concat([len, value]);
|
|
192
|
+
case TYPE_STRING4:
|
|
193
|
+
len = Buffer.allocUnsafe(4);
|
|
194
|
+
len.writeUInt32BE(value.length);
|
|
195
|
+
return Buffer.concat([len, value]);
|
|
196
|
+
case TYPE_MAP:
|
|
197
|
+
body = [];
|
|
198
|
+
let n = 0;
|
|
199
|
+
for (let k of Object.keys(value)) {
|
|
200
|
+
++n;
|
|
201
|
+
body.push(createElement(TAG_MAP_K, k));
|
|
202
|
+
body.push(createElement(TAG_MAP_V, value[k]));
|
|
203
|
+
}
|
|
204
|
+
body.unshift(createElement(TAG_LENGTH, n));
|
|
205
|
+
return Buffer.concat(body);
|
|
206
|
+
case TYPE_LIST:
|
|
207
|
+
body = [createElement(TAG_LENGTH, value.length)];
|
|
208
|
+
for (let i = 0; i < value.length; ++i) {
|
|
209
|
+
body.push(createElement(TAG_LIST_E, value[i]));
|
|
210
|
+
}
|
|
211
|
+
return Buffer.concat(body);
|
|
212
|
+
// case TYPE_STRUCT_BEGIN:
|
|
213
|
+
// case TYPE_STRUCT_END:
|
|
214
|
+
case TYPE_ZERO:
|
|
215
|
+
return BUF0;
|
|
216
|
+
case TYPE_SIMPLE_LIST:
|
|
217
|
+
return Buffer.concat([createHead(0, TAG_BYTES), createElement(TAG_LENGTH, value.length), value]);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* @param {Number} tag UInt8
|
|
223
|
+
* @param {Number|BigInt|String|Buffer|Array|Object|Nested} value
|
|
224
|
+
* @returns {Buffer}
|
|
225
|
+
*/
|
|
226
|
+
function createElement(tag, value) {
|
|
227
|
+
if (value instanceof Nested) {
|
|
228
|
+
const begin = createHead(TYPE_STRUCT_BEGIN, tag);
|
|
229
|
+
const end = createHead(TYPE_STRUCT_END, TAG_STRUCT_END);
|
|
230
|
+
return Buffer.concat([begin, value.data, end]);
|
|
231
|
+
}
|
|
232
|
+
let type = typeof value;
|
|
233
|
+
switch (type) {
|
|
234
|
+
case "string":
|
|
235
|
+
value = Buffer.from(value, _encoding);
|
|
236
|
+
type = value.length <= 0xff ? TYPE_STRING1 : TYPE_STRING4;
|
|
237
|
+
break;
|
|
238
|
+
case "object":
|
|
239
|
+
if (value === null)
|
|
240
|
+
throw new JceError("Unsupported type: null");
|
|
241
|
+
if (value instanceof Uint8Array)
|
|
242
|
+
type = TYPE_SIMPLE_LIST;
|
|
243
|
+
else
|
|
244
|
+
type = Array.isArray(value) ? TYPE_LIST : TYPE_MAP;
|
|
245
|
+
break;
|
|
246
|
+
case "bigint":
|
|
247
|
+
case "number":
|
|
248
|
+
if (value == 0)
|
|
249
|
+
type = TYPE_ZERO;
|
|
250
|
+
else if (Number.isInteger(value) || type === "bigint") {
|
|
251
|
+
if (value >= -0x80 && value <= 0x7f)
|
|
252
|
+
type = TYPE_INT8;
|
|
253
|
+
else if (value >= -0x8000 && value <= 0x7fff)
|
|
254
|
+
type = TYPE_INT16;
|
|
255
|
+
else if (value >= -0x80000000 && value <= 0x7fffffff)
|
|
256
|
+
type = TYPE_INT32;
|
|
257
|
+
else if (value >= -0x8000000000000000n && value <= 0x7fffffffffffffffn)
|
|
258
|
+
type = TYPE_INT64;
|
|
259
|
+
else
|
|
260
|
+
throw new JceError("Unsupported integer range: " + value);
|
|
261
|
+
} else {
|
|
262
|
+
type = TYPE_DOUBLE; //we don't use float
|
|
263
|
+
}
|
|
264
|
+
break;
|
|
265
|
+
default:
|
|
266
|
+
throw new JceError("Unsupported type: " + type);
|
|
267
|
+
}
|
|
268
|
+
const head = createHead(type, tag);
|
|
269
|
+
const body = createBody(type, value);
|
|
270
|
+
return Buffer.concat([head, body]);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
//--------------------------------------------------------------------
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* 设置字符串编码
|
|
277
|
+
* @param {BufferEncoding} encoding
|
|
278
|
+
*/
|
|
279
|
+
function setEncoding(encoding = "utf8") {
|
|
280
|
+
_encoding = encoding;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* 调用此函数进行jce解码
|
|
285
|
+
* @param {Buffer} blob
|
|
286
|
+
* @returns {{[k: number]: any}}
|
|
287
|
+
*/
|
|
288
|
+
function decode(blob) {
|
|
289
|
+
const stream = Readable.from(blob, {objectMode: false});
|
|
290
|
+
stream.read(0);
|
|
291
|
+
const result = Object.create(null);
|
|
292
|
+
while(stream.readableLength) {
|
|
293
|
+
const {tag, value} = readElement(stream);
|
|
294
|
+
result[tag] = value;
|
|
295
|
+
}
|
|
296
|
+
return result;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* 调用此函数进行jce编码
|
|
301
|
+
* @param {{[k: number]: any}|any[]} object 键值对或数组(值为null或undefined自动跳过此tag)
|
|
302
|
+
* @param {JceStruct} struct undefined时取object的键为tag
|
|
303
|
+
*/
|
|
304
|
+
function encode(object, struct = undefined) {
|
|
305
|
+
const elements = [];
|
|
306
|
+
if (!struct) {
|
|
307
|
+
if (Array.isArray(object)) {
|
|
308
|
+
for (let i = 0; i < object.length; ++i) {
|
|
309
|
+
if (object[i] === null || object[i] === undefined)
|
|
310
|
+
continue;
|
|
311
|
+
elements.push(createElement(i, object[i]));
|
|
312
|
+
}
|
|
313
|
+
} else {
|
|
314
|
+
for (let i of Object.keys(object)) {
|
|
315
|
+
if (object[i] === null || object[i] === undefined)
|
|
316
|
+
continue;
|
|
317
|
+
elements.push(createElement(parseInt(i), object[i]));
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
} else {
|
|
321
|
+
for (const name of Object.keys(struct)) {
|
|
322
|
+
if (!Reflect.has(object, name))
|
|
323
|
+
continue;
|
|
324
|
+
elements.push(createElement(struct[name], object[name]));
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return Buffer.concat(elements);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* 嵌套结构数据必须调用此函数创建,暂不支持在struct中直接定义
|
|
332
|
+
* @param {{[k: number]: any}|any[]} object
|
|
333
|
+
* @param {JceStruct} struct
|
|
334
|
+
*/
|
|
335
|
+
function encodeNested(object, struct = undefined) {
|
|
336
|
+
return new Nested(encode(object, struct));
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
module.exports = {
|
|
340
|
+
setEncoding, decode, encode, encodeNested, Struct, Nested
|
|
341
|
+
};
|
package/lib/algo/pb.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* protobuf组包解包
|
|
3
|
+
*/
|
|
4
|
+
"use strict";
|
|
5
|
+
// const pb = require("protobufjs");
|
|
6
|
+
const pb = require("./protobuf.min");
|
|
7
|
+
|
|
8
|
+
class Proto {
|
|
9
|
+
/**
|
|
10
|
+
* @param {Buffer} bytes
|
|
11
|
+
* @param {import("../ref").Proto} decoded
|
|
12
|
+
*/
|
|
13
|
+
constructor(bytes, decoded) {
|
|
14
|
+
if (decoded)
|
|
15
|
+
Reflect.setPrototypeOf(this, decoded);
|
|
16
|
+
this._raw = bytes;
|
|
17
|
+
}
|
|
18
|
+
toString() {
|
|
19
|
+
return String(this._raw);
|
|
20
|
+
}
|
|
21
|
+
toHex() {
|
|
22
|
+
return this._raw.toString("hex");
|
|
23
|
+
}
|
|
24
|
+
toBase64() {
|
|
25
|
+
return this._raw.toString("base64");
|
|
26
|
+
}
|
|
27
|
+
toBuffer() {
|
|
28
|
+
return this._raw;
|
|
29
|
+
}
|
|
30
|
+
[Symbol.toPrimitive]() {
|
|
31
|
+
return this.toString();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {pb.Writer} writer
|
|
37
|
+
* @param {number} tag
|
|
38
|
+
* @param {any} value
|
|
39
|
+
*/
|
|
40
|
+
function _encode(writer, tag, value) {
|
|
41
|
+
if (value === null || value === undefined)
|
|
42
|
+
return;
|
|
43
|
+
let type = 2;
|
|
44
|
+
if (typeof value === "number") {
|
|
45
|
+
type = Number.isInteger(value) ? 0 : 1;
|
|
46
|
+
} else if (typeof value === "string") {
|
|
47
|
+
value = Buffer.from(value);
|
|
48
|
+
} else if (value instanceof Uint8Array) {
|
|
49
|
+
//
|
|
50
|
+
} else if (value instanceof Proto) {
|
|
51
|
+
value = value.toBuffer();
|
|
52
|
+
} else if (typeof value === "object") {
|
|
53
|
+
value = encode(value);
|
|
54
|
+
} else if (typeof value === "bigint") {
|
|
55
|
+
const tmp = new pb.util.Long();
|
|
56
|
+
tmp.unsigned = false;
|
|
57
|
+
tmp.low = Number(value & 0xffffffffn);
|
|
58
|
+
tmp.high = Number((value & 0xffffffff00000000n) >> 32n);
|
|
59
|
+
value = tmp;
|
|
60
|
+
type = 0;
|
|
61
|
+
} else {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const head = tag << 3 | type;
|
|
65
|
+
writer.uint32(head);
|
|
66
|
+
switch (type) {
|
|
67
|
+
case 0:
|
|
68
|
+
if (value < 0)
|
|
69
|
+
writer.sint64(value);
|
|
70
|
+
else
|
|
71
|
+
writer.int64(value);
|
|
72
|
+
break;
|
|
73
|
+
case 2:
|
|
74
|
+
writer.bytes(value);
|
|
75
|
+
break;
|
|
76
|
+
case 1:
|
|
77
|
+
writer.double(value);
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* @param {import("../ref").Proto} o
|
|
84
|
+
* @returns {Uint8Array}
|
|
85
|
+
*/
|
|
86
|
+
function encode(o) {
|
|
87
|
+
Reflect.setPrototypeOf(o, null);
|
|
88
|
+
const writer = new pb.Writer();
|
|
89
|
+
for (let tag in o) {
|
|
90
|
+
const value = o[tag];
|
|
91
|
+
tag = parseInt(tag);
|
|
92
|
+
if (Array.isArray(value)) {
|
|
93
|
+
for (let v of value)
|
|
94
|
+
_encode(writer, tag, v);
|
|
95
|
+
} else {
|
|
96
|
+
_encode(writer, tag, value);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return writer.finish();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @param {pb.Long} long
|
|
104
|
+
*/
|
|
105
|
+
function long2int(long) {
|
|
106
|
+
if (long.high === 0) {
|
|
107
|
+
return long.low >>> 0;
|
|
108
|
+
}
|
|
109
|
+
const bigint = (BigInt(long.high) << 32n) | (BigInt(long.low) & 0xffffffffn);
|
|
110
|
+
const int = long.toNumber();
|
|
111
|
+
return Number.isSafeInteger(int) ? int : bigint;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @param {Buffer} buf
|
|
116
|
+
* @returns {import("../ref").Proto}
|
|
117
|
+
*/
|
|
118
|
+
function decode(buf) {
|
|
119
|
+
const data = new Proto(buf);
|
|
120
|
+
const reader = new pb.Reader(buf);
|
|
121
|
+
while (reader.pos < reader.len) {
|
|
122
|
+
const k = reader.uint32();
|
|
123
|
+
const tag = k >> 3, type = k & 0b111;
|
|
124
|
+
let value, decoded;
|
|
125
|
+
switch (type) {
|
|
126
|
+
case 0:
|
|
127
|
+
value = long2int(reader.int64());
|
|
128
|
+
break;
|
|
129
|
+
case 1:
|
|
130
|
+
value = long2int(reader.fixed64());
|
|
131
|
+
break;
|
|
132
|
+
case 2:
|
|
133
|
+
value = reader.bytes();
|
|
134
|
+
try {
|
|
135
|
+
decoded = decode(value);
|
|
136
|
+
} catch { }
|
|
137
|
+
value = new Proto(value, decoded);
|
|
138
|
+
break;
|
|
139
|
+
case 5:
|
|
140
|
+
value = reader.fixed32();
|
|
141
|
+
break;
|
|
142
|
+
default:
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (Array.isArray(data[tag])) {
|
|
146
|
+
data[tag].push(value);
|
|
147
|
+
} else if (Reflect.has(data, tag)) {
|
|
148
|
+
data[tag] = [data[tag]];
|
|
149
|
+
data[tag].push(value);
|
|
150
|
+
} else {
|
|
151
|
+
data[tag] = value;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return data;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
module.exports = {
|
|
158
|
+
encode, decode,
|
|
159
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* protobuf.js v6.10.0 (c) 2016, daniel wirtz
|
|
3
|
+
* compiled wed, 15 jul 2020 23:34:14 utc
|
|
4
|
+
* licensed under the bsd-3-clause license
|
|
5
|
+
* see: https://github.com/dcodeio/protobuf.js for details
|
|
6
|
+
*/
|
|
7
|
+
!function(d){"use strict";var r,u,t,n;r={1:[function(t,n){n.exports=function(t,n){var i=Array(arguments.length-1),e=0,r=2,s=!0;for(;r<arguments.length;)i[e++]=arguments[r++];return new Promise(function(r,u){i[e]=function(t){if(s)if(s=!1,t)u(t);else{for(var n=Array(arguments.length-1),i=0;i<n.length;)n[i++]=arguments[i];r.apply(null,n)}};try{t.apply(n||null,i)}catch(t){s&&(s=!1,u(t))}})}},{}],2:[function(t,n,i){var r=i;r.length=function(t){var n=t.length;if(!n)return 0;for(var i=0;1<--n%4&&"="==t[0|n];)++i;return Math.ceil(3*t.length)/4-i};for(var o=Array(64),f=Array(123),u=0;u<64;)f[o[u]=u<26?u+65:u<52?u+71:u<62?u-4:u-59|43]=u++;r.encode=function(t,n,i){for(var r,u=null,e=[],s=0,h=0;n<i;){var f=t[n++];switch(h){case 0:e[s++]=o[f>>2],r=(3&f)<<4,h=1;break;case 1:e[s++]=o[r|f>>4],r=(15&f)<<2,h=2;break;case 2:e[s++]=o[r|f>>6],e[s++]=o[63&f],h=0}8191<s&&((u=u||[]).push(String.fromCharCode.apply(String,e)),s=0)}return h&&(e[s++]=o[r],e[s++]=61,1===h&&(e[s++]=61)),u?(s&&u.push(String.fromCharCode.apply(String,e.slice(0,s))),u.join("")):String.fromCharCode.apply(String,e.slice(0,s))};var c="invalid encoding";r.decode=function(t,n,i){for(var r,u=i,e=0,s=0;s<t.length;){var h=t.charCodeAt(s++);if(61===h&&1<e)break;if((h=f[h])===d)throw Error(c);switch(e){case 0:r=h,e=1;break;case 1:n[i++]=r<<2|(48&h)>>4,r=h,e=2;break;case 2:n[i++]=(15&r)<<4|(60&h)>>2,r=h,e=3;break;case 3:n[i++]=(3&r)<<6|h,e=0}}if(1===e)throw Error(c);return i-u},r.test=function(t){return/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(t)}},{}],3:[function(t,n){function i(){this.t={}}(n.exports=i).prototype.on=function(t,n,i){return(this.t[t]||(this.t[t]=[])).push({fn:n,ctx:i||this}),this},i.prototype.off=function(t,n){if(t===d)this.t={};else if(n===d)this.t[t]=[];else for(var i=this.t[t],r=0;r<i.length;)i[r].fn===n?i.splice(r,1):++r;return this},i.prototype.emit=function(t){var n=this.t[t];if(n){for(var i=[],r=1;r<arguments.length;)i.push(arguments[r++]);for(r=0;r<n.length;)n[r].fn.apply(n[r++].ctx,i)}return this}},{}],4:[function(t,n){function i(t){function n(t,n,i,r){var u=n<0?1:0;if(u&&(n=-n),0===n)t(0<1/n?0:2147483648,i,r);else if(isNaN(n))t(2143289344,i,r);else if(34028234663852886e22<n)t((u<<31|2139095040)>>>0,i,r);else if(n<11754943508222875e-54)t((u<<31|Math.round(n/1401298464324817e-60))>>>0,i,r);else{var e=Math.floor(Math.log(n)/Math.LN2);t((u<<31|127+e<<23|8388607&Math.round(n*Math.pow(2,-e)*8388608))>>>0,i,r)}}function i(t,n,i){var r=t(n,i),u=2*(r>>31)+1,e=r>>>23&255,s=8388607&r;return 255==e?s?NaN:1/0*u:0==e?1401298464324817e-60*u*s:u*Math.pow(2,e-150)*(8388608+s)}function r(t,n,i){h[0]=t,n[i]=f[0],n[i+1]=f[1],n[i+2]=f[2],n[i+3]=f[3]}function u(t,n,i){h[0]=t,n[i]=f[3],n[i+1]=f[2],n[i+2]=f[1],n[i+3]=f[0]}function e(t,n){return f[0]=t[n],f[1]=t[n+1],f[2]=t[n+2],f[3]=t[n+3],h[0]}function s(t,n){return f[3]=t[n],f[2]=t[n+1],f[1]=t[n+2],f[0]=t[n+3],h[0]}var h,f,o,c,a,l;function v(t,n,i,r,u,e){var s=r<0?1:0;if(s&&(r=-r),0===r)t(0,u,e+n),t(0<1/r?0:2147483648,u,e+i);else if(isNaN(r))t(0,u,e+n),t(2146959360,u,e+i);else if(17976931348623157e292<r)t(0,u,e+n),t((s<<31|2146435072)>>>0,u,e+i);else{var h;if(r<22250738585072014e-324)t((h=r/5e-324)>>>0,u,e+n),t((s<<31|h/4294967296)>>>0,u,e+i);else{var f=Math.floor(Math.log(r)/Math.LN2);1024===f&&(f=1023),t(4503599627370496*(h=r*Math.pow(2,-f))>>>0,u,e+n),t((s<<31|f+1023<<20|1048576*h&1048575)>>>0,u,e+i)}}}function w(t,n,i,r,u){var e=t(r,u+n),s=t(r,u+i),h=2*(s>>31)+1,f=s>>>20&2047,o=4294967296*(1048575&s)+e;return 2047==f?o?NaN:1/0*h:0==f?5e-324*h*o:h*Math.pow(2,f-1075)*(o+4503599627370496)}function y(t,n,i){c[0]=t,n[i]=a[0],n[i+1]=a[1],n[i+2]=a[2],n[i+3]=a[3],n[i+4]=a[4],n[i+5]=a[5],n[i+6]=a[6],n[i+7]=a[7]}function b(t,n,i){c[0]=t,n[i]=a[7],n[i+1]=a[6],n[i+2]=a[5],n[i+3]=a[4],n[i+4]=a[3],n[i+5]=a[2],n[i+6]=a[1],n[i+7]=a[0]}function d(t,n){return a[0]=t[n],a[1]=t[n+1],a[2]=t[n+2],a[3]=t[n+3],a[4]=t[n+4],a[5]=t[n+5],a[6]=t[n+6],a[7]=t[n+7],c[0]}function g(t,n){return a[7]=t[n],a[6]=t[n+1],a[5]=t[n+2],a[4]=t[n+3],a[3]=t[n+4],a[2]=t[n+5],a[1]=t[n+6],a[0]=t[n+7],c[0]}return"undefined"!=typeof Float32Array?(h=new Float32Array([-0]),f=new Uint8Array(h.buffer),o=128===f[3],t.writeFloatLE=o?r:u,t.writeFloatBE=o?u:r,t.readFloatLE=o?e:s,t.readFloatBE=o?s:e):(t.writeFloatLE=n.bind(null,A),t.writeFloatBE=n.bind(null,p),t.readFloatLE=i.bind(null,m),t.readFloatBE=i.bind(null,j)),"undefined"!=typeof Float64Array?(c=new Float64Array([-0]),a=new Uint8Array(c.buffer),l=128===a[7],t.writeDoubleLE=l?y:b,t.writeDoubleBE=l?b:y,t.readDoubleLE=l?d:g,t.readDoubleBE=l?g:d):(t.writeDoubleLE=v.bind(null,A,0,4),t.writeDoubleBE=v.bind(null,p,4,0),t.readDoubleLE=w.bind(null,m,0,4),t.readDoubleBE=w.bind(null,j,4,0)),t}function A(t,n,i){n[i]=255&t,n[i+1]=t>>>8&255,n[i+2]=t>>>16&255,n[i+3]=t>>>24}function p(t,n,i){n[i]=t>>>24,n[i+1]=t>>>16&255,n[i+2]=t>>>8&255,n[i+3]=255&t}function m(t,n){return(t[n]|t[n+1]<<8|t[n+2]<<16|t[n+3]<<24)>>>0}function j(t,n){return(t[n]<<24|t[n+1]<<16|t[n+2]<<8|t[n+3])>>>0}n.exports=i(i)},{}],5:[function(t,n,i){function r(t){try{var n=eval("require")(t);if(n&&(n.length||Object.keys(n).length))return n}catch(t){}return null}n.exports=r},{}],6:[function(t,n){n.exports=function(i,r,t){var u=t||8192,e=u>>>1,s=null,h=u;return function(t){if(t<1||e<t)return i(t);u<h+t&&(s=i(u),h=0);var n=r.call(s,h,h+=t);return 7&h&&(h=1+(7|h)),n}}},{}],7:[function(t,n,i){var r=i;r.length=function(t){for(var n=0,i=0,r=0;r<t.length;++r)(i=t.charCodeAt(r))<128?n+=1:i<2048?n+=2:55296==(64512&i)&&56320==(64512&t.charCodeAt(r+1))?(++r,n+=4):n+=3;return n},r.read=function(t,n,i){if(i-n<1)return"";for(var r,u=null,e=[],s=0;n<i;)(r=t[n++])<128?e[s++]=r:191<r&&r<224?e[s++]=(31&r)<<6|63&t[n++]:239<r&&r<365?(r=((7&r)<<18|(63&t[n++])<<12|(63&t[n++])<<6|63&t[n++])-65536,e[s++]=55296+(r>>10),e[s++]=56320+(1023&r)):e[s++]=(15&r)<<12|(63&t[n++])<<6|63&t[n++],8191<s&&((u=u||[]).push(String.fromCharCode.apply(String,e)),s=0);return u?(s&&u.push(String.fromCharCode.apply(String,e.slice(0,s))),u.join("")):String.fromCharCode.apply(String,e.slice(0,s))},r.write=function(t,n,i){for(var r,u,e=i,s=0;s<t.length;++s)(r=t.charCodeAt(s))<128?n[i++]=r:(r<2048?n[i++]=r>>6|192:(55296==(64512&r)&&56320==(64512&(u=t.charCodeAt(s+1)))?(r=65536+((1023&r)<<10)+(1023&u),++s,n[i++]=r>>18|240,n[i++]=r>>12&63|128):n[i++]=r>>12|224,n[i++]=r>>6&63|128),n[i++]=63&r|128);return i-e}},{}],8:[function(t,n,i){var r=i;function u(){r.util.n(),r.Writer.n(r.BufferWriter),r.Reader.n(r.BufferReader)}r.build="minimal",r.Writer=t(16),r.BufferWriter=t(17),r.Reader=t(9),r.BufferReader=t(10),r.util=t(15),r.rpc=t(12),r.roots=t(11),(r.configure=u)()},{10:10,11:11,12:12,15:15,16:16,17:17,9:9}],9:[function(t,n){n.exports=h;var i,r=t(15),u=r.LongBits,e=r.utf8;function s(t,n){return RangeError("index out of range: "+t.pos+" + "+(n||1)+" > "+t.len)}function h(t){this.buf=t,this.pos=0,this.len=t.length}function f(){return r.Buffer?function(t){return(h.create=function(t){return r.Buffer.isBuffer(t)?new i(t):c(t)})(t)}:c}var o,c="undefined"!=typeof Uint8Array?function(t){if(t instanceof Uint8Array||Array.isArray(t))return new h(t);throw Error("illegal buffer")}:function(t){if(Array.isArray(t))return new h(t);throw Error("illegal buffer")};function a(){var t=new u(0,0),n=0;if(!(4<this.len-this.pos)){for(;n<3;++n){if(this.pos>=this.len)throw s(this);if(t.lo=(t.lo|(127&this.buf[this.pos])<<7*n)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(127&this.buf[this.pos++])<<7*n)>>>0,t}for(;n<4;++n)if(t.lo=(t.lo|(127&this.buf[this.pos])<<7*n)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(127&this.buf[this.pos])<<28)>>>0,t.hi=(t.hi|(127&this.buf[this.pos])>>4)>>>0,this.buf[this.pos++]<128)return t;if(n=0,4<this.len-this.pos){for(;n<5;++n)if(t.hi=(t.hi|(127&this.buf[this.pos])<<7*n+3)>>>0,this.buf[this.pos++]<128)return t}else for(;n<5;++n){if(this.pos>=this.len)throw s(this);if(t.hi=(t.hi|(127&this.buf[this.pos])<<7*n+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}function l(t,n){return(t[n-4]|t[n-3]<<8|t[n-2]<<16|t[n-1]<<24)>>>0}function v(){if(this.pos+8>this.len)throw s(this,8);return new u(l(this.buf,this.pos+=4),l(this.buf,this.pos+=4))}h.create=f(),h.prototype.i=r.Array.prototype.subarray||r.Array.prototype.slice,h.prototype.uint32=(o=4294967295,function(){if(o=(127&this.buf[this.pos])>>>0,this.buf[this.pos++]<128)return o;if(o=(o|(127&this.buf[this.pos])<<7)>>>0,this.buf[this.pos++]<128)return o;if(o=(o|(127&this.buf[this.pos])<<14)>>>0,this.buf[this.pos++]<128)return o;if(o=(o|(127&this.buf[this.pos])<<21)>>>0,this.buf[this.pos++]<128)return o;if(o=(o|(15&this.buf[this.pos])<<28)>>>0,this.buf[this.pos++]<128)return o;if((this.pos+=5)>this.len)throw this.pos=this.len,s(this,10);return o}),h.prototype.int32=function(){return 0|this.uint32()},h.prototype.sint32=function(){var t=this.uint32();return t>>>1^-(1&t)|0},h.prototype.bool=function(){return 0!==this.uint32()},h.prototype.fixed32=function(){if(this.pos+4>this.len)throw s(this,4);return l(this.buf,this.pos+=4)},h.prototype.sfixed32=function(){if(this.pos+4>this.len)throw s(this,4);return 0|l(this.buf,this.pos+=4)},h.prototype.float=function(){if(this.pos+4>this.len)throw s(this,4);var t=r.float.readFloatLE(this.buf,this.pos);return this.pos+=4,t},h.prototype.double=function(){if(this.pos+8>this.len)throw s(this,4);var t=r.float.readDoubleLE(this.buf,this.pos);return this.pos+=8,t},h.prototype.bytes=function(){var t=this.uint32(),n=this.pos,i=this.pos+t;if(i>this.len)throw s(this,t);return this.pos+=t,Array.isArray(this.buf)?this.buf.slice(n,i):n===i?Buffer.alloc(0):this.i.call(this.buf,n,i)},h.prototype.string=function(){var t=this.bytes();return e.read(t,0,t.length)},h.prototype.skip=function(t){if("number"==typeof t){if(this.pos+t>this.len)throw s(this,t);this.pos+=t}else do{if(this.pos>=this.len)throw s(this)}while(128&this.buf[this.pos++]);return this},h.prototype.skipType=function(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;4!=(t=7&this.uint32());)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error("invalid wire type "+t+" at offset "+this.pos)}return this},h.n=function(t){i=t,h.create=f(),i.n();var n=r.Long?"toLong":"toNumber";r.merge(h.prototype,{int64:function(){return a.call(this)[n](!1)},uint64:function(){return a.call(this)[n](!0)},sint64:function(){return a.call(this).zzDecode()[n](!1)},fixed64:function(){return v.call(this)[n](!0)},sfixed64:function(){return v.call(this)[n](!1)}})}},{15:15}],10:[function(t,n){n.exports=u;var i=t(9);(u.prototype=Object.create(i.prototype)).constructor=u;var r=t(15);function u(t){i.call(this,t)}u.n=function(){r.Buffer&&(u.prototype.i=r.Buffer.prototype.slice)},u.prototype.string=function(){var t=this.uint32();return this.buf.utf8Slice?this.buf.utf8Slice(this.pos,this.pos=Math.min(this.pos+t,this.len)):this.buf.toString("utf-8",this.pos,this.pos=Math.min(this.pos+t,this.len))},u.n()},{15:15,9:9}],11:[function(t,n){n.exports={}},{}],12:[function(t,n,i){i.Service=t(13)},{13:13}],13:[function(t,n){n.exports=i;var h=t(15);function i(t,n,i){if("function"!=typeof t)throw TypeError("rpcImpl must be a function");h.EventEmitter.call(this),this.rpcImpl=t,this.requestDelimited=!!n,this.responseDelimited=!!i}((i.prototype=Object.create(h.EventEmitter.prototype)).constructor=i).prototype.rpcCall=function t(i,n,r,u,e){if(!u)throw TypeError("request must be specified");var s=this;if(!e)return h.asPromise(t,s,i,n,r,u);if(!s.rpcImpl)return setTimeout(function(){e(Error("already ended"))},0),d;try{return s.rpcImpl(i,n[s.requestDelimited?"encodeDelimited":"encode"](u).finish(),function(t,n){if(t)return s.emit("error",t,i),e(t);if(null===n)return s.end(!0),d;if(!(n instanceof r))try{n=r[s.responseDelimited?"decodeDelimited":"decode"](n)}catch(t){return s.emit("error",t,i),e(t)}return s.emit("data",n,i),e(null,n)})}catch(t){return s.emit("error",t,i),setTimeout(function(){e(t)},0),d}},i.prototype.end=function(t){return this.rpcImpl&&(t||this.rpcImpl(null,null,null),this.rpcImpl=null,this.emit("end").off()),this}},{15:15}],14:[function(t,n){n.exports=u;var i=t(15);function u(t,n){this.lo=t>>>0,this.hi=n>>>0}var e=u.zero=new u(0,0);e.toNumber=function(){return 0},e.zzEncode=e.zzDecode=function(){return this},e.length=function(){return 1};var r=u.zeroHash="\0\0\0\0\0\0\0\0";u.fromNumber=function(t){if(0===t)return e;var n=t<0;n&&(t=-t);var i=t>>>0,r=(t-i)/4294967296>>>0;return n&&(r=~r>>>0,i=~i>>>0,4294967295<++i&&(i=0,4294967295<++r&&(r=0))),new u(i,r)},u.from=function(t){if("number"==typeof t)return u.fromNumber(t);if(i.isString(t)){if(!i.Long)return u.fromNumber(parseInt(t,10));t=i.Long.fromString(t)}return t.low||t.high?new u(t.low>>>0,t.high>>>0):e},u.prototype.toNumber=function(t){if(!t&&this.hi>>>31){var n=1+~this.lo>>>0,i=~this.hi>>>0;return n||(i=i+1>>>0),-(n+4294967296*i)}return this.lo+4294967296*this.hi},u.prototype.toLong=function(t){return i.Long?new i.Long(0|this.lo,0|this.hi,!!t):{low:0|this.lo,high:0|this.hi,unsigned:!!t}};var s=String.prototype.charCodeAt;u.fromHash=function(t){return t===r?e:new u((s.call(t,0)|s.call(t,1)<<8|s.call(t,2)<<16|s.call(t,3)<<24)>>>0,(s.call(t,4)|s.call(t,5)<<8|s.call(t,6)<<16|s.call(t,7)<<24)>>>0)},u.prototype.toHash=function(){return String.fromCharCode(255&this.lo,this.lo>>>8&255,this.lo>>>16&255,this.lo>>>24,255&this.hi,this.hi>>>8&255,this.hi>>>16&255,this.hi>>>24)},u.prototype.zzEncode=function(){var t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this},u.prototype.zzDecode=function(){var t=-(1&this.lo);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this},u.prototype.length=function(){var t=this.lo,n=(this.lo>>>28|this.hi<<4)>>>0,i=this.hi>>>24;return 0==i?0==n?t<16384?t<128?1:2:t<2097152?3:4:n<16384?n<128?5:6:n<2097152?7:8:i<128?9:10}},{15:15}],15:[function(t,n,i){var r=i;function u(t,n,i){for(var r=Object.keys(n),u=0;u<r.length;++u)t[r[u]]!==d&&i||(t[r[u]]=n[r[u]]);return t}function e(t){function i(t,n){if(!(this instanceof i))return new i(t,n);Object.defineProperty(this,"message",{get:function(){return t}}),Error.captureStackTrace?Error.captureStackTrace(this,i):Object.defineProperty(this,"stack",{value:Error().stack||""}),n&&u(this,n)}return(i.prototype=Object.create(Error.prototype)).constructor=i,Object.defineProperty(i.prototype,"name",{get:function(){return t}}),i.prototype.toString=function(){return this.name+": "+this.message},i}r.asPromise=t(1),r.base64=t(2),r.EventEmitter=t(3),r.float=t(4),r.inquire=t(5),r.utf8=t(7),r.pool=t(6),r.LongBits=t(14),r.isNode=!!("undefined"!=typeof global&&global&&global.process&&global.process.versions&&global.process.versions.node),r.global=r.isNode&&global||"undefined"!=typeof window&&window||"undefined"!=typeof self&&self||this,r.emptyArray=Object.freeze?Object.freeze([]):[],r.emptyObject=Object.freeze?Object.freeze({}):{},r.isInteger=Number.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t},r.isString=function(t){return"string"==typeof t||t instanceof String},r.isObject=function(t){return t&&"object"==typeof t},r.isset=r.isSet=function(t,n){var i=t[n];return null!=i&&t.hasOwnProperty(n)&&("object"!=typeof i||0<(Array.isArray(i)?i.length:Object.keys(i).length))},r.Buffer=function(){try{var t=r.inquire("buffer").Buffer;return t.prototype.utf8Write?t:null}catch(t){return null}}(),r.r=null,r.u=null,r.newBuffer=function(t){return"number"==typeof t?r.Buffer?r.u(t):new r.Array(t):r.Buffer?r.r(t):"undefined"==typeof Uint8Array?t:new Uint8Array(t)},r.Array="undefined"!=typeof Uint8Array?Uint8Array:Array,r.Long=r.global.dcodeIO&&r.global.dcodeIO.Long||r.global.Long||r.inquire("long"),r.key2Re=/^true|false|0|1$/,r.key32Re=/^-?(?:0|[1-9][0-9]*)$/,r.key64Re=/^(?:[\\x00-\\xff]{8}|-?(?:0|[1-9][0-9]*))$/,r.longToHash=function(t){return t?r.LongBits.from(t).toHash():r.LongBits.zeroHash},r.longFromHash=function(t,n){var i=r.LongBits.fromHash(t);return r.Long?r.Long.fromBits(i.lo,i.hi,n):i.toNumber(!!n)},r.merge=u,r.lcFirst=function(t){return t[0].toLowerCase()+t.substring(1)},r.newError=e,r.ProtocolError=e("ProtocolError"),r.oneOfGetter=function(t){for(var i={},n=0;n<t.length;++n)i[t[n]]=1;return function(){for(var t=Object.keys(this),n=t.length-1;-1<n;--n)if(1===i[t[n]]&&this[t[n]]!==d&&null!==this[t[n]])return t[n]}},r.oneOfSetter=function(i){return function(t){for(var n=0;n<i.length;++n)i[n]!==t&&delete this[i[n]]}},r.toJSONOptions={longs:String,enums:String,bytes:String,json:!0},r.n=function(){var i=r.Buffer;i?(r.r=i.from!==Uint8Array.from&&i.from||function(t,n){return new i(t,n)},r.u=i.allocUnsafe||function(t){return new i(t)}):r.r=r.u=null}},{1:1,14:14,2:2,3:3,4:4,5:5,6:6,7:7}],16:[function(t,n){n.exports=c;var i,r=t(15),u=r.LongBits,e=r.base64,s=r.utf8;function h(t,n,i){this.fn=t,this.len=n,this.next=d,this.val=i}function f(){}function o(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}function c(){this.len=0,this.head=new h(f,0,0),this.tail=this.head,this.states=null}function a(){return r.Buffer?function(){return(c.create=function(){return new i})()}:function(){return new c}}function l(t,n,i){n[i]=255&t}function v(t,n){this.len=t,this.next=d,this.val=n}function w(t,n,i){for(;t.hi;)n[i++]=127&t.lo|128,t.lo=(t.lo>>>7|t.hi<<25)>>>0,t.hi>>>=7;for(;127<t.lo;)n[i++]=127&t.lo|128,t.lo=t.lo>>>7;n[i++]=t.lo}function y(t,n,i){n[i]=255&t,n[i+1]=t>>>8&255,n[i+2]=t>>>16&255,n[i+3]=t>>>24}c.create=a(),c.alloc=function(t){return new r.Array(t)},r.Array!==Array&&(c.alloc=r.pool(c.alloc,r.Array.prototype.subarray)),c.prototype.e=function(t,n,i){return this.tail=this.tail.next=new h(t,n,i),this.len+=n,this},(v.prototype=Object.create(h.prototype)).fn=function(t,n,i){for(;127<t;)n[i++]=127&t|128,t>>>=7;n[i]=t},c.prototype.uint32=function(t){return this.len+=(this.tail=this.tail.next=new v((t>>>=0)<128?1:t<16384?2:t<2097152?3:t<268435456?4:5,t)).len,this},c.prototype.int32=function(t){return t<0?this.e(w,10,u.fromNumber(t)):this.uint32(t)},c.prototype.sint32=function(t){return this.uint32((t<<1^t>>31)>>>0)},c.prototype.int64=c.prototype.uint64=function(t){var n=u.from(t);return this.e(w,n.length(),n)},c.prototype.sint64=function(t){var n=u.from(t).zzEncode();return this.e(w,n.length(),n)},c.prototype.bool=function(t){return this.e(l,1,t?1:0)},c.prototype.sfixed32=c.prototype.fixed32=function(t){return this.e(y,4,t>>>0)},c.prototype.sfixed64=c.prototype.fixed64=function(t){var n=u.from(t);return this.e(y,4,n.lo).e(y,4,n.hi)},c.prototype.float=function(t){return this.e(r.float.writeFloatLE,4,t)},c.prototype.double=function(t){return this.e(r.float.writeDoubleLE,8,t)};var b=r.Array.prototype.set?function(t,n,i){n.set(t,i)}:function(t,n,i){for(var r=0;r<t.length;++r)n[i+r]=t[r]};c.prototype.bytes=function(t){var n=t.length>>>0;if(!n)return this.e(l,1,0);if(r.isString(t)){var i=c.alloc(n=e.length(t));e.decode(t,i,0),t=i}return this.uint32(n).e(b,n,t)},c.prototype.string=function(t){var n=s.length(t);return n?this.uint32(n).e(s.write,n,t):this.e(l,1,0)},c.prototype.fork=function(){return this.states=new o(this),this.head=this.tail=new h(f,0,0),this.len=0,this},c.prototype.reset=function(){return this.states?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new h(f,0,0),this.len=0),this},c.prototype.ldelim=function(){var t=this.head,n=this.tail,i=this.len;return this.reset().uint32(i),i&&(this.tail.next=t.next,this.tail=n,this.len+=i),this},c.prototype.finish=function(){for(var t=this.head.next,n=this.constructor.alloc(this.len),i=0;t;)t.fn(t.val,n,i),i+=t.len,t=t.next;return n},c.n=function(t){i=t,c.create=a(),i.n()}},{15:15}],17:[function(t,n){n.exports=u;var i=t(16);(u.prototype=Object.create(i.prototype)).constructor=u;var r=t(15);function u(){i.call(this)}function e(t,n,i){t.length<40?r.utf8.write(t,n,i):n.utf8Write?n.utf8Write(t,i):n.write(t,i)}u.n=function(){u.alloc=r.u,u.writeBytesBuffer=r.Buffer&&r.Buffer.prototype instanceof Uint8Array&&"set"===r.Buffer.prototype.set.name?function(t,n,i){n.set(t,i)}:function(t,n,i){if(t.copy)t.copy(n,i,0,t.length);else for(var r=0;r<t.length;)n[i++]=t[r++]}},u.prototype.bytes=function(t){r.isString(t)&&(t=r.r(t,"base64"));var n=t.length>>>0;return this.uint32(n),n&&this.e(u.writeBytesBuffer,n,t),this},u.prototype.string=function(t){var n=r.Buffer.byteLength(t);return this.uint32(n),n&&this.e(e,n,t),this},u.n()},{15:15,16:16}]},u={},t=[8],n=function t(n){var i=u[n];return i||r[n][0].call(i=u[n]={exports:{}},t,i,i.exports),i.exports}(t[0]),n.util.global.protobuf=n,"function"==typeof define&&define.amd&&define(["long"],function(t){return t&&t.isLong&&(n.util.Long=t,n.configure()),n}),"object"==typeof module&&module&&module.exports&&(module.exports=n)}();
|
|
8
|
+
//# sourceMappingURL=protobuf.min.js.map
|