whatap 1.0.1 → 1.0.2
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.md +32 -78
- package/lib/conf/conf-sys-mon.js +101 -0
- package/lib/conf/config-default.js +10 -3
- package/lib/conf/configure.js +369 -349
- package/lib/conf/license.js +1 -1
- package/lib/control/cmd-config.js +24 -0
- package/lib/control/control-handler.js +367 -0
- package/lib/control/packagectr-helper.js +34 -3
- package/lib/core/agent.js +176 -882
- package/lib/core/interceptor.js +6 -6
- package/lib/core/request-agent.js +27 -0
- package/lib/core/shimmer.js +82 -36
- package/lib/counter/counter-manager.js +79 -8
- package/lib/counter/meter/meter-activex.js +67 -0
- package/lib/counter/meter/meter-httpc.js +57 -0
- package/lib/counter/meter/meter-resource.js +9 -0
- package/lib/counter/meter/meter-service.js +168 -0
- package/lib/counter/meter/meter-socket.io.js +51 -0
- package/lib/counter/meter/meter-sql.js +71 -0
- package/lib/counter/meter/meter-users.js +58 -0
- package/lib/counter/meter.js +183 -0
- package/lib/counter/task/activetransaction.js +68 -17
- package/lib/counter/task/agentinfo.js +107 -0
- package/lib/{system → counter/task}/gc-action.js +27 -74
- package/lib/counter/task/gcstat.js +34 -0
- package/lib/counter/task/heapmem.js +25 -0
- package/lib/counter/task/httpc.js +76 -0
- package/lib/counter/task/metering-info.js +125 -0
- package/lib/counter/task/proc-cpu.js +29 -0
- package/lib/counter/task/realtimeuser.js +31 -0
- package/lib/counter/task/res/systemECSTask.js +39 -0
- package/lib/counter/task/res/systemKubeTask.js +53 -0
- package/lib/counter/task/res/util/awsEcsClientThread.js +218 -0
- package/lib/counter/task/res/util/linuxProcStatUtil.js +14 -0
- package/lib/counter/task/res-sys-cpu.js +62 -0
- package/lib/counter/task/service.js +202 -0
- package/lib/counter/task/socketio.js +30 -0
- package/lib/counter/task/sql.js +105 -0
- package/lib/counter/task/systemperf.js +43 -0
- package/lib/data/datapack-sender.js +289 -0
- package/lib/data/dataprofile-agent.js +162 -0
- package/lib/data/datatext-agent.js +135 -0
- package/lib/data/event-level.js +15 -0
- package/lib/data/test.js +49 -0
- package/lib/data/zipprofile.js +197 -0
- package/lib/env/constants.js +21 -0
- package/lib/error/error-handler.js +437 -0
- package/lib/io/data-inputx.js +13 -3
- package/lib/io/data-outputx.js +268 -206
- package/lib/kube/kube-client.js +144 -0
- package/lib/lang/text-types.js +58 -0
- package/lib/logger.js +6 -6
- package/lib/logsink/line-log-util.js +87 -0
- package/lib/logsink/line-log.js +12 -0
- package/lib/logsink/log-sender.js +78 -0
- package/lib/logsink/log-tracer.js +40 -0
- package/lib/logsink/sender-util.js +56 -0
- package/lib/logsink/zip/zip-send.js +177 -0
- package/lib/net/netflag.js +55 -0
- package/lib/net/receiver.js +66 -0
- package/lib/net/security-master.js +139 -20
- package/lib/net/sender.js +141 -0
- package/lib/net/tcp-return.js +18 -0
- package/lib/net/tcp-session.js +286 -0
- package/lib/net/tcpreq-client-proxy.js +70 -0
- package/lib/net/tcprequest-mgr.js +58 -0
- package/lib/observers/apollo-server-observer.js +33 -27
- package/lib/observers/cluster-observer.js +22 -0
- package/lib/observers/express-observer.js +215 -0
- package/lib/observers/file-observer.js +184 -0
- package/lib/observers/global-observer.js +155 -80
- package/lib/observers/grpc-observer.js +336 -0
- package/lib/observers/http-observer.js +666 -236
- package/lib/observers/maria-observer.js +204 -362
- package/lib/observers/memcached-observer.js +56 -0
- package/lib/observers/mongo-observer.js +317 -0
- package/lib/observers/mongodb-observer.js +169 -226
- package/lib/observers/mongoose-observer.js +518 -323
- package/lib/observers/mssql-observer.js +177 -418
- package/lib/observers/mysql-observer.js +342 -449
- package/lib/observers/mysql2-observer.js +396 -358
- package/lib/observers/net-observer.js +77 -0
- package/lib/observers/oracle-observer.js +559 -384
- package/lib/observers/pgsql-observer.js +231 -489
- package/lib/observers/prisma-observer.js +303 -92
- package/lib/observers/process-observer.js +79 -35
- package/lib/observers/promise-observer.js +31 -0
- package/lib/observers/redis-observer.js +166 -331
- package/lib/observers/schedule-observer.js +67 -0
- package/lib/observers/socket.io-observer.js +226 -187
- package/lib/observers/stream-observer.js +19 -0
- package/lib/observers/thrift-observer.js +197 -0
- package/lib/observers/websocket-observer.js +175 -301
- package/lib/pack/activestack-pack.js +55 -0
- package/lib/pack/apenum.js +8 -0
- package/lib/pack/counter-pack.js +3 -0
- package/lib/pack/errorsnap-pack.js +69 -0
- package/lib/pack/event-pack.js +54 -0
- package/lib/pack/hitmap-pack.js +63 -0
- package/lib/pack/hitmap-pack1.js +152 -0
- package/lib/pack/log-sink-pack.js +14 -52
- package/lib/pack/netstat.js +15 -0
- package/lib/pack/otype.js +7 -0
- package/lib/pack/profile-pack.js +49 -0
- package/lib/pack/realtimeuser-pack.js +41 -0
- package/lib/pack/stat-general-pack.js +96 -0
- package/lib/pack/staterror-pack.js +120 -0
- package/lib/pack/stathttpc-pack.js +66 -0
- package/lib/pack/stathttpc-rec.js +78 -0
- package/lib/pack/statremote-pack.js +46 -0
- package/lib/pack/statservice-pack.js +63 -0
- package/lib/pack/statservice-pack1.js +88 -0
- package/lib/pack/statservice-rec.js +292 -0
- package/lib/pack/statservice-rec_dep.js +151 -0
- package/lib/pack/statsql-pack.js +69 -0
- package/lib/pack/statsql-rec.js +100 -0
- package/lib/pack/statuseragent-pack.js +44 -0
- package/lib/pack/tagcount-pack.js +4 -4
- package/lib/pack/tagctr.js +15 -0
- package/lib/pack/text-pack.js +50 -0
- package/lib/pack/time-count.js +25 -0
- package/lib/pack/websocket.js +15 -0
- package/lib/pack/zip-pack.js +70 -0
- package/lib/pii/pii-item.js +31 -0
- package/lib/pii/pii-mask.js +174 -0
- package/lib/plugin/plugin-loadermanager.js +57 -0
- package/lib/plugin/plugin.js +75 -0
- package/lib/service/tx-record.js +332 -0
- package/lib/stat/stat-error.js +116 -0
- package/lib/stat/stat-httpc.js +98 -0
- package/lib/stat/stat-remote-ip.js +46 -0
- package/lib/stat/stat-remote-ipurl.js +88 -0
- package/lib/stat/stat-sql.js +113 -0
- package/lib/stat/stat-tranx.js +58 -0
- package/lib/stat/stat-tx-caller.js +160 -0
- package/lib/stat/stat-tx-domain.js +111 -0
- package/lib/stat/stat-tx-referer.js +112 -0
- package/lib/stat/stat-useragent.js +48 -0
- package/lib/stat/timingsender.js +76 -0
- package/lib/step/activestack-step.js +38 -0
- package/lib/step/dbc-step.js +36 -0
- package/lib/step/http-stepx.js +67 -0
- package/lib/step/message-step.js +40 -0
- package/lib/step/method-stepx.js +45 -0
- package/lib/step/resultset-step.js +40 -0
- package/lib/step/securemsg-step.js +44 -0
- package/lib/step/socket-step.js +46 -0
- package/lib/step/sql-stepx.js +68 -0
- package/lib/step/sqlxtype.js +16 -0
- package/lib/step/step.js +66 -0
- package/lib/step/stepenum.js +54 -0
- package/lib/topology/link.js +63 -0
- package/lib/topology/nodeinfo.js +123 -0
- package/lib/topology/status-detector.js +111 -0
- package/lib/trace/trace-context-manager.js +113 -25
- package/lib/trace/trace-context.js +21 -7
- package/lib/trace/trace-httpc.js +17 -11
- package/lib/trace/trace-sql.js +29 -21
- package/lib/util/anylist.js +103 -0
- package/lib/util/cardinality/hyperloglog.js +106 -0
- package/lib/util/cardinality/murmurhash.js +31 -0
- package/lib/util/cardinality/registerset.js +75 -0
- package/lib/util/errordata.js +21 -0
- package/lib/util/escape-literal-sql.js +5 -5
- package/lib/util/hashutil.js +18 -18
- package/lib/util/iputil_x.js +527 -0
- package/lib/util/keygen.js +0 -3
- package/lib/util/kube-util.js +73 -0
- package/lib/util/linkedset.js +1 -2
- package/lib/util/nodeutil.js +2 -1
- package/lib/util/paramsecurity.js +80 -0
- package/lib/util/pre-process.js +13 -0
- package/lib/util/process-seq.js +166 -0
- package/lib/util/property-util.js +36 -0
- package/lib/util/request-queue.js +70 -0
- package/lib/util/requestdouble-queue.js +72 -0
- package/lib/util/resourceprofile.js +157 -0
- package/lib/util/stop-watch.js +30 -0
- package/lib/util/system-util.js +10 -0
- package/lib/util/userid-util.js +57 -0
- package/lib/value/map-value.js +3 -2
- package/package.json +9 -4
- package/whatap.conf +1 -4
- package/agent/darwin/arm64/whatap_nodejs +0 -0
- package/agent/linux/amd64/whatap_nodejs +0 -0
- package/agent/linux/arm64/whatap_nodejs +0 -0
- package/build.txt +0 -4
- package/lib/observers/ioredis-observer.js +0 -294
- package/lib/udp/async_sender.js +0 -119
- package/lib/udp/index.js +0 -17
- package/lib/udp/packet_enum.js +0 -52
- package/lib/udp/packet_queue.js +0 -69
- package/lib/udp/packet_type_enum.js +0 -33
- package/lib/udp/param_def.js +0 -72
- package/lib/udp/udp_session.js +0 -336
- package/lib/util/sql-util.js +0 -178
- package/lib/util/trace-helper.js +0 -91
- package/lib/util/transfer.js +0 -58
package/lib/io/data-outputx.js
CHANGED
|
@@ -4,21 +4,23 @@
|
|
|
4
4
|
* can be found in the LICENSE file.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
var
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
7
|
+
var constants = require('../env/constants'),
|
|
8
|
+
util = require('../util/utils'),
|
|
9
|
+
Long = require('long'),
|
|
10
|
+
Logger = require('../logger');
|
|
11
|
+
|
|
12
|
+
var BYTE1_MAX_UVALUE = 0xff,
|
|
13
|
+
BYTE2_MAX_UVALUE = 0xffff,
|
|
14
|
+
BYTE4_MAX_UVALUE = 0xffffffff,
|
|
15
|
+
BYTE8_MAX_UVALUE = 0xffffffffffffffff,
|
|
16
|
+
BYTE1_MAX_VALUE = Math.floor( BYTE1_MAX_UVALUE / 2 ),
|
|
17
|
+
BYTE1_MIN_VALUE = Math.floor( -BYTE1_MAX_UVALUE / 2 ),
|
|
18
|
+
BYTE2_MAX_VALUE = Math.floor( BYTE2_MAX_UVALUE / 2 ),
|
|
19
|
+
BYTE2_MIN_VALUE = Math.floor( -BYTE2_MAX_UVALUE / 2 ),
|
|
20
|
+
BYTE4_MAX_VALUE = Math.floor( BYTE4_MAX_UVALUE / 2 ),
|
|
21
|
+
BYTE4_MIN_VALUE = Math.floor( -BYTE4_MAX_UVALUE / 2 ),
|
|
22
|
+
BYTE8_MAX_VALUE = Math.floor( BYTE8_MAX_UVALUE / 2 ),
|
|
23
|
+
BYTE8_MIN_VALUE = Math.floor( -BYTE8_MAX_UVALUE / 2 );
|
|
22
24
|
|
|
23
25
|
function isNumOk(n) {
|
|
24
26
|
return n != null && n !== undefined && isNaN(n) == false;
|
|
@@ -31,9 +33,9 @@ function isNotNull(n) {
|
|
|
31
33
|
function DataOutputX(size) {
|
|
32
34
|
this.buf = undefined;
|
|
33
35
|
if (size == undefined) {
|
|
34
|
-
this.buf = Buffer.alloc(32, 0);
|
|
36
|
+
this.buf = Buffer.alloc(32 , 0);
|
|
35
37
|
} else {
|
|
36
|
-
this.buf = Buffer.alloc(size, 0);
|
|
38
|
+
this.buf = Buffer.alloc(size , 0);
|
|
37
39
|
}
|
|
38
40
|
this.offset = 0;
|
|
39
41
|
}
|
|
@@ -57,8 +59,9 @@ DataOutputX.prototype.grow = function(minCapacity) {
|
|
|
57
59
|
newCapacity = 2147483647;
|
|
58
60
|
}
|
|
59
61
|
var oldBuffer = this.buf;
|
|
60
|
-
this.buf = Buffer.alloc(newCapacity,
|
|
62
|
+
this.buf = Buffer.alloc(newCapacity,0);
|
|
61
63
|
oldBuffer.copy(this.buf);
|
|
64
|
+
|
|
62
65
|
};
|
|
63
66
|
|
|
64
67
|
DataOutputX.prototype.reset = function() {
|
|
@@ -66,17 +69,16 @@ DataOutputX.prototype.reset = function() {
|
|
|
66
69
|
};
|
|
67
70
|
|
|
68
71
|
DataOutputX.prototype.size = function() {
|
|
69
|
-
return this.
|
|
72
|
+
return this.buf.length;
|
|
70
73
|
};
|
|
71
74
|
|
|
72
|
-
DataOutputX.prototype.writeIntBytes = function(b)
|
|
73
|
-
if
|
|
75
|
+
DataOutputX.prototype.writeIntBytes = function(b){
|
|
76
|
+
if( !b || b.length == 0 ){
|
|
74
77
|
this.writeInt(0);
|
|
75
|
-
} else
|
|
78
|
+
} else{
|
|
76
79
|
this.writeInt(b.length);
|
|
77
80
|
this.writeBytes(b);
|
|
78
81
|
}
|
|
79
|
-
return this;
|
|
80
82
|
};
|
|
81
83
|
|
|
82
84
|
DataOutputX.prototype.writeShortBytes = function(b) {
|
|
@@ -89,7 +91,7 @@ DataOutputX.prototype.writeBlob = function(value) {
|
|
|
89
91
|
if (isNotNull(value) == false) {
|
|
90
92
|
this.writeByte(0);
|
|
91
93
|
} else {
|
|
92
|
-
if
|
|
94
|
+
if((value instanceof Buffer) == false) {
|
|
93
95
|
throw new Error('Write Blob parameter must be buffer instance');
|
|
94
96
|
}
|
|
95
97
|
var len = value.length;
|
|
@@ -113,16 +115,17 @@ DataOutputX.prototype.copy = function(inputBuff) {
|
|
|
113
115
|
this.ensureCapacity(this.offset + inputBuff.length);
|
|
114
116
|
inputBuff.copy(this.buf, this.offset, 0, inputBuff.length);
|
|
115
117
|
this.offset += inputBuff.length;
|
|
118
|
+
inputBuff = null;
|
|
119
|
+
|
|
116
120
|
};
|
|
117
121
|
|
|
118
122
|
DataOutputX.prototype.toByteArray = function() {
|
|
119
123
|
var returnBuffer = Buffer.alloc(this.offset);
|
|
120
|
-
this.buf.copy(returnBuffer
|
|
124
|
+
this.buf.copy(returnBuffer);
|
|
121
125
|
return returnBuffer;
|
|
122
126
|
};
|
|
123
127
|
|
|
124
128
|
DataOutputX.prototype.writeByte = function(b) {
|
|
125
|
-
b = b & 0xFF;
|
|
126
129
|
this.ensureCapacity(this.offset + 1);
|
|
127
130
|
this.buf[this.offset] = b;
|
|
128
131
|
this.offset += 1;
|
|
@@ -135,7 +138,7 @@ DataOutputX.prototype.writeBytes = function(bytes) {
|
|
|
135
138
|
}
|
|
136
139
|
|
|
137
140
|
this.ensureCapacity(this.offset + bytes.length);
|
|
138
|
-
for (var i = 0; i < bytes.length; i++) {
|
|
141
|
+
for ( var i = 0; i < bytes.length; i++) {
|
|
139
142
|
this.buf[this.offset] = bytes[i];
|
|
140
143
|
this.offset += 1;
|
|
141
144
|
}
|
|
@@ -144,51 +147,55 @@ DataOutputX.prototype.writeBytes = function(bytes) {
|
|
|
144
147
|
};
|
|
145
148
|
|
|
146
149
|
DataOutputX.prototype.writeDecimal = function(value) {
|
|
150
|
+
if(value instanceof Long) {
|
|
151
|
+
this.writeByte(8);
|
|
152
|
+
this.writeLong(value);
|
|
153
|
+
return this;
|
|
154
|
+
}
|
|
155
|
+
|
|
147
156
|
if (isNumOk(value) == false) {
|
|
148
157
|
this.writeByte(0);
|
|
149
|
-
} else if (
|
|
158
|
+
} else if (constants.numType.INT8_MIN <= value
|
|
159
|
+
&& value <= constants.numType.INT8_MAX) {
|
|
150
160
|
this.writeByte(1);
|
|
151
|
-
this.
|
|
152
|
-
} else if (
|
|
161
|
+
this.writeInt8(value);
|
|
162
|
+
} else if (constants.numType.INT16_MIN <= value
|
|
163
|
+
&& value <= constants.numType.INT16_MAX) {
|
|
153
164
|
this.writeByte(2);
|
|
154
|
-
this.
|
|
155
|
-
} else if (
|
|
165
|
+
this.writeInt16BE(value);
|
|
166
|
+
} else if (constants.numType.INT24_MIN <= value
|
|
167
|
+
&& value <= constants.numType.INT24_MAX) {
|
|
156
168
|
this.writeByte(3);
|
|
157
|
-
this.
|
|
158
|
-
} else if (
|
|
169
|
+
this.writeInt24BE(value);
|
|
170
|
+
} else if (constants.numType.INT32_MIN <= value
|
|
171
|
+
&& value <= constants.numType.INT32_MAX) {
|
|
159
172
|
this.writeByte(4);
|
|
160
|
-
this.
|
|
161
|
-
} else if
|
|
173
|
+
this.writeInt32BE(value);
|
|
174
|
+
} else if(constants.numType.INT40_MIN <= value && value <=
|
|
175
|
+
constants.numType.INT40_MAX) {
|
|
162
176
|
this.writeByte(5);
|
|
163
|
-
this.
|
|
164
|
-
} else if (
|
|
177
|
+
this.writeInt40BE(value);
|
|
178
|
+
} else if (constants.numType.INT64_MIN <= value
|
|
179
|
+
&& value <= constants.numType.INT64_MAX) {
|
|
180
|
+
var longVal = Long.fromNumber(value);
|
|
165
181
|
this.writeByte(8);
|
|
166
|
-
this.writeLong(
|
|
182
|
+
this.writeLong(longVal);
|
|
167
183
|
}
|
|
168
184
|
return this;
|
|
169
185
|
};
|
|
170
186
|
|
|
171
|
-
DataOutputX.prototype.write = function(value)
|
|
172
|
-
|
|
173
|
-
this.ensureCapacity(this.offset + value.length);
|
|
174
|
-
value.copy(this.buf, this.offset);
|
|
175
|
-
this.offset += value.length;
|
|
176
|
-
} else if (Array.isArray(value)) {
|
|
177
|
-
this.writeBytes(value);
|
|
178
|
-
}
|
|
179
|
-
return this;
|
|
187
|
+
DataOutputX.prototype.write = function(value /* byte[] */, off /* int */, len /* int */){
|
|
188
|
+
this.writeBytes(value);
|
|
180
189
|
};
|
|
181
190
|
|
|
182
|
-
DataOutputX.prototype.writeInt = function(value)
|
|
191
|
+
DataOutputX.prototype.writeInt = function(value){
|
|
183
192
|
this.writeInt32BE(value);
|
|
184
|
-
return this;
|
|
185
193
|
};
|
|
186
194
|
|
|
187
195
|
DataOutputX.prototype.writeInt8 = function(value) {
|
|
188
196
|
if (isNumOk(value) == false) {
|
|
189
197
|
value = 0;
|
|
190
198
|
}
|
|
191
|
-
value = value & 0xFF;
|
|
192
199
|
this.ensureCapacity(this.offset + 1);
|
|
193
200
|
this.buf[this.offset] = value;
|
|
194
201
|
this.offset += 1;
|
|
@@ -199,37 +206,42 @@ DataOutputX.prototype.writeUInt8 = function(value) {
|
|
|
199
206
|
if (isNumOk(value) == false) {
|
|
200
207
|
value = 0;
|
|
201
208
|
}
|
|
202
|
-
value = value & 0xFF;
|
|
203
209
|
this.ensureCapacity(this.offset + 1);
|
|
204
|
-
this.buf
|
|
210
|
+
// this.buf[this.offset] = value;
|
|
211
|
+
this.buf.writeUInt8(value,this.offset);
|
|
205
212
|
this.offset += 1;
|
|
206
213
|
return this;
|
|
207
214
|
};
|
|
208
215
|
|
|
209
216
|
DataOutputX.prototype.writeShort = function(value) {
|
|
217
|
+
this.writeInt16BE(value);
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
DataOutputX.prototype.writeInt16BE = function(value) {
|
|
210
221
|
if (isNumOk(value) == false) {
|
|
211
222
|
value = 0;
|
|
212
223
|
}
|
|
213
|
-
value = value & 0xFFFF;
|
|
214
224
|
this.ensureCapacity(this.offset + 2);
|
|
215
|
-
this.buf.
|
|
225
|
+
this.buf.writeInt16BE(value, this.offset);
|
|
216
226
|
this.offset += 2;
|
|
217
227
|
return this;
|
|
218
228
|
};
|
|
219
229
|
|
|
220
|
-
DataOutputX.prototype.writeInt16BE = function(value) {
|
|
221
|
-
return this.writeShort(value);
|
|
222
|
-
};
|
|
223
|
-
|
|
224
230
|
DataOutputX.prototype.writeUInt16BE = function(value) {
|
|
225
|
-
|
|
231
|
+
if (isNumOk(value) == false) {
|
|
232
|
+
value = 0;
|
|
233
|
+
}
|
|
234
|
+
this.ensureCapacity(this.offset + 2);
|
|
235
|
+
this.buf.writeUInt16BE(value, this.offset);
|
|
236
|
+
this.offset += 2;
|
|
237
|
+
return this;
|
|
226
238
|
};
|
|
227
239
|
|
|
228
|
-
DataOutputX.prototype.
|
|
240
|
+
DataOutputX.prototype.writeInt24BE = function(value) {
|
|
229
241
|
if (isNumOk(value) == false) {
|
|
230
242
|
value = 0;
|
|
231
243
|
}
|
|
232
|
-
this.ensureCapacity(this.offset +
|
|
244
|
+
this.ensureCapacity(this.offset + 1);
|
|
233
245
|
this.buf[this.offset] = (value >>> 16) & 0xff;
|
|
234
246
|
this.buf[this.offset + 1] = (value >>> 8) & 0xff;
|
|
235
247
|
this.buf[this.offset + 2] = (value >>> 0) & 0xff;
|
|
@@ -237,85 +249,87 @@ DataOutputX.prototype.writeInt3 = function(value) {
|
|
|
237
249
|
return this;
|
|
238
250
|
};
|
|
239
251
|
|
|
240
|
-
DataOutputX.prototype.writeInt24BE = function(value) {
|
|
241
|
-
return this.writeInt3(value);
|
|
242
|
-
};
|
|
243
|
-
|
|
244
252
|
DataOutputX.prototype.writeInt32BE = function(value) {
|
|
245
253
|
if (isNumOk(value) == false) {
|
|
246
254
|
value = 0;
|
|
247
255
|
}
|
|
248
|
-
// Convert to unsigned 32-bit integer to handle negative values
|
|
249
|
-
value = (value & 0xFFFFFFFF) >>> 0;
|
|
250
256
|
this.ensureCapacity(this.offset + 4);
|
|
251
|
-
this.buf.
|
|
257
|
+
this.buf.writeInt32BE(value, this.offset);
|
|
252
258
|
this.offset += 4;
|
|
253
259
|
return this;
|
|
254
260
|
};
|
|
255
261
|
|
|
256
262
|
DataOutputX.prototype.writeUInt32BE = function(value) {
|
|
257
|
-
return this.writeInt32BE(value);
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
DataOutputX.prototype.writeLong5 = function(value) {
|
|
261
263
|
if (isNumOk(value) == false) {
|
|
262
264
|
value = 0;
|
|
263
265
|
}
|
|
264
|
-
this.ensureCapacity(this.offset +
|
|
265
|
-
this.buf
|
|
266
|
-
this.
|
|
267
|
-
this.buf[this.offset + 2] = ((value >> 16) & 0xFF);
|
|
268
|
-
this.buf[this.offset + 3] = ((value >> 8) & 0xFF);
|
|
269
|
-
this.buf[this.offset + 4] = ((value >> 0) & 0xFF);
|
|
270
|
-
this.offset += 5;
|
|
266
|
+
this.ensureCapacity(this.offset + 4);
|
|
267
|
+
this.buf.writeUInt32BE(value, this.offset);
|
|
268
|
+
this.offset += 4;
|
|
271
269
|
return this;
|
|
272
270
|
};
|
|
273
271
|
|
|
274
272
|
DataOutputX.prototype.writeInt40BE = function(value) {
|
|
275
|
-
return this.writeLong5(value);
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
// 새롭게 구현된 writeLong - Python 구현과 동일하게 작동
|
|
279
|
-
DataOutputX.prototype.writeLong = function(value) {
|
|
280
273
|
if (isNumOk(value) == false) {
|
|
281
274
|
value = 0;
|
|
282
275
|
}
|
|
276
|
+
var lo = value % 0x100000000;
|
|
277
|
+
var hi = value / 0x100000000;
|
|
278
|
+
hi = hi | 0;
|
|
283
279
|
|
|
284
|
-
this.
|
|
280
|
+
this.writeByte((hi >>> 0) & 0xff);
|
|
281
|
+
this.writeByte((lo >>> 24) & 0xff);
|
|
282
|
+
this.writeByte((lo >>> 16) & 0xff);
|
|
283
|
+
this.writeByte((lo >>> 8) & 0xff);
|
|
284
|
+
this.writeByte((lo >>> 0) & 0xff);
|
|
285
285
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
// 음수든 양수든 BigInt로 변환하면 64비트 표현으로 보존됨
|
|
289
|
-
const bigValue = BigInt(value);
|
|
286
|
+
return this;
|
|
287
|
+
};
|
|
290
288
|
|
|
291
|
-
|
|
292
|
-
|
|
289
|
+
DataOutputX.prototype.writeLong = function(value){
|
|
290
|
+
var v = value;
|
|
291
|
+
if(typeof value == 'string'){
|
|
292
|
+
v = Long.fromString(value);
|
|
293
|
+
} else if(typeof value == 'number') {
|
|
294
|
+
v = Long.fromNumber(value);
|
|
295
|
+
}
|
|
293
296
|
|
|
294
|
-
|
|
295
|
-
this.
|
|
297
|
+
if(v.constructor == Long){
|
|
298
|
+
this.writeInt32BE(v.getHighBits())
|
|
299
|
+
this.writeInt32BE(v.getLowBits())
|
|
300
|
+
}else{
|
|
301
|
+
this.ensureCapacity(this.offset + 8);
|
|
296
302
|
this.offset += 8;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
let hi, lo;
|
|
301
|
-
if (value < 0) {
|
|
302
|
-
// 2의 보수 로직으로 음수 처리
|
|
303
|
-
const absValue = Math.abs(value + 1);
|
|
304
|
-
hi = ~Math.floor(absValue / 0x100000000) & 0xFFFFFFFF;
|
|
305
|
-
lo = ~(absValue % 0x100000000) & 0xFFFFFFFF;
|
|
306
|
-
} else {
|
|
307
|
-
hi = Math.floor(value / 0x100000000) & 0xFFFFFFFF;
|
|
308
|
-
lo = value % 0x100000000;
|
|
309
|
-
}
|
|
303
|
+
}
|
|
304
|
+
return this;
|
|
305
|
+
};
|
|
310
306
|
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
307
|
+
DataOutputX.prototype.writeInt64BE = function(value) {
|
|
308
|
+
if (isNumOk(value) == false) {
|
|
309
|
+
value = 0;
|
|
314
310
|
}
|
|
311
|
+
var lo = value % 0x10000000;
|
|
312
|
+
var hi = value / 0x10000000;
|
|
313
|
+
hi = hi | 0;
|
|
314
|
+
|
|
315
|
+
this.writeByte((hi >>> 24) & 0xff);
|
|
316
|
+
this.writeByte((hi >>> 16) & 0xff);
|
|
317
|
+
this.writeByte((hi >>> 8) & 0xff);
|
|
318
|
+
this.writeByte((hi >>> 0) & 0xff);
|
|
319
|
+
this.writeByte((lo >>> 24) & 0xff);
|
|
320
|
+
this.writeByte((lo >>> 16) & 0xff);
|
|
321
|
+
this.writeByte((lo >>> 8) & 0xff);
|
|
322
|
+
this.writeByte((lo >>> 0) & 0xff);
|
|
315
323
|
|
|
316
324
|
return this;
|
|
317
325
|
};
|
|
318
326
|
|
|
327
|
+
DataOutputX.prototype.writeTXID = function(int64) {
|
|
328
|
+
int64.copy(this.buf, this.offset);
|
|
329
|
+
this.offset += 8;
|
|
330
|
+
return this;
|
|
331
|
+
};
|
|
332
|
+
|
|
319
333
|
DataOutputX.prototype.writeFloat = function(value) {
|
|
320
334
|
if (isNumOk(value) == false) {
|
|
321
335
|
value = 0.0;
|
|
@@ -336,153 +350,201 @@ DataOutputX.prototype.writeDouble = function(value) {
|
|
|
336
350
|
return this;
|
|
337
351
|
};
|
|
338
352
|
|
|
353
|
+
DataOutputX.prototype.writeString = function(value) {
|
|
354
|
+
var length = value.length;
|
|
355
|
+
this.ensureCapacity(this.offset + length);
|
|
356
|
+
this.buf.write(value, this.offset, length);
|
|
357
|
+
this.offset += length;
|
|
358
|
+
return this;
|
|
359
|
+
|
|
360
|
+
};
|
|
361
|
+
|
|
339
362
|
DataOutputX.prototype.writeText = function(value) {
|
|
340
363
|
if (isNotNull(value) == false) {
|
|
341
364
|
this.writeByte(0);
|
|
342
365
|
} else {
|
|
343
|
-
const bytes = Buffer.from(value, 'utf-8');
|
|
344
|
-
const len = bytes.length;
|
|
345
366
|
|
|
346
|
-
if
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
367
|
+
if(typeof value === 'string') {
|
|
368
|
+
value = util.toUTF8(value);
|
|
369
|
+
}
|
|
370
|
+
if(Array.isArray(value)) {
|
|
371
|
+
var len = value.length;
|
|
372
|
+
if (len <= 253) {
|
|
373
|
+
this.writeUInt8(len);
|
|
374
|
+
this.writeBytes(value);
|
|
375
|
+
} else if (len <= 65535) {
|
|
376
|
+
this.writeUInt8(255);
|
|
377
|
+
this.writeUInt16BE(len);
|
|
378
|
+
this.writeBytes(value);
|
|
379
|
+
} else {
|
|
380
|
+
this.writeUInt8(254);
|
|
381
|
+
this.writeUInt32BE(len);
|
|
382
|
+
this.writeBytes(value);
|
|
383
|
+
}
|
|
353
384
|
} else {
|
|
354
|
-
this.
|
|
355
|
-
this.writeUInt32BE(len);
|
|
356
|
-
this.write(bytes);
|
|
385
|
+
this.writeByte(0);
|
|
357
386
|
}
|
|
358
387
|
}
|
|
359
388
|
return this;
|
|
360
389
|
};
|
|
361
390
|
|
|
362
|
-
DataOutputX.prototype.
|
|
363
|
-
|
|
364
|
-
|
|
391
|
+
DataOutputX.prototype.print = function() {
|
|
392
|
+
for ( var i = 0; i < this.offset; i++) {
|
|
393
|
+
console.log(i + ': ' + this.buf[i].toString(16));
|
|
365
394
|
}
|
|
395
|
+
};
|
|
366
396
|
|
|
367
|
-
|
|
368
|
-
|
|
397
|
+
DataOutputX.prototype.writePack = function(pack) {
|
|
398
|
+
this.writeInt16BE(pack.getPackType());
|
|
399
|
+
pack.write(this);
|
|
400
|
+
return this;
|
|
401
|
+
};
|
|
369
402
|
|
|
370
|
-
|
|
371
|
-
|
|
403
|
+
DataOutputX.prototype.writeValue = function(value) {
|
|
404
|
+
if(value == null){
|
|
405
|
+
// value = NullValue
|
|
406
|
+
}
|
|
407
|
+
try{
|
|
408
|
+
this.writeByte(value.getValueType());
|
|
409
|
+
value.write(this);
|
|
410
|
+
} catch (e){
|
|
411
|
+
Logger.printError('WHATAP-251', 'DataOutputX writeValue Error', e);
|
|
412
|
+
}
|
|
372
413
|
|
|
373
414
|
return this;
|
|
374
415
|
};
|
|
375
416
|
|
|
376
|
-
DataOutputX.prototype.
|
|
377
|
-
this.writeByte(
|
|
417
|
+
DataOutputX.prototype.writeStep = function(step) {
|
|
418
|
+
this.writeByte(step.getStepType());
|
|
419
|
+
step.write(this);
|
|
378
420
|
return this;
|
|
379
421
|
};
|
|
380
422
|
|
|
381
|
-
DataOutputX.prototype.
|
|
382
|
-
if
|
|
383
|
-
this.
|
|
423
|
+
DataOutputX.prototype.writeBoolean = function(value) {
|
|
424
|
+
if(typeof value == 'boolean') {
|
|
425
|
+
this.writeByte(value ? 1 : 0);
|
|
426
|
+
return this;
|
|
384
427
|
} else {
|
|
385
|
-
this.
|
|
386
|
-
|
|
387
|
-
this.writeFloat(values[i]);
|
|
388
|
-
}
|
|
428
|
+
this.writeByte(0);
|
|
429
|
+
return this;
|
|
389
430
|
}
|
|
390
|
-
return this;
|
|
391
431
|
};
|
|
392
432
|
|
|
393
|
-
DataOutputX.prototype.
|
|
394
|
-
if
|
|
433
|
+
DataOutputX.prototype.writeFloatArray = function(value) {
|
|
434
|
+
if(value == null || Array.isArray(value) == false) {
|
|
395
435
|
this.writeShort(0);
|
|
396
436
|
} else {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
437
|
+
var length = value.length;
|
|
438
|
+
this.writeShort(length);
|
|
439
|
+
for(var i=0; i<length; i++) {
|
|
440
|
+
this.writeFloat(value[i]);
|
|
400
441
|
}
|
|
401
442
|
}
|
|
402
443
|
return this;
|
|
403
444
|
};
|
|
404
445
|
|
|
405
|
-
DataOutputX.prototype.
|
|
406
|
-
if
|
|
446
|
+
DataOutputX.prototype.writeIntArray = function(value) {
|
|
447
|
+
if(value == null || Array.isArray(value) == false) {
|
|
407
448
|
this.writeShort(0);
|
|
408
449
|
} else {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
450
|
+
var length = value.length;
|
|
451
|
+
this.writeShort(length);
|
|
452
|
+
for(var i=0; i<length; i++) {
|
|
453
|
+
this.writeInt(value[i]);
|
|
412
454
|
}
|
|
413
455
|
}
|
|
414
456
|
return this;
|
|
415
457
|
};
|
|
416
458
|
|
|
417
|
-
DataOutputX.prototype.
|
|
418
|
-
if
|
|
459
|
+
DataOutputX.prototype.writeLongArray = function(value) {
|
|
460
|
+
if(value == null || Array.isArray(value) == false) {
|
|
419
461
|
this.writeShort(0);
|
|
420
462
|
} else {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
463
|
+
var length = value.length;
|
|
464
|
+
this.writeShort(length);
|
|
465
|
+
for(var i=0; i<length; i++) {
|
|
466
|
+
var long = value[i];
|
|
467
|
+
if(long instanceof Long) {
|
|
468
|
+
this.writeLong(value[i]);
|
|
469
|
+
} else {
|
|
470
|
+
this.writeLong(Long.fromInt(0));
|
|
471
|
+
}
|
|
424
472
|
}
|
|
425
473
|
}
|
|
426
|
-
return this;
|
|
427
474
|
};
|
|
428
475
|
|
|
429
|
-
DataOutputX.
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
476
|
+
DataOutputX.toBytes = function(v) {
|
|
477
|
+
var buf = new Array(4);
|
|
478
|
+
buf[0] = ((v >>> 24) & 0xFF);
|
|
479
|
+
buf[1] = ((v >>> 16) & 0xFF);
|
|
480
|
+
buf[2] = ((v >>> 8) & 0xFF);
|
|
481
|
+
buf[3] = ((v >>> 0) & 0xFF);
|
|
482
|
+
return buf;
|
|
435
483
|
};
|
|
436
484
|
|
|
437
|
-
DataOutputX.
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
if (ln_fmt) {
|
|
442
|
-
const remainder = this.offset % ln_fmt;
|
|
443
|
-
if (remainder !== 0) {
|
|
444
|
-
this.write(Buffer.alloc(ln_fmt - remainder));
|
|
445
|
-
}
|
|
485
|
+
DataOutputX.toBytesLong = function(value) {
|
|
486
|
+
var v = value;
|
|
487
|
+
if(v.constructor == String){
|
|
488
|
+
v = Long.fromString(value);
|
|
446
489
|
}
|
|
447
490
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
491
|
+
var tmp = Buffer.alloc(8);
|
|
492
|
+
if(v.constructor == Long){
|
|
493
|
+
tmp.writeInt32BE(v.getHighBits(), 0);
|
|
494
|
+
tmp.writeInt32BE(v.getLowBits(), 4);
|
|
495
|
+
}else{
|
|
496
|
+
tmp.writeInt32BE(0);
|
|
497
|
+
tmp.writeInt32BE(0);
|
|
455
498
|
}
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
499
|
+
var high = tmp.readInt32BE(0);
|
|
500
|
+
var low = tmp.readInt32BE(4);
|
|
501
|
+
return tmp;
|
|
502
|
+
};
|
|
503
|
+
|
|
504
|
+
// DataOutputX.toByteArray = function(v, byteLength){
|
|
505
|
+
// var buf;
|
|
506
|
+
// if( byteLength == 2 && (BYTE2_MIN_VALUE <= v && v <= BYTE2_MAX_VALUE) ){
|
|
507
|
+
// byteLength = byteLength || 2;
|
|
508
|
+
// buf = new Buffer(byteLength);
|
|
509
|
+
// buf[0] = ((v >>> 8) & 0xFF);
|
|
510
|
+
// buf[1] = ((v >>> 0) & 0xFF);
|
|
511
|
+
// }else if( byteLength == 4 && (BYTE4_MIN_VALUE <= v && v <= BYTE4_MAX_VALUE) ){
|
|
512
|
+
// byteLength = byteLength || 4;
|
|
513
|
+
// buf = new Buffer(byteLength);
|
|
514
|
+
// buf[0] = ((v >>> 24) & 0xFF);
|
|
515
|
+
// buf[1] = ((v >>> 16) & 0xFF);
|
|
516
|
+
// buf[2] = ((v >>> 8) & 0xFF);
|
|
517
|
+
// buf[3] = ((v >>> 0) & 0xFF);
|
|
518
|
+
// }else if( byteLength == 8 && (BYTE8_MIN_VALUE <= v && v <= BYTE8_MAX_VALUE) ){
|
|
519
|
+
// byteLength = byteLength || 8;
|
|
520
|
+
// buf = new Buffer(byteLength);
|
|
521
|
+
// buf[0] = (v >>> 56);
|
|
522
|
+
// buf[1] = (v >>> 48);
|
|
523
|
+
// buf[2] = (v >>> 40);
|
|
524
|
+
// buf[3] = (v >>> 32);
|
|
525
|
+
// buf[4] = (v >>> 24);
|
|
526
|
+
// buf[5] = (v >>> 16);
|
|
527
|
+
// buf[6] = (v >>> 8);
|
|
528
|
+
// buf[7] = (v >>> 0);
|
|
529
|
+
// }
|
|
530
|
+
// return buf;
|
|
531
|
+
// };
|
|
532
|
+
|
|
533
|
+
DataOutputX.set = function(dest, pos, src){
|
|
534
|
+
src.copy(dest, 0, pos, src.length);
|
|
535
|
+
return dest;
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
DataOutputX.toBytesPack = function(pack, fmtLen) {
|
|
539
|
+
if(fmtLen == undefined ) {
|
|
540
|
+
return new DataOutputX().writePack(pack).toByteArray();
|
|
541
|
+
}
|
|
542
|
+
var out = new DataOutputX().writePack(pack);
|
|
543
|
+
var remainder = out.size() % (fmtLen||0);
|
|
544
|
+
if (remainder != 0) {
|
|
545
|
+
out.write(Buffer.alloc(fmtLen - remainder));
|
|
462
546
|
}
|
|
463
|
-
|
|
464
|
-
return this;
|
|
465
|
-
};
|
|
466
|
-
|
|
467
|
-
DataOutputX.toBytes = function(v) {
|
|
468
|
-
const buf = Buffer.alloc(4);
|
|
469
|
-
buf.writeUInt32BE(v & 0xFFFFFFFF, 0);
|
|
470
|
-
return buf;
|
|
471
|
-
};
|
|
472
|
-
|
|
473
|
-
DataOutputX.toBytesLong = function(v) {
|
|
474
|
-
const buf = Buffer.alloc(8);
|
|
475
|
-
const hi = Math.floor(v / 0x100000000);
|
|
476
|
-
const lo = v % 0x100000000;
|
|
477
|
-
|
|
478
|
-
buf.writeUInt32BE(hi, 0);
|
|
479
|
-
buf.writeUInt32BE(lo, 4);
|
|
480
|
-
return buf;
|
|
481
|
-
};
|
|
482
|
-
|
|
483
|
-
DataOutputX.toBytesPack = function(pack, ln_fmt) {
|
|
484
|
-
const out = new DataOutputX().writePack(pack, ln_fmt);
|
|
485
547
|
return out.toByteArray();
|
|
486
|
-
}
|
|
548
|
+
}
|
|
487
549
|
|
|
488
550
|
module.exports = DataOutputX;
|