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.
Files changed (198) hide show
  1. package/README.md +32 -78
  2. package/lib/conf/conf-sys-mon.js +101 -0
  3. package/lib/conf/config-default.js +10 -3
  4. package/lib/conf/configure.js +369 -349
  5. package/lib/conf/license.js +1 -1
  6. package/lib/control/cmd-config.js +24 -0
  7. package/lib/control/control-handler.js +367 -0
  8. package/lib/control/packagectr-helper.js +34 -3
  9. package/lib/core/agent.js +176 -882
  10. package/lib/core/interceptor.js +6 -6
  11. package/lib/core/request-agent.js +27 -0
  12. package/lib/core/shimmer.js +82 -36
  13. package/lib/counter/counter-manager.js +79 -8
  14. package/lib/counter/meter/meter-activex.js +67 -0
  15. package/lib/counter/meter/meter-httpc.js +57 -0
  16. package/lib/counter/meter/meter-resource.js +9 -0
  17. package/lib/counter/meter/meter-service.js +168 -0
  18. package/lib/counter/meter/meter-socket.io.js +51 -0
  19. package/lib/counter/meter/meter-sql.js +71 -0
  20. package/lib/counter/meter/meter-users.js +58 -0
  21. package/lib/counter/meter.js +183 -0
  22. package/lib/counter/task/activetransaction.js +68 -17
  23. package/lib/counter/task/agentinfo.js +107 -0
  24. package/lib/{system → counter/task}/gc-action.js +27 -74
  25. package/lib/counter/task/gcstat.js +34 -0
  26. package/lib/counter/task/heapmem.js +25 -0
  27. package/lib/counter/task/httpc.js +76 -0
  28. package/lib/counter/task/metering-info.js +125 -0
  29. package/lib/counter/task/proc-cpu.js +29 -0
  30. package/lib/counter/task/realtimeuser.js +31 -0
  31. package/lib/counter/task/res/systemECSTask.js +39 -0
  32. package/lib/counter/task/res/systemKubeTask.js +53 -0
  33. package/lib/counter/task/res/util/awsEcsClientThread.js +218 -0
  34. package/lib/counter/task/res/util/linuxProcStatUtil.js +14 -0
  35. package/lib/counter/task/res-sys-cpu.js +62 -0
  36. package/lib/counter/task/service.js +202 -0
  37. package/lib/counter/task/socketio.js +30 -0
  38. package/lib/counter/task/sql.js +105 -0
  39. package/lib/counter/task/systemperf.js +43 -0
  40. package/lib/data/datapack-sender.js +289 -0
  41. package/lib/data/dataprofile-agent.js +162 -0
  42. package/lib/data/datatext-agent.js +135 -0
  43. package/lib/data/event-level.js +15 -0
  44. package/lib/data/test.js +49 -0
  45. package/lib/data/zipprofile.js +197 -0
  46. package/lib/env/constants.js +21 -0
  47. package/lib/error/error-handler.js +437 -0
  48. package/lib/io/data-inputx.js +13 -3
  49. package/lib/io/data-outputx.js +268 -206
  50. package/lib/kube/kube-client.js +144 -0
  51. package/lib/lang/text-types.js +58 -0
  52. package/lib/logger.js +6 -6
  53. package/lib/logsink/line-log-util.js +87 -0
  54. package/lib/logsink/line-log.js +12 -0
  55. package/lib/logsink/log-sender.js +78 -0
  56. package/lib/logsink/log-tracer.js +40 -0
  57. package/lib/logsink/sender-util.js +56 -0
  58. package/lib/logsink/zip/zip-send.js +177 -0
  59. package/lib/net/netflag.js +55 -0
  60. package/lib/net/receiver.js +66 -0
  61. package/lib/net/security-master.js +139 -20
  62. package/lib/net/sender.js +141 -0
  63. package/lib/net/tcp-return.js +18 -0
  64. package/lib/net/tcp-session.js +286 -0
  65. package/lib/net/tcpreq-client-proxy.js +70 -0
  66. package/lib/net/tcprequest-mgr.js +58 -0
  67. package/lib/observers/apollo-server-observer.js +33 -27
  68. package/lib/observers/cluster-observer.js +22 -0
  69. package/lib/observers/express-observer.js +215 -0
  70. package/lib/observers/file-observer.js +184 -0
  71. package/lib/observers/global-observer.js +155 -80
  72. package/lib/observers/grpc-observer.js +336 -0
  73. package/lib/observers/http-observer.js +666 -236
  74. package/lib/observers/maria-observer.js +204 -362
  75. package/lib/observers/memcached-observer.js +56 -0
  76. package/lib/observers/mongo-observer.js +317 -0
  77. package/lib/observers/mongodb-observer.js +169 -226
  78. package/lib/observers/mongoose-observer.js +518 -323
  79. package/lib/observers/mssql-observer.js +177 -418
  80. package/lib/observers/mysql-observer.js +342 -449
  81. package/lib/observers/mysql2-observer.js +396 -358
  82. package/lib/observers/net-observer.js +77 -0
  83. package/lib/observers/oracle-observer.js +559 -384
  84. package/lib/observers/pgsql-observer.js +231 -489
  85. package/lib/observers/prisma-observer.js +303 -92
  86. package/lib/observers/process-observer.js +79 -35
  87. package/lib/observers/promise-observer.js +31 -0
  88. package/lib/observers/redis-observer.js +166 -331
  89. package/lib/observers/schedule-observer.js +67 -0
  90. package/lib/observers/socket.io-observer.js +226 -187
  91. package/lib/observers/stream-observer.js +19 -0
  92. package/lib/observers/thrift-observer.js +197 -0
  93. package/lib/observers/websocket-observer.js +175 -301
  94. package/lib/pack/activestack-pack.js +55 -0
  95. package/lib/pack/apenum.js +8 -0
  96. package/lib/pack/counter-pack.js +3 -0
  97. package/lib/pack/errorsnap-pack.js +69 -0
  98. package/lib/pack/event-pack.js +54 -0
  99. package/lib/pack/hitmap-pack.js +63 -0
  100. package/lib/pack/hitmap-pack1.js +152 -0
  101. package/lib/pack/log-sink-pack.js +14 -52
  102. package/lib/pack/netstat.js +15 -0
  103. package/lib/pack/otype.js +7 -0
  104. package/lib/pack/profile-pack.js +49 -0
  105. package/lib/pack/realtimeuser-pack.js +41 -0
  106. package/lib/pack/stat-general-pack.js +96 -0
  107. package/lib/pack/staterror-pack.js +120 -0
  108. package/lib/pack/stathttpc-pack.js +66 -0
  109. package/lib/pack/stathttpc-rec.js +78 -0
  110. package/lib/pack/statremote-pack.js +46 -0
  111. package/lib/pack/statservice-pack.js +63 -0
  112. package/lib/pack/statservice-pack1.js +88 -0
  113. package/lib/pack/statservice-rec.js +292 -0
  114. package/lib/pack/statservice-rec_dep.js +151 -0
  115. package/lib/pack/statsql-pack.js +69 -0
  116. package/lib/pack/statsql-rec.js +100 -0
  117. package/lib/pack/statuseragent-pack.js +44 -0
  118. package/lib/pack/tagcount-pack.js +4 -4
  119. package/lib/pack/tagctr.js +15 -0
  120. package/lib/pack/text-pack.js +50 -0
  121. package/lib/pack/time-count.js +25 -0
  122. package/lib/pack/websocket.js +15 -0
  123. package/lib/pack/zip-pack.js +70 -0
  124. package/lib/pii/pii-item.js +31 -0
  125. package/lib/pii/pii-mask.js +174 -0
  126. package/lib/plugin/plugin-loadermanager.js +57 -0
  127. package/lib/plugin/plugin.js +75 -0
  128. package/lib/service/tx-record.js +332 -0
  129. package/lib/stat/stat-error.js +116 -0
  130. package/lib/stat/stat-httpc.js +98 -0
  131. package/lib/stat/stat-remote-ip.js +46 -0
  132. package/lib/stat/stat-remote-ipurl.js +88 -0
  133. package/lib/stat/stat-sql.js +113 -0
  134. package/lib/stat/stat-tranx.js +58 -0
  135. package/lib/stat/stat-tx-caller.js +160 -0
  136. package/lib/stat/stat-tx-domain.js +111 -0
  137. package/lib/stat/stat-tx-referer.js +112 -0
  138. package/lib/stat/stat-useragent.js +48 -0
  139. package/lib/stat/timingsender.js +76 -0
  140. package/lib/step/activestack-step.js +38 -0
  141. package/lib/step/dbc-step.js +36 -0
  142. package/lib/step/http-stepx.js +67 -0
  143. package/lib/step/message-step.js +40 -0
  144. package/lib/step/method-stepx.js +45 -0
  145. package/lib/step/resultset-step.js +40 -0
  146. package/lib/step/securemsg-step.js +44 -0
  147. package/lib/step/socket-step.js +46 -0
  148. package/lib/step/sql-stepx.js +68 -0
  149. package/lib/step/sqlxtype.js +16 -0
  150. package/lib/step/step.js +66 -0
  151. package/lib/step/stepenum.js +54 -0
  152. package/lib/topology/link.js +63 -0
  153. package/lib/topology/nodeinfo.js +123 -0
  154. package/lib/topology/status-detector.js +111 -0
  155. package/lib/trace/trace-context-manager.js +113 -25
  156. package/lib/trace/trace-context.js +21 -7
  157. package/lib/trace/trace-httpc.js +17 -11
  158. package/lib/trace/trace-sql.js +29 -21
  159. package/lib/util/anylist.js +103 -0
  160. package/lib/util/cardinality/hyperloglog.js +106 -0
  161. package/lib/util/cardinality/murmurhash.js +31 -0
  162. package/lib/util/cardinality/registerset.js +75 -0
  163. package/lib/util/errordata.js +21 -0
  164. package/lib/util/escape-literal-sql.js +5 -5
  165. package/lib/util/hashutil.js +18 -18
  166. package/lib/util/iputil_x.js +527 -0
  167. package/lib/util/keygen.js +0 -3
  168. package/lib/util/kube-util.js +73 -0
  169. package/lib/util/linkedset.js +1 -2
  170. package/lib/util/nodeutil.js +2 -1
  171. package/lib/util/paramsecurity.js +80 -0
  172. package/lib/util/pre-process.js +13 -0
  173. package/lib/util/process-seq.js +166 -0
  174. package/lib/util/property-util.js +36 -0
  175. package/lib/util/request-queue.js +70 -0
  176. package/lib/util/requestdouble-queue.js +72 -0
  177. package/lib/util/resourceprofile.js +157 -0
  178. package/lib/util/stop-watch.js +30 -0
  179. package/lib/util/system-util.js +10 -0
  180. package/lib/util/userid-util.js +57 -0
  181. package/lib/value/map-value.js +3 -2
  182. package/package.json +9 -4
  183. package/whatap.conf +1 -4
  184. package/agent/darwin/arm64/whatap_nodejs +0 -0
  185. package/agent/linux/amd64/whatap_nodejs +0 -0
  186. package/agent/linux/arm64/whatap_nodejs +0 -0
  187. package/build.txt +0 -4
  188. package/lib/observers/ioredis-observer.js +0 -294
  189. package/lib/udp/async_sender.js +0 -119
  190. package/lib/udp/index.js +0 -17
  191. package/lib/udp/packet_enum.js +0 -52
  192. package/lib/udp/packet_queue.js +0 -69
  193. package/lib/udp/packet_type_enum.js +0 -33
  194. package/lib/udp/param_def.js +0 -72
  195. package/lib/udp/udp_session.js +0 -336
  196. package/lib/util/sql-util.js +0 -178
  197. package/lib/util/trace-helper.js +0 -91
  198. package/lib/util/transfer.js +0 -58
