rocketmq-client-remoting-nodejs 0.0.0-stage → 0.0.1
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/README.en.md +428 -0
- package/README.md +424 -2
- package/dist/client/admin.d.ts +229 -0
- package/dist/client/admin.js +2462 -0
- package/dist/client/allocate.d.ts +48 -0
- package/dist/client/allocate.js +365 -0
- package/dist/client/backpressure.d.ts +23 -0
- package/dist/client/backpressure.js +95 -0
- package/dist/client/consumer.d.ts +294 -0
- package/dist/client/consumer.js +3095 -0
- package/dist/client/consumer_result.d.ts +129 -0
- package/dist/client/consumer_result.js +138 -0
- package/dist/client/consumer_stats.d.ts +69 -0
- package/dist/client/consumer_stats.js +258 -0
- package/dist/client/exception.d.ts +39 -0
- package/dist/client/exception.js +36 -0
- package/dist/client/hook.d.ts +145 -0
- package/dist/client/hook.js +171 -0
- package/dist/client/latency.d.ts +61 -0
- package/dist/client/latency.js +239 -0
- package/dist/client/lite_pull_consumer.d.ts +151 -0
- package/dist/client/lite_pull_consumer.js +1096 -0
- package/dist/client/mq_client.d.ts +188 -0
- package/dist/client/mq_client.js +1678 -0
- package/dist/client/mq_client_manager.d.ts +21 -0
- package/dist/client/mq_client_manager.js +129 -0
- package/dist/client/offset_store.d.ts +45 -0
- package/dist/client/offset_store.js +389 -0
- package/dist/client/open_tracing_hook.d.ts +52 -0
- package/dist/client/open_tracing_hook.js +241 -0
- package/dist/client/pop_api.d.ts +28 -0
- package/dist/client/pop_api.js +224 -0
- package/dist/client/pop_consumer.d.ts +23 -0
- package/dist/client/pop_consumer.js +719 -0
- package/dist/client/pop_process_queue.d.ts +15 -0
- package/dist/client/pop_process_queue.js +51 -0
- package/dist/client/process_queue.d.ts +49 -0
- package/dist/client/process_queue.js +261 -0
- package/dist/client/produce_accumulator.d.ts +75 -0
- package/dist/client/produce_accumulator.js +288 -0
- package/dist/client/producer.d.ts +231 -0
- package/dist/client/producer.js +1774 -0
- package/dist/client/pull_api.d.ts +26 -0
- package/dist/client/pull_api.js +264 -0
- package/dist/client/pull_consumer.d.ts +119 -0
- package/dist/client/pull_consumer.js +876 -0
- package/dist/client/pull_schedule_service.d.ts +71 -0
- package/dist/client/pull_schedule_service.js +424 -0
- package/dist/client/request_reply.d.ts +61 -0
- package/dist/client/request_reply.js +232 -0
- package/dist/client/retry_message.d.ts +2 -0
- package/dist/client/retry_message.js +27 -0
- package/dist/client/send_result.d.ts +57 -0
- package/dist/client/send_result.js +70 -0
- package/dist/client/top_addressing.d.ts +20 -0
- package/dist/client/top_addressing.js +75 -0
- package/dist/client/trace_context.d.ts +61 -0
- package/dist/client/trace_context.js +373 -0
- package/dist/client/trace_dispatcher.d.ts +31 -0
- package/dist/client/trace_dispatcher.js +236 -0
- package/dist/client/trace_hook.d.ts +23 -0
- package/dist/client/trace_hook.js +228 -0
- package/dist/client/traceparent.d.ts +9 -0
- package/dist/client/traceparent.js +86 -0
- package/dist/common/boundary_type.d.ts +7 -0
- package/dist/common/boundary_type.js +16 -0
- package/dist/common/compress.d.ts +28 -0
- package/dist/common/compress.js +512 -0
- package/dist/common/message.d.ts +129 -0
- package/dist/common/message.js +214 -0
- package/dist/common/messageClientIdSetter.d.ts +7 -0
- package/dist/common/messageClientIdSetter.js +48 -0
- package/dist/common/messageConst.d.ts +68 -0
- package/dist/common/messageConst.js +68 -0
- package/dist/common/messageDecoder.d.ts +40 -0
- package/dist/common/messageDecoder.js +504 -0
- package/dist/common/messageType.d.ts +11 -0
- package/dist/common/messageType.js +11 -0
- package/dist/common/message_accessor.d.ts +39 -0
- package/dist/common/message_accessor.js +135 -0
- package/dist/common/mixAll.d.ts +106 -0
- package/dist/common/mixAll.js +247 -0
- package/dist/common/recall_message_handle.d.ts +25 -0
- package/dist/common/recall_message_handle.js +98 -0
- package/dist/common/subscriptionData.d.ts +36 -0
- package/dist/common/subscriptionData.js +64 -0
- package/dist/common/sysflag.d.ts +129 -0
- package/dist/common/sysflag.js +96 -0
- package/dist/common/topic_config.d.ts +66 -0
- package/dist/common/topic_config.js +106 -0
- package/dist/common/topic_validator.d.ts +49 -0
- package/dist/common/topic_validator.js +115 -0
- package/dist/common/utilAll.d.ts +39 -0
- package/dist/common/utilAll.js +154 -0
- package/dist/common/validators.d.ts +25 -0
- package/dist/common/validators.js +80 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.js +36 -0
- package/dist/logging.d.ts +24 -0
- package/dist/logging.js +246 -0
- package/dist/remoting/acl.d.ts +16 -0
- package/dist/remoting/acl.js +39 -0
- package/dist/remoting/admin_body.d.ts +257 -0
- package/dist/remoting/admin_body.js +669 -0
- package/dist/remoting/bodies.d.ts +475 -0
- package/dist/remoting/bodies.js +1131 -0
- package/dist/remoting/client.d.ts +73 -0
- package/dist/remoting/client.js +591 -0
- package/dist/remoting/codes.d.ts +296 -0
- package/dist/remoting/codes.js +301 -0
- package/dist/remoting/exception.d.ts +45 -0
- package/dist/remoting/exception.js +58 -0
- package/dist/remoting/extra_info.d.ts +61 -0
- package/dist/remoting/extra_info.js +220 -0
- package/dist/remoting/headers.d.ts +758 -0
- package/dist/remoting/headers.js +1307 -0
- package/dist/remoting/heartbeat.d.ts +91 -0
- package/dist/remoting/heartbeat.js +227 -0
- package/dist/remoting/namespace.d.ts +14 -0
- package/dist/remoting/namespace.js +85 -0
- package/dist/remoting/pop_bodies.d.ts +58 -0
- package/dist/remoting/pop_bodies.js +214 -0
- package/dist/remoting/remotingCommand.d.ts +39 -0
- package/dist/remoting/remotingCommand.js +225 -0
- package/dist/remoting/route.d.ts +61 -0
- package/dist/remoting/route.js +288 -0
- package/dist/remoting/rpc_hooks.d.ts +31 -0
- package/dist/remoting/rpc_hooks.js +73 -0
- package/dist/remoting/serialize.d.ts +33 -0
- package/dist/remoting/serialize.js +372 -0
- package/dist/remoting/socks_proxy.d.ts +29 -0
- package/dist/remoting/socks_proxy.js +379 -0
- package/dist/remoting/static_topic.d.ts +49 -0
- package/dist/remoting/static_topic.js +244 -0
- package/dist/remoting/subscription.d.ts +65 -0
- package/dist/remoting/subscription.js +172 -0
- package/package.json +38 -4
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
// -*- coding: utf-8 -*-
|
|
2
|
+
// Protocol serialization: JSON (RemotingSerializable) + fastjson2-tolerant parser
|
|
3
|
+
// + RocketMQ private binary header (RocketMQSerializable).
|
|
4
|
+
import { Buffer } from 'node:buffer';
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// fastjson2 tolerant JSON parser
|
|
7
|
+
// fastjson2 output is NOT strict JSON: map numeric keys lack quotes
|
|
8
|
+
// ({"brokerAddrs":{0:"127.0.0.1:10911"}}), map object keys are inlined as
|
|
9
|
+
// JSON ({"offsetTable":{{"brokerName":..}:{...}}}), and special floats
|
|
10
|
+
// (NaN/Infinity) appear. We need a small parser that tolerates non-string keys.
|
|
11
|
+
// ---------------------------------------------------------------------------
|
|
12
|
+
const WS = ' \t\r\n';
|
|
13
|
+
const ESCAPES = { '"': '"', '\\': '\\', '/': '/', b: '\b', f: '\f', n: '\n', r: '\r', t: '\t' };
|
|
14
|
+
class FastJsonParseError extends Error {
|
|
15
|
+
}
|
|
16
|
+
class _FastJsonParser {
|
|
17
|
+
constructor(text) { this.text = text; this.pos = 0; this.size = text.length; }
|
|
18
|
+
_skipWs() { while (this.pos < this.size && WS.includes(this.text[this.pos]))
|
|
19
|
+
this.pos++; }
|
|
20
|
+
_peek() {
|
|
21
|
+
if (this.pos >= this.size)
|
|
22
|
+
throw new FastJsonParseError(`unexpected end at ${this.pos}`);
|
|
23
|
+
return this.text[this.pos];
|
|
24
|
+
}
|
|
25
|
+
parse() {
|
|
26
|
+
const value = this._value();
|
|
27
|
+
this._skipWs();
|
|
28
|
+
if (this.pos !== this.size)
|
|
29
|
+
throw new FastJsonParseError(`trailing data at ${this.pos}`);
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
_value() {
|
|
33
|
+
this._skipWs();
|
|
34
|
+
const c = this._peek();
|
|
35
|
+
if (c === '{')
|
|
36
|
+
return this._object();
|
|
37
|
+
if (c === '[')
|
|
38
|
+
return this._array();
|
|
39
|
+
if (c === '"')
|
|
40
|
+
return this._string();
|
|
41
|
+
return this._literal();
|
|
42
|
+
}
|
|
43
|
+
_object() {
|
|
44
|
+
this.pos++; // eat '{'
|
|
45
|
+
const result = {};
|
|
46
|
+
this._skipWs();
|
|
47
|
+
if (this._peek() === '}') {
|
|
48
|
+
this.pos++;
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
for (;;) {
|
|
52
|
+
const key = this._key();
|
|
53
|
+
this._skipWs();
|
|
54
|
+
if (this._peek() !== ':')
|
|
55
|
+
throw new FastJsonParseError(`expected ':' at ${this.pos}`);
|
|
56
|
+
this.pos++;
|
|
57
|
+
result[key] = this._value();
|
|
58
|
+
this._skipWs();
|
|
59
|
+
const c = this._peek();
|
|
60
|
+
if (c === ',') {
|
|
61
|
+
this.pos++;
|
|
62
|
+
this._skipWs();
|
|
63
|
+
if (this._peek() === '}') {
|
|
64
|
+
this.pos++;
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (c === '}') {
|
|
70
|
+
this.pos++;
|
|
71
|
+
return result;
|
|
72
|
+
}
|
|
73
|
+
throw new FastJsonParseError(`expected ',' or '}' at ${this.pos}`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
_array() {
|
|
77
|
+
this.pos++; // eat '['
|
|
78
|
+
const items = [];
|
|
79
|
+
this._skipWs();
|
|
80
|
+
if (this._peek() === ']') {
|
|
81
|
+
this.pos++;
|
|
82
|
+
return items;
|
|
83
|
+
}
|
|
84
|
+
for (;;) {
|
|
85
|
+
items.push(this._value());
|
|
86
|
+
this._skipWs();
|
|
87
|
+
const c = this._peek();
|
|
88
|
+
if (c === ',') {
|
|
89
|
+
this.pos++;
|
|
90
|
+
this._skipWs();
|
|
91
|
+
if (this._peek() === ']') {
|
|
92
|
+
this.pos++;
|
|
93
|
+
return items;
|
|
94
|
+
}
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (c === ']') {
|
|
98
|
+
this.pos++;
|
|
99
|
+
return items;
|
|
100
|
+
}
|
|
101
|
+
throw new FastJsonParseError(`expected ',' or ']' at ${this.pos}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
_key() {
|
|
105
|
+
this._skipWs();
|
|
106
|
+
const c = this._peek();
|
|
107
|
+
if (c === '"')
|
|
108
|
+
return this._string();
|
|
109
|
+
if (c === '{' || c === '[') {
|
|
110
|
+
const start = this.pos;
|
|
111
|
+
this._value();
|
|
112
|
+
return this.text.slice(start, this.pos);
|
|
113
|
+
}
|
|
114
|
+
const start = this.pos;
|
|
115
|
+
while (this.pos < this.size && !': \t\r\n'.includes(this.text[this.pos]))
|
|
116
|
+
this.pos++;
|
|
117
|
+
return this.text.slice(start, this.pos);
|
|
118
|
+
}
|
|
119
|
+
_string() {
|
|
120
|
+
this.pos++; // eat opening quote
|
|
121
|
+
let out = '';
|
|
122
|
+
for (;;) {
|
|
123
|
+
if (this.pos >= this.size)
|
|
124
|
+
throw new FastJsonParseError('unterminated string');
|
|
125
|
+
const c = this.text[this.pos];
|
|
126
|
+
if (c === '"') {
|
|
127
|
+
this.pos++;
|
|
128
|
+
return out;
|
|
129
|
+
}
|
|
130
|
+
if (c === '\\') {
|
|
131
|
+
this.pos++;
|
|
132
|
+
if (this.pos >= this.size)
|
|
133
|
+
throw new FastJsonParseError('unterminated escape');
|
|
134
|
+
const e = this.text[this.pos];
|
|
135
|
+
if (e === 'u') {
|
|
136
|
+
const digits = this.text.slice(this.pos + 1, this.pos + 5);
|
|
137
|
+
if (digits.length !== 4)
|
|
138
|
+
throw new FastJsonParseError('bad \\u escape');
|
|
139
|
+
out += String.fromCharCode(parseInt(digits, 16));
|
|
140
|
+
this.pos += 5;
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
out += (ESCAPES[e] != null ? ESCAPES[e] : e);
|
|
144
|
+
this.pos++;
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
out += c;
|
|
148
|
+
this.pos++;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
_literal() {
|
|
152
|
+
const rest = this.text.slice(this.pos);
|
|
153
|
+
for (const [token, value] of [['true', true], ['false', false], ['null', null],
|
|
154
|
+
['NaN', NaN], ['Infinity', Infinity], ['-Infinity', -Infinity]]) {
|
|
155
|
+
if (rest.startsWith(token)) {
|
|
156
|
+
const tail = rest.slice(token.length, token.length + 1);
|
|
157
|
+
if (tail === '' || ',}] \t\r\n'.includes(tail)) {
|
|
158
|
+
this.pos += token.length;
|
|
159
|
+
return value;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const m = /^-?\d+(\.\d+)?([eE][-+]?\d+)?/.exec(rest);
|
|
164
|
+
if (!m)
|
|
165
|
+
throw new FastJsonParseError(`unexpected token at ${this.pos}: ${rest.slice(0, 20)}`);
|
|
166
|
+
this.pos += m[0].length;
|
|
167
|
+
return m[0].includes('.') || m[0].includes('e') || m[0].includes('E') ? parseFloat(m[0]) : parseInt(m[0], 10);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
export function fastjsonLoads(text) { return new _FastJsonParser(text).parse(); }
|
|
171
|
+
export function decodeMessageQueueKey(key) {
|
|
172
|
+
const text = (key || '').trim();
|
|
173
|
+
if (!text.startsWith('{'))
|
|
174
|
+
return null;
|
|
175
|
+
try {
|
|
176
|
+
return fastjsonLoads(text);
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function _tolerantJsonLoads(text) {
|
|
183
|
+
try {
|
|
184
|
+
return JSON.parse(text);
|
|
185
|
+
}
|
|
186
|
+
catch (e1) { /* fall through */ }
|
|
187
|
+
try {
|
|
188
|
+
return fastjsonLoads(text);
|
|
189
|
+
}
|
|
190
|
+
catch (e2) { /* fall through */ }
|
|
191
|
+
const fixed = text.replace(/(?:[{,]\s*)(-?\d+(?:\.\d+)?)\s*(:)/g, (m, n, c) => `${m.slice(0, m.indexOf(n))}"${n}"${c}`);
|
|
192
|
+
return JSON.parse(fixed);
|
|
193
|
+
}
|
|
194
|
+
export class RemotingSerializable {
|
|
195
|
+
static encode(obj) {
|
|
196
|
+
if (obj == null)
|
|
197
|
+
return Buffer.alloc(0);
|
|
198
|
+
if (Buffer.isBuffer(obj))
|
|
199
|
+
return obj;
|
|
200
|
+
return Buffer.from(JSON.stringify(obj, jsonReplacer), 'utf-8');
|
|
201
|
+
}
|
|
202
|
+
static toJson(obj, pretty = false) {
|
|
203
|
+
return JSON.stringify(obj, jsonReplacer, pretty ? 2 : undefined);
|
|
204
|
+
}
|
|
205
|
+
static decode(data) {
|
|
206
|
+
if (data == null || data.length === 0)
|
|
207
|
+
return null;
|
|
208
|
+
return _tolerantJsonLoads(data.toString('utf-8'));
|
|
209
|
+
}
|
|
210
|
+
static fromJson(jsonStr) { return _tolerantJsonLoads(jsonStr); }
|
|
211
|
+
static decodeJson(data) {
|
|
212
|
+
if (data == null)
|
|
213
|
+
return null;
|
|
214
|
+
return _tolerantJsonLoads(data.toString('utf-8'));
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function jsonReplacer(_key, value) {
|
|
218
|
+
if (value === undefined)
|
|
219
|
+
return undefined;
|
|
220
|
+
if (typeof value === 'bigint')
|
|
221
|
+
return value.toString();
|
|
222
|
+
if (value instanceof Set)
|
|
223
|
+
return Array.from(value);
|
|
224
|
+
if (value instanceof Map) {
|
|
225
|
+
const o = {};
|
|
226
|
+
for (const [k, v] of value)
|
|
227
|
+
o[k] = v;
|
|
228
|
+
return o;
|
|
229
|
+
}
|
|
230
|
+
return value;
|
|
231
|
+
}
|
|
232
|
+
// ---------------------------------------------------------------------------
|
|
233
|
+
// RocketMQ 4.x private binary header codec (RocketMQSerializable)
|
|
234
|
+
// Layout: code(2) language(1) version(2) opaque(4) flag(4)
|
|
235
|
+
// remark(int-len utf8) extFields(int-len map of short-key/int-value)
|
|
236
|
+
// ---------------------------------------------------------------------------
|
|
237
|
+
export class RocketMQSerializable {
|
|
238
|
+
// Write a UTF-8 string into `buf` at `offset` with a length prefix
|
|
239
|
+
// (short if useShortLength, else int). Returns the new offset.
|
|
240
|
+
static writeStr(buf, offset, useShortLength, s) {
|
|
241
|
+
const bs = (s == null) ? Buffer.alloc(0) : Buffer.from(String(s), 'utf-8');
|
|
242
|
+
const n = bs.length;
|
|
243
|
+
let o = offset;
|
|
244
|
+
if (useShortLength) {
|
|
245
|
+
buf.writeUInt16BE(n, o);
|
|
246
|
+
o += 2;
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
buf.writeUInt32BE(n, o);
|
|
250
|
+
o += 4;
|
|
251
|
+
}
|
|
252
|
+
bs.copy(buf, o);
|
|
253
|
+
o += n;
|
|
254
|
+
return o;
|
|
255
|
+
}
|
|
256
|
+
static readStr(buf, offset, useShortLength) {
|
|
257
|
+
let n, o = offset;
|
|
258
|
+
if (useShortLength) {
|
|
259
|
+
n = buf.readUInt16BE(o);
|
|
260
|
+
o += 2;
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
n = buf.readUInt32BE(o);
|
|
264
|
+
o += 4;
|
|
265
|
+
}
|
|
266
|
+
if (n === 0)
|
|
267
|
+
return [null, o];
|
|
268
|
+
const s = buf.slice(o, o + n).toString('utf-8');
|
|
269
|
+
return [s, o + n];
|
|
270
|
+
}
|
|
271
|
+
static mapSerialize(mapData) {
|
|
272
|
+
if (!mapData || Object.keys(mapData).length === 0)
|
|
273
|
+
return null;
|
|
274
|
+
const entries = [];
|
|
275
|
+
let total = 0;
|
|
276
|
+
for (const [k, v] of Object.entries(mapData)) {
|
|
277
|
+
if (k == null || v == null)
|
|
278
|
+
continue;
|
|
279
|
+
const kb = Buffer.from(String(k), 'utf-8');
|
|
280
|
+
const vb = Buffer.from(String(v), 'utf-8');
|
|
281
|
+
total += 2 + kb.length + 4 + vb.length;
|
|
282
|
+
entries.push([kb, vb]);
|
|
283
|
+
}
|
|
284
|
+
const out = Buffer.alloc(total);
|
|
285
|
+
let o = 0;
|
|
286
|
+
for (const [kb, vb] of entries) {
|
|
287
|
+
o = RocketMQSerializable.writeStr(out, o, true, kb);
|
|
288
|
+
o = RocketMQSerializable.writeStr(out, o, false, vb);
|
|
289
|
+
}
|
|
290
|
+
return out;
|
|
291
|
+
}
|
|
292
|
+
static calTotalLen(remark, ext) {
|
|
293
|
+
const remarkLen = remark ? Buffer.byteLength(remark, 'utf-8') : 0;
|
|
294
|
+
const extLen = ext ? ext.length : 0;
|
|
295
|
+
return 2 + 1 + 2 + 4 + 4 + 4 + remarkLen + 4 + extLen;
|
|
296
|
+
}
|
|
297
|
+
static rocketMqProtocolEncode(cmd) {
|
|
298
|
+
const remark = cmd.remark;
|
|
299
|
+
const remarkBytes = remark ? Buffer.from(remark, 'utf-8') : null;
|
|
300
|
+
const extFieldsBytes = RocketMQSerializable.mapSerialize(cmd.extFields);
|
|
301
|
+
const totalLen = RocketMQSerializable.calTotalLen(remark, extFieldsBytes);
|
|
302
|
+
const buf = Buffer.alloc(totalLen);
|
|
303
|
+
let o = 0;
|
|
304
|
+
buf.writeInt16BE(cmd.code & 0xffff, o);
|
|
305
|
+
o += 2;
|
|
306
|
+
buf.writeUInt8(cmd.language & 0xff, o);
|
|
307
|
+
o += 1;
|
|
308
|
+
buf.writeInt16BE(cmd.version & 0xffff, o);
|
|
309
|
+
o += 2;
|
|
310
|
+
buf.writeInt32BE(cmd.opaque | 0, o);
|
|
311
|
+
o += 4;
|
|
312
|
+
buf.writeInt32BE(cmd.flag | 0, o);
|
|
313
|
+
o += 4;
|
|
314
|
+
if (remarkBytes) {
|
|
315
|
+
buf.writeInt32BE(remarkBytes.length, o);
|
|
316
|
+
o += 4;
|
|
317
|
+
remarkBytes.copy(buf, o);
|
|
318
|
+
o += remarkBytes.length;
|
|
319
|
+
}
|
|
320
|
+
else {
|
|
321
|
+
buf.writeInt32BE(0, o);
|
|
322
|
+
o += 4;
|
|
323
|
+
}
|
|
324
|
+
if (extFieldsBytes) {
|
|
325
|
+
buf.writeInt32BE(extFieldsBytes.length, o);
|
|
326
|
+
o += 4;
|
|
327
|
+
extFieldsBytes.copy(buf, o);
|
|
328
|
+
o += extFieldsBytes.length;
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
buf.writeInt32BE(0, o);
|
|
332
|
+
o += 4;
|
|
333
|
+
}
|
|
334
|
+
return buf;
|
|
335
|
+
}
|
|
336
|
+
static mapDeserialize(buf, offset, length) {
|
|
337
|
+
const mapData = {};
|
|
338
|
+
let o = offset;
|
|
339
|
+
const end = offset + length;
|
|
340
|
+
while (o < end) {
|
|
341
|
+
let k, v;
|
|
342
|
+
[k, o] = RocketMQSerializable.readStr(buf, o, true);
|
|
343
|
+
[v, o] = RocketMQSerializable.readStr(buf, o, false);
|
|
344
|
+
if (k != null && v != null)
|
|
345
|
+
mapData[k] = v;
|
|
346
|
+
}
|
|
347
|
+
return [mapData, o];
|
|
348
|
+
}
|
|
349
|
+
static rocketMqProtocolDecode(headerBytes) {
|
|
350
|
+
const buf = Buffer.isBuffer(headerBytes) ? headerBytes : Buffer.from(headerBytes);
|
|
351
|
+
let o = 0;
|
|
352
|
+
let code = buf.readInt16BE(o);
|
|
353
|
+
o += 2;
|
|
354
|
+
let language = buf.readUInt8(o);
|
|
355
|
+
o += 1;
|
|
356
|
+
let version = buf.readInt16BE(o);
|
|
357
|
+
o += 2;
|
|
358
|
+
let opaque = buf.readInt32BE(o);
|
|
359
|
+
o += 4;
|
|
360
|
+
let flag = buf.readInt32BE(o);
|
|
361
|
+
o += 4;
|
|
362
|
+
let remark, extFields = null;
|
|
363
|
+
[remark, o] = RocketMQSerializable.readStr(buf, o, false);
|
|
364
|
+
const extLen = buf.readInt32BE(o);
|
|
365
|
+
o += 4;
|
|
366
|
+
if (extLen > 0) {
|
|
367
|
+
[extFields, o] = RocketMQSerializable.mapDeserialize(buf, o, extLen);
|
|
368
|
+
}
|
|
369
|
+
return { code: code & 0xffff, language, version: version & 0xffff, opaque, flag, remark, extFields: extFields || {} };
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
export default { RemotingSerializable, RocketMQSerializable, fastjsonLoads, decodeMessageQueueKey };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
export interface SocksProxyConfig {
|
|
3
|
+
addr: string;
|
|
4
|
+
username?: string | null;
|
|
5
|
+
password?: string | null;
|
|
6
|
+
version?: number | string | null;
|
|
7
|
+
}
|
|
8
|
+
export declare const SOCKS5_METHOD_NO_AUTH = 0;
|
|
9
|
+
export declare const SOCKS5_METHOD_GSSAPI = 1;
|
|
10
|
+
export declare const SOCKS5_METHOD_USER_PASS = 2;
|
|
11
|
+
export declare const SOCKS5_METHOD_NO_ACCEPTABLE = 255;
|
|
12
|
+
export declare const SOCKS4_GRANTED = 90;
|
|
13
|
+
export declare const SOCKS5_REPLY_NAMES: Record<number, string>;
|
|
14
|
+
export declare function socks5ReplyName(code: number): string;
|
|
15
|
+
export declare function proxyVersion(proxy: SocksProxyConfig): 4 | 5;
|
|
16
|
+
export declare function parseProxyAddr(addr: string | null | undefined): [string, number];
|
|
17
|
+
export declare function buildSocks5Greeting(withUserPass: boolean): Buffer;
|
|
18
|
+
export declare function parseSocks5MethodSelection(buf: Buffer): number;
|
|
19
|
+
export declare function buildSocks5UserPassAuth(username: string, password: string): Buffer;
|
|
20
|
+
export declare function parseSocks5UserPassReply(buf: Buffer): void;
|
|
21
|
+
export declare function buildSocks5Connect(host: string, port: number): Buffer;
|
|
22
|
+
export declare function parseSocks5ConnectReply(buf: Buffer): {
|
|
23
|
+
boundAddr: string;
|
|
24
|
+
boundPort: number;
|
|
25
|
+
};
|
|
26
|
+
export declare function buildSocks4Connect(host: string, port: number, userid?: string): Buffer;
|
|
27
|
+
export declare function parseSocks4ConnectReply(buf: Buffer): void;
|
|
28
|
+
export declare function parseSocksProxyConfig(json: string | null | undefined): SocksProxyConfig | null;
|
|
29
|
+
export declare function socksHandshake(socket: any, proxy: SocksProxyConfig, targetHost: string, targetPort: number, timeoutMillis?: number): Promise<void>;
|