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