@@ -4,21 +4,23 @@
4
4
  * can be found in the LICENSE file.
5
5
  */
6
6
 
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;
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, 0);
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.offset;
72
+ return this.buf.length;
70
73
  };
71
74
 
72
- DataOutputX.prototype.writeIntBytes = function(b) {
73
- if (!b || b.length == 0) {
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 ((value instanceof Buffer) == false) {
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, 0, 0, this.offset);
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 (BYTE_MIN_VALUE <= value && value <= BYTE_MAX_VALUE) {
158
+ } else if (constants.numType.INT8_MIN <= value
159
+ && value <= constants.numType.INT8_MAX) {
150
160
  this.writeByte(1);
151
- this.writeByte(value);
152
- } else if (SHORT_MIN_VALUE <= value && value <= SHORT_MAX_VALUE) {
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.writeShort(value);
155
- } else if (INT3_MIN_VALUE <= value && value <= INT3_MAX_VALUE) {
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.writeInt3(value);
158
- } else if (INT_MIN_VALUE <= value && value <= INT_MAX_VALUE) {
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.writeInt(value);
161
- } else if (LONG5_MIN_VALUE <= value && value <= LONG5_MAX_VALUE) {
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.writeLong5(value);
164
- } else if (LONG_MIN_VALUE <= value && value <= LONG_MAX_VALUE) {
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(value);
182
+ this.writeLong(longVal);
167
183
  }
168
184
  return this;
169
185
  };
170
186
 
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;
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.writeUInt8(value, this.offset);
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.writeUInt16BE(value, this.offset);
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
- return this.writeShort(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;
226
238
  };
227
239
 
228
- DataOutputX.prototype.writeInt3 = function(value) {
240
+ DataOutputX.prototype.writeInt24BE = function(value) {
229
241
  if (isNumOk(value) == false) {
230
242
  value = 0;
231
243
  }
232
- this.ensureCapacity(this.offset + 3);
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.writeUInt32BE(value, this.offset);
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 + 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;
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.ensureCapacity(this.offset + 8);
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
- // BigInt를 사용하여 64비트 연산을 정확히 처리
287
- try {
288
- // 음수든 양수든 BigInt로 변환하면 64비트 표현으로 보존됨
289
- const bigValue = BigInt(value);
286
+ return this;
287
+ };
290
288
 
291
- // 64비트 마스킹
292
- const maskedValue = bigValue & 0xFFFFFFFFFFFFFFFFn;
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
- // BigInt 값을 버퍼에 씀
295
- this.buf.writeBigUInt64BE(maskedValue, this.offset);
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
- } 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
- }
303
+ }
304
+ return this;
305
+ };
310
306
 
311
- this.buf.writeUInt32BE(hi, this.offset);
312
- this.buf.writeUInt32BE(lo, this.offset + 4);
313
- this.offset += 8;
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 (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);
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.writeUInt8(254);
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.writeUTF = function(value) {
363
- if (isNotNull(value) == false) {
364
- value = "";
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
- const bytes = Buffer.from(value, 'utf-8');
368
- const truncatedBytes = bytes.length > 65535 ? bytes.slice(0, 65535) : bytes;
397
+ DataOutputX.prototype.writePack = function(pack) {
398
+ this.writeInt16BE(pack.getPackType());
399
+ pack.write(this);
400
+ return this;
401
+ };
369
402
 
370
- this.writeUInt16BE(truncatedBytes.length);
371
- this.write(truncatedBytes);
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.writeBoolean = function(value) {
377
- this.writeByte(value ? 1 : 0);
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.writeFloatArray = function(values) {
382
- if (!values || !Array.isArray(values)) {
383
- this.writeShort(0);
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.writeShort(values.length);
386
- for (let i = 0; i < values.length; i++) {
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.writeIntArray = function(values) {
394
- if (!values || !Array.isArray(values)) {
433
+ DataOutputX.prototype.writeFloatArray = function(value) {
434
+ if(value == null || Array.isArray(value) == false) {
395
435
  this.writeShort(0);
396
436
  } else {
397
- this.writeShort(values.length);
398
- for (let i = 0; i < values.length; i++) {
399
- this.writeInt(values[i]);
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.writeLongArray = function(values) {
406
- if (!values || !Array.isArray(values)) {
446
+ DataOutputX.prototype.writeIntArray = function(value) {
447
+ if(value == null || Array.isArray(value) == false) {
407
448
  this.writeShort(0);
408
449
  } else {
409
- this.writeShort(values.length);
410
- for (let i = 0; i < values.length; i++) {
411
- this.writeLong(values[i]);
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.writeDecimalArray = function(values) {
418
- if (!values || !Array.isArray(values)) {
459
+ DataOutputX.prototype.writeLongArray = function(value) {
460
+ if(value == null || Array.isArray(value) == false) {
419
461
  this.writeShort(0);
420
462
  } else {
421
- this.writeShort(values.length);
422
- for (let i = 0; i < values.length; i++) {
423
- this.writeDecimal(values[i]);
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.prototype.writeToPos = function(pos, value) {
430
- if (isNumOk(value) == false) {
431
- value = 0;
432
- }
433
- this.buf.writeUInt32BE(value, pos);
434
- return this;
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.prototype.writePack = function(pack, ln_fmt) {
438
- this.writeShort(pack.getPackType());
439
- pack.write(this);
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
- return this;
449
- };
450
-
451
- DataOutputX.prototype.writeValue = function(value) {
452
- if (value == null) {
453
- // NullValue 처리
454
- value = new NullValue();
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
- try {
458
- this.writeByte(value.getValueType());
459
- value.write(this);
460
- } catch (e) {
461
- Logger.printError('WHATAP-503', 'DataOutputX writeValue Error', e);
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;