@netkitty/codec 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 (463) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/LICENSE +21 -0
  3. package/README.md +352 -0
  4. package/README.zh-CN.md +342 -0
  5. package/dist/Codec.d.ts +133 -0
  6. package/dist/Codec.js +632 -0
  7. package/dist/PacketHeaders.d.ts +189 -0
  8. package/dist/PacketHeaders.js +384 -0
  9. package/dist/abstracts/BaseHeader.d.ts +325 -0
  10. package/dist/abstracts/BaseHeader.js +734 -0
  11. package/dist/errors/CodecSchemaValidateError.d.ts +4 -0
  12. package/dist/errors/CodecSchemaValidateError.js +11 -0
  13. package/dist/headers/ADSAMS.d.ts +33 -0
  14. package/dist/headers/ADSAMS.js +208 -0
  15. package/dist/headers/AH.d.ts +28 -0
  16. package/dist/headers/AH.js +137 -0
  17. package/dist/headers/AMQP.d.ts +31 -0
  18. package/dist/headers/AMQP.js +316 -0
  19. package/dist/headers/ARP.d.ts +26 -0
  20. package/dist/headers/ARP.js +243 -0
  21. package/dist/headers/BACnetIP.d.ts +27 -0
  22. package/dist/headers/BACnetIP.js +97 -0
  23. package/dist/headers/BFD.d.ts +28 -0
  24. package/dist/headers/BFD.js +155 -0
  25. package/dist/headers/BGP.d.ts +27 -0
  26. package/dist/headers/BGP.js +111 -0
  27. package/dist/headers/BSAPIP.d.ts +33 -0
  28. package/dist/headers/BSAPIP.js +78 -0
  29. package/dist/headers/Babel.d.ts +32 -0
  30. package/dist/headers/Babel.js +224 -0
  31. package/dist/headers/BitTorrent.d.ts +28 -0
  32. package/dist/headers/BitTorrent.js +72 -0
  33. package/dist/headers/C37118.d.ts +26 -0
  34. package/dist/headers/C37118.js +147 -0
  35. package/dist/headers/CAPWAP.d.ts +38 -0
  36. package/dist/headers/CAPWAP.js +275 -0
  37. package/dist/headers/CDP.d.ts +25 -0
  38. package/dist/headers/CDP.js +117 -0
  39. package/dist/headers/CMS.d.ts +33 -0
  40. package/dist/headers/CMS.js +238 -0
  41. package/dist/headers/COTP.d.ts +30 -0
  42. package/dist/headers/COTP.js +193 -0
  43. package/dist/headers/CassandraCQL.d.ts +28 -0
  44. package/dist/headers/CassandraCQL.js +117 -0
  45. package/dist/headers/CoAP.d.ts +29 -0
  46. package/dist/headers/CoAP.js +140 -0
  47. package/dist/headers/Codesys.d.ts +32 -0
  48. package/dist/headers/Codesys.js +119 -0
  49. package/dist/headers/Collectd.d.ts +29 -0
  50. package/dist/headers/Collectd.js +154 -0
  51. package/dist/headers/DCCP.d.ts +30 -0
  52. package/dist/headers/DCCP.js +204 -0
  53. package/dist/headers/DHCP.d.ts +26 -0
  54. package/dist/headers/DHCP.js +148 -0
  55. package/dist/headers/DHCPFailover.d.ts +30 -0
  56. package/dist/headers/DHCPFailover.js +104 -0
  57. package/dist/headers/DHCPv6.d.ts +25 -0
  58. package/dist/headers/DHCPv6.js +145 -0
  59. package/dist/headers/DNP3.d.ts +27 -0
  60. package/dist/headers/DNP3.js +150 -0
  61. package/dist/headers/DNS.d.ts +55 -0
  62. package/dist/headers/DNS.js +309 -0
  63. package/dist/headers/DTLS.d.ts +33 -0
  64. package/dist/headers/DTLS.js +142 -0
  65. package/dist/headers/Diameter.d.ts +34 -0
  66. package/dist/headers/Diameter.js +229 -0
  67. package/dist/headers/EAPOL.d.ts +32 -0
  68. package/dist/headers/EAPOL.js +135 -0
  69. package/dist/headers/EIGRP.d.ts +28 -0
  70. package/dist/headers/EIGRP.js +165 -0
  71. package/dist/headers/ENIP.d.ts +31 -0
  72. package/dist/headers/ENIP.js +164 -0
  73. package/dist/headers/ESP.d.ts +27 -0
  74. package/dist/headers/ESP.js +140 -0
  75. package/dist/headers/Elasticsearch.d.ts +30 -0
  76. package/dist/headers/Elasticsearch.js +125 -0
  77. package/dist/headers/EtherCAT.d.ts +35 -0
  78. package/dist/headers/EtherCAT.js +150 -0
  79. package/dist/headers/EthernetII.d.ts +28 -0
  80. package/dist/headers/EthernetII.js +117 -0
  81. package/dist/headers/FCoE.d.ts +38 -0
  82. package/dist/headers/FCoE.js +210 -0
  83. package/dist/headers/FTP.d.ts +34 -0
  84. package/dist/headers/FTP.js +158 -0
  85. package/dist/headers/Finger.d.ts +41 -0
  86. package/dist/headers/Finger.js +135 -0
  87. package/dist/headers/FoundationFieldbusHSE.d.ts +43 -0
  88. package/dist/headers/FoundationFieldbusHSE.js +163 -0
  89. package/dist/headers/GELF.d.ts +35 -0
  90. package/dist/headers/GELF.js +261 -0
  91. package/dist/headers/GENEVE.d.ts +26 -0
  92. package/dist/headers/GENEVE.js +209 -0
  93. package/dist/headers/GESRTP.d.ts +32 -0
  94. package/dist/headers/GESRTP.js +141 -0
  95. package/dist/headers/GLBP.d.ts +29 -0
  96. package/dist/headers/GLBP.js +159 -0
  97. package/dist/headers/GRE.d.ts +27 -0
  98. package/dist/headers/GRE.js +181 -0
  99. package/dist/headers/GTPU.d.ts +25 -0
  100. package/dist/headers/GTPU.js +203 -0
  101. package/dist/headers/GTPv2C.d.ts +30 -0
  102. package/dist/headers/GTPv2C.js +281 -0
  103. package/dist/headers/GitProtocol.d.ts +34 -0
  104. package/dist/headers/GitProtocol.js +141 -0
  105. package/dist/headers/Goose.d.ts +115 -0
  106. package/dist/headers/Goose.js +1067 -0
  107. package/dist/headers/Gopher.d.ts +43 -0
  108. package/dist/headers/Gopher.js +182 -0
  109. package/dist/headers/HARTIP.d.ts +30 -0
  110. package/dist/headers/HARTIP.js +145 -0
  111. package/dist/headers/HSR.d.ts +27 -0
  112. package/dist/headers/HSR.js +105 -0
  113. package/dist/headers/HSRP.d.ts +26 -0
  114. package/dist/headers/HSRP.js +173 -0
  115. package/dist/headers/HTTP.d.ts +32 -0
  116. package/dist/headers/HTTP.js +153 -0
  117. package/dist/headers/HTTP2.d.ts +34 -0
  118. package/dist/headers/HTTP2.js +190 -0
  119. package/dist/headers/IAX2.d.ts +33 -0
  120. package/dist/headers/IAX2.js +274 -0
  121. package/dist/headers/ICMP.d.ts +15 -0
  122. package/dist/headers/ICMP.js +148 -0
  123. package/dist/headers/ICMPv6.d.ts +15 -0
  124. package/dist/headers/ICMPv6.js +129 -0
  125. package/dist/headers/IEC104_I_Frame.d.ts +23 -0
  126. package/dist/headers/IEC104_I_Frame.js +6489 -0
  127. package/dist/headers/IEC104_S_Frame.d.ts +26 -0
  128. package/dist/headers/IEC104_S_Frame.js +135 -0
  129. package/dist/headers/IEC104_U_Frame.d.ts +27 -0
  130. package/dist/headers/IEC104_U_Frame.js +176 -0
  131. package/dist/headers/IEC61850SampledValues.d.ts +20 -0
  132. package/dist/headers/IEC61850SampledValues.js +420 -0
  133. package/dist/headers/IGMP.d.ts +31 -0
  134. package/dist/headers/IGMP.js +274 -0
  135. package/dist/headers/IMAP.d.ts +32 -0
  136. package/dist/headers/IMAP.js +185 -0
  137. package/dist/headers/IPFIX.d.ts +29 -0
  138. package/dist/headers/IPFIX.js +156 -0
  139. package/dist/headers/IPv4.d.ts +20 -0
  140. package/dist/headers/IPv4.js +370 -0
  141. package/dist/headers/IPv6.d.ts +29 -0
  142. package/dist/headers/IPv6.js +209 -0
  143. package/dist/headers/IPv6HopByHopOptions.d.ts +81 -0
  144. package/dist/headers/IPv6HopByHopOptions.js +495 -0
  145. package/dist/headers/IRC.d.ts +34 -0
  146. package/dist/headers/IRC.js +175 -0
  147. package/dist/headers/ISAKMP.d.ts +29 -0
  148. package/dist/headers/ISAKMP.js +197 -0
  149. package/dist/headers/ISCSI.d.ts +39 -0
  150. package/dist/headers/ISCSI.js +289 -0
  151. package/dist/headers/ISIS.d.ts +25 -0
  152. package/dist/headers/ISIS.js +79 -0
  153. package/dist/headers/ISOSession.d.ts +27 -0
  154. package/dist/headers/ISOSession.js +343 -0
  155. package/dist/headers/Ident.d.ts +42 -0
  156. package/dist/headers/Ident.js +184 -0
  157. package/dist/headers/KNXnetIP.d.ts +30 -0
  158. package/dist/headers/KNXnetIP.js +135 -0
  159. package/dist/headers/Kafka.d.ts +35 -0
  160. package/dist/headers/Kafka.js +128 -0
  161. package/dist/headers/Kerberos.d.ts +30 -0
  162. package/dist/headers/Kerberos.js +217 -0
  163. package/dist/headers/L2TP.d.ts +26 -0
  164. package/dist/headers/L2TP.js +297 -0
  165. package/dist/headers/LACP.d.ts +31 -0
  166. package/dist/headers/LACP.js +151 -0
  167. package/dist/headers/LDAP.d.ts +31 -0
  168. package/dist/headers/LDAP.js +226 -0
  169. package/dist/headers/LDP.d.ts +31 -0
  170. package/dist/headers/LDP.js +138 -0
  171. package/dist/headers/LISP.d.ts +30 -0
  172. package/dist/headers/LISP.js +103 -0
  173. package/dist/headers/LLC.d.ts +27 -0
  174. package/dist/headers/LLC.js +81 -0
  175. package/dist/headers/LLDP.d.ts +26 -0
  176. package/dist/headers/LLDP.js +126 -0
  177. package/dist/headers/LLMNR.d.ts +23 -0
  178. package/dist/headers/LLMNR.js +40 -0
  179. package/dist/headers/LPD.d.ts +31 -0
  180. package/dist/headers/LPD.js +159 -0
  181. package/dist/headers/MACsec.d.ts +34 -0
  182. package/dist/headers/MACsec.js +178 -0
  183. package/dist/headers/MDNS.d.ts +26 -0
  184. package/dist/headers/MDNS.js +45 -0
  185. package/dist/headers/MGCP.d.ts +30 -0
  186. package/dist/headers/MGCP.js +155 -0
  187. package/dist/headers/MMS.d.ts +29 -0
  188. package/dist/headers/MMS.js +243 -0
  189. package/dist/headers/MPLS.d.ts +31 -0
  190. package/dist/headers/MPLS.js +145 -0
  191. package/dist/headers/MQTT.d.ts +30 -0
  192. package/dist/headers/MQTT.js +173 -0
  193. package/dist/headers/MQTTSN.d.ts +34 -0
  194. package/dist/headers/MQTTSN.js +177 -0
  195. package/dist/headers/MarkerProtocol.d.ts +32 -0
  196. package/dist/headers/MarkerProtocol.js +153 -0
  197. package/dist/headers/Megaco.d.ts +32 -0
  198. package/dist/headers/Megaco.js +144 -0
  199. package/dist/headers/Memcached.d.ts +44 -0
  200. package/dist/headers/Memcached.js +285 -0
  201. package/dist/headers/ModbusTCP.d.ts +25 -0
  202. package/dist/headers/ModbusTCP.js +99 -0
  203. package/dist/headers/ModbusUDP.d.ts +26 -0
  204. package/dist/headers/ModbusUDP.js +100 -0
  205. package/dist/headers/MongoDB.d.ts +33 -0
  206. package/dist/headers/MongoDB.js +143 -0
  207. package/dist/headers/MySQL.d.ts +30 -0
  208. package/dist/headers/MySQL.js +114 -0
  209. package/dist/headers/NATS.d.ts +29 -0
  210. package/dist/headers/NATS.js +135 -0
  211. package/dist/headers/NBDS.d.ts +34 -0
  212. package/dist/headers/NBDS.js +176 -0
  213. package/dist/headers/NBNS.d.ts +34 -0
  214. package/dist/headers/NBNS.js +78 -0
  215. package/dist/headers/NBSS.d.ts +36 -0
  216. package/dist/headers/NBSS.js +137 -0
  217. package/dist/headers/NFS.d.ts +36 -0
  218. package/dist/headers/NFS.js +273 -0
  219. package/dist/headers/NHRP.d.ts +32 -0
  220. package/dist/headers/NHRP.js +154 -0
  221. package/dist/headers/NNTP.d.ts +35 -0
  222. package/dist/headers/NNTP.js +162 -0
  223. package/dist/headers/NTP.d.ts +18 -0
  224. package/dist/headers/NTP.js +73 -0
  225. package/dist/headers/NetFlowV5.d.ts +28 -0
  226. package/dist/headers/NetFlowV5.js +205 -0
  227. package/dist/headers/OLSR.d.ts +31 -0
  228. package/dist/headers/OLSR.js +213 -0
  229. package/dist/headers/OPCUA.d.ts +33 -0
  230. package/dist/headers/OPCUA.js +165 -0
  231. package/dist/headers/OPCUAPubSub.d.ts +33 -0
  232. package/dist/headers/OPCUAPubSub.js +144 -0
  233. package/dist/headers/OSPF.d.ts +31 -0
  234. package/dist/headers/OSPF.js +365 -0
  235. package/dist/headers/OmronFINS.d.ts +31 -0
  236. package/dist/headers/OmronFINS.js +90 -0
  237. package/dist/headers/OpenFlow.d.ts +30 -0
  238. package/dist/headers/OpenFlow.js +113 -0
  239. package/dist/headers/OpenVPN.d.ts +35 -0
  240. package/dist/headers/OpenVPN.js +214 -0
  241. package/dist/headers/PCWorx.d.ts +35 -0
  242. package/dist/headers/PCWorx.js +115 -0
  243. package/dist/headers/PIM.d.ts +27 -0
  244. package/dist/headers/PIM.js +129 -0
  245. package/dist/headers/POP3.d.ts +31 -0
  246. package/dist/headers/POP3.js +152 -0
  247. package/dist/headers/POWERLINK.d.ts +28 -0
  248. package/dist/headers/POWERLINK.js +116 -0
  249. package/dist/headers/PPPoEDiscovery.d.ts +29 -0
  250. package/dist/headers/PPPoEDiscovery.js +198 -0
  251. package/dist/headers/PPPoESession.d.ts +28 -0
  252. package/dist/headers/PPPoESession.js +125 -0
  253. package/dist/headers/PPTP.d.ts +30 -0
  254. package/dist/headers/PPTP.js +122 -0
  255. package/dist/headers/PROFINETRT.d.ts +28 -0
  256. package/dist/headers/PROFINETRT.js +74 -0
  257. package/dist/headers/PTP.d.ts +34 -0
  258. package/dist/headers/PTP.js +213 -0
  259. package/dist/headers/PostgreSQL.d.ts +40 -0
  260. package/dist/headers/PostgreSQL.js +236 -0
  261. package/dist/headers/QUIC.d.ts +34 -0
  262. package/dist/headers/QUIC.js +308 -0
  263. package/dist/headers/RADIUS.d.ts +24 -0
  264. package/dist/headers/RADIUS.js +138 -0
  265. package/dist/headers/RDP.d.ts +27 -0
  266. package/dist/headers/RDP.js +93 -0
  267. package/dist/headers/RFB.d.ts +39 -0
  268. package/dist/headers/RFB.js +151 -0
  269. package/dist/headers/RGoose.d.ts +72 -0
  270. package/dist/headers/RGoose.js +340 -0
  271. package/dist/headers/RIP.d.ts +29 -0
  272. package/dist/headers/RIP.js +133 -0
  273. package/dist/headers/RIPng.d.ts +26 -0
  274. package/dist/headers/RIPng.js +140 -0
  275. package/dist/headers/RMCP.d.ts +26 -0
  276. package/dist/headers/RMCP.js +155 -0
  277. package/dist/headers/RSVP.d.ts +31 -0
  278. package/dist/headers/RSVP.js +263 -0
  279. package/dist/headers/RTCP.d.ts +34 -0
  280. package/dist/headers/RTCP.js +217 -0
  281. package/dist/headers/RTP.d.ts +33 -0
  282. package/dist/headers/RTP.js +291 -0
  283. package/dist/headers/RTPS.d.ts +33 -0
  284. package/dist/headers/RTPS.js +182 -0
  285. package/dist/headers/RTSP.d.ts +36 -0
  286. package/dist/headers/RTSP.js +184 -0
  287. package/dist/headers/RawData.d.ts +17 -0
  288. package/dist/headers/RawData.js +43 -0
  289. package/dist/headers/Redis.d.ts +32 -0
  290. package/dist/headers/Redis.js +202 -0
  291. package/dist/headers/Rlogin.d.ts +42 -0
  292. package/dist/headers/Rlogin.js +139 -0
  293. package/dist/headers/Rsync.d.ts +28 -0
  294. package/dist/headers/Rsync.js +117 -0
  295. package/dist/headers/S7comm.d.ts +36 -0
  296. package/dist/headers/S7comm.js +244 -0
  297. package/dist/headers/SCTP.d.ts +35 -0
  298. package/dist/headers/SCTP.js +174 -0
  299. package/dist/headers/SFlow.d.ts +29 -0
  300. package/dist/headers/SFlow.js +242 -0
  301. package/dist/headers/SIP.d.ts +27 -0
  302. package/dist/headers/SIP.js +146 -0
  303. package/dist/headers/SLMP.d.ts +36 -0
  304. package/dist/headers/SLMP.js +154 -0
  305. package/dist/headers/SLP.d.ts +30 -0
  306. package/dist/headers/SLP.js +207 -0
  307. package/dist/headers/SLPv1.d.ts +32 -0
  308. package/dist/headers/SLPv1.js +138 -0
  309. package/dist/headers/SMB1.d.ts +37 -0
  310. package/dist/headers/SMB1.js +200 -0
  311. package/dist/headers/SMB2.d.ts +36 -0
  312. package/dist/headers/SMB2.js +203 -0
  313. package/dist/headers/SMPP.d.ts +33 -0
  314. package/dist/headers/SMPP.js +119 -0
  315. package/dist/headers/SMTP.d.ts +33 -0
  316. package/dist/headers/SMTP.js +157 -0
  317. package/dist/headers/SNAP.d.ts +22 -0
  318. package/dist/headers/SNAP.js +68 -0
  319. package/dist/headers/SNMP.d.ts +28 -0
  320. package/dist/headers/SNMP.js +302 -0
  321. package/dist/headers/SOCKS4.d.ts +42 -0
  322. package/dist/headers/SOCKS4.js +302 -0
  323. package/dist/headers/SOCKS5.d.ts +45 -0
  324. package/dist/headers/SOCKS5.js +223 -0
  325. package/dist/headers/SSDP.d.ts +27 -0
  326. package/dist/headers/SSDP.js +161 -0
  327. package/dist/headers/SSH.d.ts +44 -0
  328. package/dist/headers/SSH.js +274 -0
  329. package/dist/headers/STOMP.d.ts +48 -0
  330. package/dist/headers/STOMP.js +177 -0
  331. package/dist/headers/STP.d.ts +26 -0
  332. package/dist/headers/STP.js +150 -0
  333. package/dist/headers/STUN.d.ts +25 -0
  334. package/dist/headers/STUN.js +183 -0
  335. package/dist/headers/SercosIII.d.ts +43 -0
  336. package/dist/headers/SercosIII.js +199 -0
  337. package/dist/headers/Skinny.d.ts +32 -0
  338. package/dist/headers/Skinny.js +139 -0
  339. package/dist/headers/StatsD.d.ts +27 -0
  340. package/dist/headers/StatsD.js +134 -0
  341. package/dist/headers/SunRPC.d.ts +34 -0
  342. package/dist/headers/SunRPC.js +268 -0
  343. package/dist/headers/Syslog.d.ts +21 -0
  344. package/dist/headers/Syslog.js +91 -0
  345. package/dist/headers/TCP.d.ts +19 -0
  346. package/dist/headers/TCP.js +905 -0
  347. package/dist/headers/TFTP.d.ts +28 -0
  348. package/dist/headers/TFTP.js +224 -0
  349. package/dist/headers/TLS_Alert.d.ts +24 -0
  350. package/dist/headers/TLS_Alert.js +639 -0
  351. package/dist/headers/TLS_ApplicationData.d.ts +24 -0
  352. package/dist/headers/TLS_ApplicationData.js +170 -0
  353. package/dist/headers/TLS_ChangeCipherSpec.d.ts +23 -0
  354. package/dist/headers/TLS_ChangeCipherSpec.js +168 -0
  355. package/dist/headers/TLS_Handshake.d.ts +65 -0
  356. package/dist/headers/TLS_Handshake.js +860 -0
  357. package/dist/headers/TLS_Heartbeat.d.ts +27 -0
  358. package/dist/headers/TLS_Heartbeat.js +247 -0
  359. package/dist/headers/TPKT.d.ts +26 -0
  360. package/dist/headers/TPKT.js +99 -0
  361. package/dist/headers/TacacsPlus.d.ts +27 -0
  362. package/dist/headers/TacacsPlus.js +133 -0
  363. package/dist/headers/Telnet.d.ts +40 -0
  364. package/dist/headers/Telnet.js +193 -0
  365. package/dist/headers/Teredo.d.ts +40 -0
  366. package/dist/headers/Teredo.js +251 -0
  367. package/dist/headers/TimeProtocol.d.ts +25 -0
  368. package/dist/headers/TimeProtocol.js +53 -0
  369. package/dist/headers/UDP.d.ts +19 -0
  370. package/dist/headers/UDP.js +171 -0
  371. package/dist/headers/VLAN_802dot1Q.d.ts +24 -0
  372. package/dist/headers/VLAN_802dot1Q.js +96 -0
  373. package/dist/headers/VRRP.d.ts +26 -0
  374. package/dist/headers/VRRP.js +309 -0
  375. package/dist/headers/VXLAN.d.ts +24 -0
  376. package/dist/headers/VXLAN.js +75 -0
  377. package/dist/headers/WCCP.d.ts +29 -0
  378. package/dist/headers/WCCP.js +117 -0
  379. package/dist/headers/WHOIS.d.ts +37 -0
  380. package/dist/headers/WHOIS.js +126 -0
  381. package/dist/headers/WSDiscovery.d.ts +29 -0
  382. package/dist/headers/WSDiscovery.js +118 -0
  383. package/dist/headers/WakeOnLAN.d.ts +30 -0
  384. package/dist/headers/WakeOnLAN.js +126 -0
  385. package/dist/headers/WebSocket.d.ts +26 -0
  386. package/dist/headers/WebSocket.js +173 -0
  387. package/dist/headers/WireGuard.d.ts +38 -0
  388. package/dist/headers/WireGuard.js +216 -0
  389. package/dist/headers/XMPP.d.ts +37 -0
  390. package/dist/headers/XMPP.js +149 -0
  391. package/dist/headers/Zabbix.d.ts +35 -0
  392. package/dist/headers/Zabbix.js +153 -0
  393. package/dist/headers/cms/AcsiPdu.d.ts +45 -0
  394. package/dist/headers/cms/AcsiPdu.js +112 -0
  395. package/dist/headers/cms/PerDecoder.d.ts +68 -0
  396. package/dist/headers/cms/PerDecoder.js +211 -0
  397. package/dist/headers/cms/PerReader.d.ts +64 -0
  398. package/dist/headers/cms/PerReader.js +155 -0
  399. package/dist/helper/BufferToHex.d.ts +5 -0
  400. package/dist/helper/BufferToHex.js +10 -0
  401. package/dist/helper/BufferToIP.d.ts +12 -0
  402. package/dist/helper/BufferToIP.js +23 -0
  403. package/dist/helper/BufferToNumber.d.ts +18 -0
  404. package/dist/helper/BufferToNumber.js +47 -0
  405. package/dist/helper/HexToBuffer.d.ts +7 -0
  406. package/dist/helper/HexToBuffer.js +27 -0
  407. package/dist/helper/HexToNumber.d.ts +18 -0
  408. package/dist/helper/HexToNumber.js +48 -0
  409. package/dist/helper/IPToBuffer.d.ts +12 -0
  410. package/dist/helper/IPToBuffer.js +34 -0
  411. package/dist/helper/NumberToBERBuffer.d.ts +18 -0
  412. package/dist/helper/NumberToBERBuffer.js +31 -0
  413. package/dist/helper/NumberToBERHex.d.ts +18 -0
  414. package/dist/helper/NumberToBERHex.js +52 -0
  415. package/dist/helper/NumberToBuffer.d.ts +18 -0
  416. package/dist/helper/NumberToBuffer.js +38 -0
  417. package/dist/helper/NumberToHex.d.ts +18 -0
  418. package/dist/helper/NumberToHex.js +35 -0
  419. package/dist/index.d.ts +52 -0
  420. package/dist/index.js +113 -0
  421. package/dist/lib/FlexibleObject.d.ts +27 -0
  422. package/dist/lib/FlexibleObject.js +113 -0
  423. package/dist/lib/GetBERIntegerLengthFromBuffer.d.ts +6 -0
  424. package/dist/lib/GetBERIntegerLengthFromBuffer.js +16 -0
  425. package/dist/lib/ProcessPacketPostHandlers.d.ts +13 -0
  426. package/dist/lib/ProcessPacketPostHandlers.js +53 -0
  427. package/dist/lib/SortPostHandlers.d.ts +7 -0
  428. package/dist/lib/SortPostHandlers.js +11 -0
  429. package/dist/lib/StringContentEncodingEnum.d.ts +10 -0
  430. package/dist/lib/StringContentEncodingEnum.js +14 -0
  431. package/dist/schema/ProtocolFieldJSONSchema.d.ts +35 -0
  432. package/dist/schema/ProtocolFieldJSONSchema.js +2 -0
  433. package/dist/schema/ProtocolFieldJSONSchemaDefinition.d.ts +2 -0
  434. package/dist/schema/ProtocolFieldJSONSchemaDefinition.js +2 -0
  435. package/dist/schema/ProtocolJSONSchema.d.ts +32 -0
  436. package/dist/schema/ProtocolJSONSchema.js +2 -0
  437. package/dist/types/CodecData.d.ts +7 -0
  438. package/dist/types/CodecData.js +2 -0
  439. package/dist/types/CodecDecodeResult.d.ts +10 -0
  440. package/dist/types/CodecDecodeResult.js +2 -0
  441. package/dist/types/CodecEncodeInput.d.ts +2 -0
  442. package/dist/types/CodecEncodeInput.js +2 -0
  443. package/dist/types/CodecEncodeResult.d.ts +5 -0
  444. package/dist/types/CodecEncodeResult.js +2 -0
  445. package/dist/types/CodecErrorInfo.d.ts +5 -0
  446. package/dist/types/CodecErrorInfo.js +2 -0
  447. package/dist/types/CodecModule.d.ts +2 -0
  448. package/dist/types/CodecModule.js +2 -0
  449. package/dist/types/CodecModuleConstructor.d.ts +2 -0
  450. package/dist/types/CodecModuleConstructor.js +2 -0
  451. package/dist/types/CodecSchema.d.ts +6 -0
  452. package/dist/types/CodecSchema.js +2 -0
  453. package/dist/types/DemuxProducer.d.ts +23 -0
  454. package/dist/types/DemuxProducer.js +2 -0
  455. package/dist/types/Dissection.d.ts +23 -0
  456. package/dist/types/Dissection.js +2 -0
  457. package/dist/types/HeaderTreeNode.d.ts +4 -0
  458. package/dist/types/HeaderTreeNode.js +2 -0
  459. package/dist/types/LayerGraph.d.ts +32 -0
  460. package/dist/types/LayerGraph.js +2 -0
  461. package/dist/types/PostHandlerItem.d.ts +4 -0
  462. package/dist/types/PostHandlerItem.js +2 -0
  463. package/package.json +141 -0
@@ -0,0 +1,211 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.PerDecoder = void 0;
5
+ const PerReader_1 = require("./PerReader");
6
+ /**
7
+ * PerDecoder — a never-throwing ALIGNED BASIC-PER interpreter. It walks an {@link AsnType} descriptor,
8
+ * pulling from a {@link PerReader}, and returns a plain JS value tree for DISPLAY only (CMS keeps the raw
9
+ * service-data bytes as the authoritative encode form, so this decoder never affects output bytes). When it
10
+ * meets something it cannot safely decode — a fragmented length, an unknown `ref`, or an extensible type
11
+ * whose additions are present — it sets {@link bailed} so the caller can fall back to showing raw hex.
12
+ */
13
+ class PerDecoder {
14
+ static #MAX_DEPTH = 64;
15
+ #reader;
16
+ #table;
17
+ #bailed;
18
+ #depth;
19
+ constructor(buf, table = {}) {
20
+ this.#reader = new PerReader_1.PerReader(buf);
21
+ this.#table = table;
22
+ this.#bailed = false;
23
+ this.#depth = 0;
24
+ }
25
+ /** True once the decoder hit a construct it could not safely decode; the result is then incomplete. */
26
+ get bailed() {
27
+ return this.#bailed;
28
+ }
29
+ /** Bytes consumed so far (rounded down) — lets the caller show any trailing bytes as raw. */
30
+ get bytePos() {
31
+ return this.#reader.bytePos();
32
+ }
33
+ decode(type) {
34
+ return this.#decode(type);
35
+ }
36
+ #decode(type) {
37
+ if (this.#depth >= _a.#MAX_DEPTH) {
38
+ //Runaway recursion (a malformed/pathological descriptor): stop rather than overflow the stack.
39
+ this.#bailed = true;
40
+ return undefined;
41
+ }
42
+ this.#depth++;
43
+ try {
44
+ return this.#dispatch(type);
45
+ }
46
+ finally {
47
+ this.#depth--;
48
+ }
49
+ }
50
+ #dispatch(type) {
51
+ switch (type.k) {
52
+ case 'bool':
53
+ return this.#reader.readBit() === 1;
54
+ case 'int':
55
+ return this.#decodeInt(type);
56
+ case 'enum':
57
+ return this.#decodeEnum(type);
58
+ case 'bitstr':
59
+ case 'octstr':
60
+ return this.#decodeString(type);
61
+ case 'vstr':
62
+ return this.#decodeVisibleString(type);
63
+ case 'seq':
64
+ return this.#decodeSequence(type);
65
+ case 'seqof':
66
+ return this.#decodeSequenceOf(type);
67
+ case 'choice':
68
+ return this.#decodeChoice(type);
69
+ case 'ref':
70
+ return this.#decodeRef(type);
71
+ }
72
+ }
73
+ #decodeInt(type) {
74
+ if (type.lb !== undefined && type.ub !== undefined)
75
+ return this.#reader.readConstrainedInt(type.lb, type.ub);
76
+ //Unconstrained / semi-constrained: a length determinant then that many octets, octet-aligned.
77
+ const length = this.#reader.readLengthDeterminant();
78
+ if (length.fragmented) {
79
+ this.#bailed = true;
80
+ return 0;
81
+ }
82
+ const octets = this.#reader.readOctets(length.value);
83
+ if (octets.length === 0)
84
+ return type.lb ?? 0;
85
+ //Accumulate with BigInt so any width (up to INT64) is exact — a JS number loses precision past 2^53.
86
+ let value = 0n;
87
+ for (let i = 0; i < octets.length; i++)
88
+ value = (value << 8n) | BigInt(octets[i]);
89
+ if (type.lb !== undefined) {
90
+ //Semi-constrained (lb..MAX): the octets are the unsigned value offset by the lower bound.
91
+ value += BigInt(type.lb);
92
+ }
93
+ else if (octets[0] & 0x80) {
94
+ //Fully unconstrained INTEGER: the octets are a two's-complement signed value.
95
+ value -= 1n << BigInt(octets.length * 8);
96
+ }
97
+ return _a.#bigToJson(value);
98
+ }
99
+ /** Return a BigInt as a plain number when it fits exactly in a JS number, else a decimal string, so the
100
+ * display tree stays JSON-serializable and never loses precision on 64-bit values. */
101
+ static #bigToJson(value) {
102
+ if (value >= BigInt(Number.MIN_SAFE_INTEGER) && value <= BigInt(Number.MAX_SAFE_INTEGER))
103
+ return Number(value);
104
+ return value.toString();
105
+ }
106
+ #decodeEnum(type) {
107
+ if (type.ext && this.#reader.readBit() === 1) {
108
+ //An extension addition: index is a normally-small-non-negative number we do not decode.
109
+ this.#bailed = true;
110
+ return '';
111
+ }
112
+ const idx = this.#reader.readConstrainedInt(0, type.values.length - 1);
113
+ return type.values[idx] ?? idx;
114
+ }
115
+ #decodeString(type) {
116
+ //Fixed-size BIT STRING: `size` is a bit count. Its content octet-aligns unless the whole string is
117
+ //≤ 16 bits (X.691 small-string exception — Quality SIZE(13), Dbpos/Tcmd/Check SIZE(2) pack unaligned).
118
+ if (type.k === 'bitstr' && type.size !== undefined) {
119
+ return this.#reader.readBitString(type.size, type.size > 16);
120
+ }
121
+ let count;
122
+ if (type.size !== undefined) {
123
+ //Fixed-size OCTET STRING: `size` is a byte count.
124
+ count = type.size;
125
+ }
126
+ else {
127
+ const length = this.#reader.readLengthDeterminant();
128
+ if (length.fragmented) {
129
+ this.#bailed = true;
130
+ return '';
131
+ }
132
+ count = type.k === 'bitstr' ? Math.ceil(length.value / 8) : length.value;
133
+ }
134
+ return this.#reader.readOctets(count).toString('hex');
135
+ }
136
+ #decodeVisibleString(type) {
137
+ if (type.min !== undefined && type.max !== undefined) {
138
+ //Fixed size: no length field. Content octet-aligns unless the whole string is ≤ 16 bits
139
+ //(X.691 small-string exception — 8 bits/char, so a 1- or 2-char fixed string packs unaligned).
140
+ if (type.max === type.min)
141
+ return this.#reader.readCharString(type.min, type.min * 8 > 16);
142
+ const count = this.#reader.readConstrainedInt(type.min, type.max);
143
+ return this.#reader.readOctets(count).toString('latin1');
144
+ }
145
+ return this.#reader.readLengthPrefixedString();
146
+ }
147
+ #decodeSequence(type) {
148
+ //Leading extension bit (extensible SEQUENCE): if additions are present we decode the root fields
149
+ //then stop, leaving the additions for the raw-hex fallback.
150
+ let extensions = false;
151
+ if (type.ext)
152
+ extensions = this.#reader.readBit() === 1;
153
+ //Preamble bitmap: one present/absent bit per OPTIONAL / DEFAULT component, in order.
154
+ const optionals = type.fields.filter((f) => !!f.optional || f.default !== undefined);
155
+ const present = {};
156
+ for (const field of optionals)
157
+ present[field.name] = this.#reader.readBit() === 1;
158
+ const out = {};
159
+ for (const field of type.fields) {
160
+ const isOptional = !!field.optional || field.default !== undefined;
161
+ if (isOptional && !present[field.name]) {
162
+ if (field.default !== undefined)
163
+ out[field.name] = field.default;
164
+ continue;
165
+ }
166
+ out[field.name] = this.#decode(field.type);
167
+ }
168
+ if (extensions)
169
+ this.#bailed = true;
170
+ return out;
171
+ }
172
+ #decodeSequenceOf(type) {
173
+ const length = this.#reader.readLengthDeterminant();
174
+ if (length.fragmented) {
175
+ this.#bailed = true;
176
+ return [];
177
+ }
178
+ const out = [];
179
+ for (let i = 0; i < length.value; i++) {
180
+ if (this.#reader.bitsRemaining() <= 0) {
181
+ this.#bailed = true;
182
+ break;
183
+ }
184
+ out.push(this.#decode(type.element));
185
+ }
186
+ return out;
187
+ }
188
+ #decodeChoice(type) {
189
+ if (type.ext && this.#reader.readBit() === 1) {
190
+ this.#bailed = true;
191
+ return {};
192
+ }
193
+ const idx = this.#reader.readConstrainedInt(0, type.alts.length - 1);
194
+ const alt = type.alts[idx];
195
+ if (!alt) {
196
+ this.#bailed = true;
197
+ return {};
198
+ }
199
+ return { [alt.name]: this.#decode(alt.type) };
200
+ }
201
+ #decodeRef(type) {
202
+ const resolved = this.#table[type.name];
203
+ if (!resolved) {
204
+ this.#bailed = true;
205
+ return undefined;
206
+ }
207
+ return this.#decode(resolved);
208
+ }
209
+ }
210
+ exports.PerDecoder = PerDecoder;
211
+ _a = PerDecoder;
@@ -0,0 +1,64 @@
1
+ /**
2
+ * PerReader — a clamping, never-throwing bit cursor for ASN.1 ALIGNED BASIC-PER (ITU-T X.691 / GB/T
3
+ * 16263.2), used to decode the CMS (DL/T 2811-2024) service data area for DISPLAY. It reads from a
4
+ * Buffer with a bit position and octet-aligns on demand. Past the end of the buffer every read returns
5
+ * zero/empty rather than throwing, so a truncated or mis-typed frame degrades gracefully (the CMS layer
6
+ * keeps the raw bytes verbatim as the authoritative encode form regardless).
7
+ *
8
+ * ALIGNED-PER rules implemented here (the parts CMS ACSI needs):
9
+ * - a constrained INTEGER whose range ≤ 255 packs in ceil(log2(range)) bits with NO alignment;
10
+ * - a constrained INTEGER whose range is larger, and every length determinant, OCTET/BIT STRING and
11
+ * character-string content, octet-aligns first;
12
+ * - a length determinant is 1 octet when < 128, else 2 octets (top bits 10) up to 16383 (fragmentation
13
+ * for larger values is reported so the caller can bail to verbatim).
14
+ */
15
+ export declare class PerReader {
16
+ #private;
17
+ constructor(buf: Buffer);
18
+ /** Current byte position (rounded down). */
19
+ bytePos(): number;
20
+ /** Bits still available. */
21
+ bitsRemaining(): number;
22
+ /** Read one bit (0 past the end). */
23
+ readBit(): number;
24
+ /** Read n bits as an unsigned number (n ≤ 32; 0 past the end). */
25
+ readBits(n: number): number;
26
+ /** Advance to the next octet boundary. */
27
+ align(): void;
28
+ /** Read n whole octets (octet-aligns first). Clamps the returned slice to the buffer; the cursor still
29
+ * advances the full n octets so repeated past-the-end reads stay monotonic (never rewind). */
30
+ readOctets(n: number): Buffer;
31
+ /**
32
+ * A constrained INTEGER in [lb, ub], ALIGNED-PER (X.691 §11.5.7): range==1 → 0 bits (the value is lb);
33
+ * range ≤ 255 → the minimal bit-field, no alignment; range == 256 → one octet-aligned octet; range in
34
+ * 257..65536 → two octet-aligned octets; range > 65536 → a length determinant (octet count) then that
35
+ * many octet-aligned octets (§11.5.7.4). Multiplication is used for the octet accumulation so 32-bit
36
+ * values do not overflow a shift.
37
+ */
38
+ readConstrainedInt(lb: number, ub: number): number;
39
+ /**
40
+ * A general length determinant (X.691 §10.9). Octet-aligns first. Returns {value, fragmented}: 1 octet
41
+ * for 0..127, 2 octets for 128..16383, otherwise the fragmented form (16k-block count) which the
42
+ * caller should treat as "bail to verbatim".
43
+ */
44
+ readLengthDeterminant(): {
45
+ value: number;
46
+ fragmented: boolean;
47
+ };
48
+ /** A VisibleString / character string with a length determinant then octet-aligned content. */
49
+ readLengthPrefixedString(): string;
50
+ /**
51
+ * Read n characters of a known-multiplier character string (8 bits/char in ALIGNED-PER, e.g.
52
+ * VisibleString). Aligned-PER octet-aligns the content, EXCEPT a fixed string whose whole size is ≤ 16
53
+ * bits packs its 8-bit chars contiguously with no alignment (X.691 small-string exception). Pass
54
+ * aligned=false for that case.
55
+ */
56
+ readCharString(n: number, aligned: boolean): string;
57
+ /**
58
+ * Read a fixed-size BIT STRING of `nBits` bits, returning it as hex, the bits left-aligned (MSB first)
59
+ * into ceil(nBits/8) octets with trailing zero padding — the usual BIT STRING display form. Pass
60
+ * aligned=true (octet-align the content first) for strings wider than 16 bits; ≤16-bit fixed strings
61
+ * pack unaligned (X.691 small-string exception).
62
+ */
63
+ readBitString(nBits: number, aligned: boolean): string;
64
+ }
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PerReader = void 0;
4
+ /**
5
+ * PerReader — a clamping, never-throwing bit cursor for ASN.1 ALIGNED BASIC-PER (ITU-T X.691 / GB/T
6
+ * 16263.2), used to decode the CMS (DL/T 2811-2024) service data area for DISPLAY. It reads from a
7
+ * Buffer with a bit position and octet-aligns on demand. Past the end of the buffer every read returns
8
+ * zero/empty rather than throwing, so a truncated or mis-typed frame degrades gracefully (the CMS layer
9
+ * keeps the raw bytes verbatim as the authoritative encode form regardless).
10
+ *
11
+ * ALIGNED-PER rules implemented here (the parts CMS ACSI needs):
12
+ * - a constrained INTEGER whose range ≤ 255 packs in ceil(log2(range)) bits with NO alignment;
13
+ * - a constrained INTEGER whose range is larger, and every length determinant, OCTET/BIT STRING and
14
+ * character-string content, octet-aligns first;
15
+ * - a length determinant is 1 octet when < 128, else 2 octets (top bits 10) up to 16383 (fragmentation
16
+ * for larger values is reported so the caller can bail to verbatim).
17
+ */
18
+ class PerReader {
19
+ #buf;
20
+ #bit;
21
+ constructor(buf) {
22
+ this.#buf = buf;
23
+ this.#bit = 0;
24
+ }
25
+ /** Current byte position (rounded down). */
26
+ bytePos() {
27
+ return this.#bit >> 3;
28
+ }
29
+ /** Bits still available. */
30
+ bitsRemaining() {
31
+ return this.#buf.length * 8 - this.#bit;
32
+ }
33
+ /** Read one bit (0 past the end). */
34
+ readBit() {
35
+ if (this.#bit >= this.#buf.length * 8) {
36
+ this.#bit++;
37
+ return 0;
38
+ }
39
+ const byte = this.#buf[this.#bit >> 3];
40
+ const bit = (byte >> (7 - (this.#bit & 7))) & 1;
41
+ this.#bit++;
42
+ return bit;
43
+ }
44
+ /** Read n bits as an unsigned number (n ≤ 32; 0 past the end). */
45
+ readBits(n) {
46
+ let value = 0;
47
+ for (let i = 0; i < n; i++)
48
+ value = (value << 1) | this.readBit();
49
+ return value >>> 0;
50
+ }
51
+ /** Advance to the next octet boundary. */
52
+ align() {
53
+ if (this.#bit & 7)
54
+ this.#bit = (this.#bit + 7) & ~7;
55
+ }
56
+ /** Read n whole octets (octet-aligns first). Clamps the returned slice to the buffer; the cursor still
57
+ * advances the full n octets so repeated past-the-end reads stay monotonic (never rewind). */
58
+ readOctets(n) {
59
+ this.align();
60
+ const start = this.#bit >> 3;
61
+ const end = start + n;
62
+ this.#bit = end * 8;
63
+ const sliceStart = start > this.#buf.length ? this.#buf.length : start;
64
+ const sliceEnd = end > this.#buf.length ? this.#buf.length : end;
65
+ return this.#buf.subarray(sliceStart, sliceEnd < sliceStart ? sliceStart : sliceEnd);
66
+ }
67
+ /**
68
+ * A constrained INTEGER in [lb, ub], ALIGNED-PER (X.691 §11.5.7): range==1 → 0 bits (the value is lb);
69
+ * range ≤ 255 → the minimal bit-field, no alignment; range == 256 → one octet-aligned octet; range in
70
+ * 257..65536 → two octet-aligned octets; range > 65536 → a length determinant (octet count) then that
71
+ * many octet-aligned octets (§11.5.7.4). Multiplication is used for the octet accumulation so 32-bit
72
+ * values do not overflow a shift.
73
+ */
74
+ readConstrainedInt(lb, ub) {
75
+ const range = ub - lb + 1;
76
+ if (range <= 1)
77
+ return lb;
78
+ if (range < 256) {
79
+ let bits = 0;
80
+ while ((1 << bits) < range)
81
+ bits++;
82
+ return lb + this.readBits(bits);
83
+ }
84
+ if (range === 256)
85
+ return lb + (this.readOctets(1)[0] ?? 0);
86
+ if (range <= 65536) {
87
+ const two = this.readOctets(2);
88
+ return lb + (((two[0] ?? 0) << 8) | (two[1] ?? 0));
89
+ }
90
+ //range > 65536: length-determinant-prefixed minimal-octet form, octet-aligned.
91
+ const length = this.readLengthDeterminant();
92
+ if (length.fragmented)
93
+ return lb;
94
+ const buf = this.readOctets(length.value);
95
+ let value = 0;
96
+ for (let i = 0; i < buf.length; i++)
97
+ value = (value * 256) + buf[i];
98
+ return lb + value;
99
+ }
100
+ /**
101
+ * A general length determinant (X.691 §10.9). Octet-aligns first. Returns {value, fragmented}: 1 octet
102
+ * for 0..127, 2 octets for 128..16383, otherwise the fragmented form (16k-block count) which the
103
+ * caller should treat as "bail to verbatim".
104
+ */
105
+ readLengthDeterminant() {
106
+ this.align();
107
+ const first = this.readOctets(1)[0] ?? 0;
108
+ if ((first & 0x80) === 0)
109
+ return { value: first & 0x7f, fragmented: false };
110
+ if ((first & 0xc0) === 0x80) {
111
+ const second = this.readOctets(1)[0] ?? 0;
112
+ return { value: ((first & 0x3f) << 8) | second, fragmented: false };
113
+ }
114
+ //Fragmented (top bits 11): the low 6 bits × 16384 is the first block size; not fully decoded here.
115
+ return { value: (first & 0x3f) * 16384, fragmented: true };
116
+ }
117
+ /** A VisibleString / character string with a length determinant then octet-aligned content. */
118
+ readLengthPrefixedString() {
119
+ const length = this.readLengthDeterminant();
120
+ if (length.fragmented)
121
+ return '';
122
+ return this.readOctets(length.value).toString('latin1');
123
+ }
124
+ /**
125
+ * Read n characters of a known-multiplier character string (8 bits/char in ALIGNED-PER, e.g.
126
+ * VisibleString). Aligned-PER octet-aligns the content, EXCEPT a fixed string whose whole size is ≤ 16
127
+ * bits packs its 8-bit chars contiguously with no alignment (X.691 small-string exception). Pass
128
+ * aligned=false for that case.
129
+ */
130
+ readCharString(n, aligned) {
131
+ if (aligned)
132
+ return this.readOctets(n).toString('latin1');
133
+ let out = '';
134
+ for (let i = 0; i < n; i++)
135
+ out += String.fromCharCode(this.readBits(8));
136
+ return out;
137
+ }
138
+ /**
139
+ * Read a fixed-size BIT STRING of `nBits` bits, returning it as hex, the bits left-aligned (MSB first)
140
+ * into ceil(nBits/8) octets with trailing zero padding — the usual BIT STRING display form. Pass
141
+ * aligned=true (octet-align the content first) for strings wider than 16 bits; ≤16-bit fixed strings
142
+ * pack unaligned (X.691 small-string exception).
143
+ */
144
+ readBitString(nBits, aligned) {
145
+ if (aligned)
146
+ this.align();
147
+ const out = Buffer.alloc(Math.ceil(nBits / 8));
148
+ for (let i = 0; i < nBits; i++) {
149
+ if (this.readBit())
150
+ out[i >> 3] |= 0x80 >> (i & 7);
151
+ }
152
+ return out.toString('hex');
153
+ }
154
+ }
155
+ exports.PerReader = PerReader;
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Convert a buffer to a lower-case hex string (two hex chars per byte, zero-padded).
3
+ * @param buffer
4
+ */
5
+ export declare function BufferToHex(buffer: Buffer): string;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BufferToHex = BufferToHex;
4
+ /**
5
+ * Convert a buffer to a lower-case hex string (two hex chars per byte, zero-padded).
6
+ * @param buffer
7
+ */
8
+ function BufferToHex(buffer) {
9
+ return buffer.toString('hex').padStart(buffer.length * 2, '0');
10
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Convert Buffer to IPv4 string
3
+ * @param buffer
4
+ * @constructor
5
+ */
6
+ export declare function BufferToIPv4(buffer: Buffer): string;
7
+ /**
8
+ * Convert Buffer to IPv6 string
9
+ * @param buffer
10
+ * @constructor
11
+ */
12
+ export declare function BufferToIPv6(buffer: Buffer): string;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BufferToIPv4 = BufferToIPv4;
4
+ exports.BufferToIPv6 = BufferToIPv6;
5
+ const ip_address_1 = require("ip-address");
6
+ /**
7
+ * Convert Buffer to IPv4 string
8
+ * @param buffer
9
+ * @constructor
10
+ */
11
+ function BufferToIPv4(buffer) {
12
+ //Direct dotted-quad formatting; the old ip-address-library + BigInt + hex path micro-benchmarked
13
+ //~20x slower per address. Missing bytes read as 0, matching the previous zero-padded behaviour.
14
+ return `${buffer.length > 0 ? buffer[0] : 0}.${buffer.length > 1 ? buffer[1] : 0}.${buffer.length > 2 ? buffer[2] : 0}.${buffer.length > 3 ? buffer[3] : 0}`;
15
+ }
16
+ /**
17
+ * Convert Buffer to IPv6 string
18
+ * @param buffer
19
+ * @constructor
20
+ */
21
+ function BufferToIPv6(buffer) {
22
+ return ip_address_1.Address6.fromBigInt(BigInt(`0x${Buffer.concat([buffer.subarray(0, 16), Buffer.alloc(16)]).subarray(0, 16).toString('hex').padStart(32, '0')}`)).address;
23
+ }
@@ -0,0 +1,18 @@
1
+ /** Read a signed 8-bit integer from the start of `buffer` (0 when empty). */
2
+ export declare const BufferToInt8: (buffer: Buffer) => number;
3
+ /** Read a big-endian signed 16-bit integer from the start of `buffer` (short buffers read their available low bytes unsigned). */
4
+ export declare const BufferToInt16: (buffer: Buffer) => number;
5
+ /** Read a big-endian signed 32-bit integer from the start of `buffer` (short buffers read their available low bytes unsigned). */
6
+ export declare const BufferToInt32: (buffer: Buffer) => number;
7
+ /** Read a big-endian signed 64-bit integer from `buffer` as a bigint (clamped to the int64 range on overflow). */
8
+ export declare const BufferToInt64: (buffer: Buffer) => bigint;
9
+ /** Read an unsigned 8-bit integer from the start of `buffer` (0 when empty). */
10
+ export declare const BufferToUInt8: (buffer: Buffer) => number;
11
+ /** Read a big-endian unsigned 16-bit integer from the start of `buffer` (short buffers read their available low bytes). */
12
+ export declare const BufferToUInt16: (buffer: Buffer) => number;
13
+ /** Read a big-endian unsigned 32-bit integer from the start of `buffer` (short buffers read their available low bytes). */
14
+ export declare const BufferToUInt32: (buffer: Buffer) => number;
15
+ /** Read a big-endian unsigned 64-bit integer from `buffer` as a bigint (clamped to the uint64 range on overflow). */
16
+ export declare const BufferToUInt64: (buffer: Buffer) => bigint;
17
+ /** Read a big-endian IEEE-754 32-bit float from `buffer`. */
18
+ export declare const BufferToFloat32: (buffer: Buffer) => number;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BufferToFloat32 = exports.BufferToUInt64 = exports.BufferToUInt32 = exports.BufferToUInt16 = exports.BufferToUInt8 = exports.BufferToInt64 = exports.BufferToInt32 = exports.BufferToInt16 = exports.BufferToInt8 = void 0;
4
+ const HexToNumber_1 = require("./HexToNumber");
5
+ //8/16/32-bit reads use native Buffer accessors instead of the old hex-string roundtrip
6
+ //(buffer.toString('hex') → parseInt → TypedArray), which micro-benchmarked ~27x slower per call and
7
+ //runs on every scalar field of every packet. Behaviour is preserved bit-for-bit, including the
8
+ //best-effort handling of short/truncated buffers: missing high bytes read as 0, so a partial buffer
9
+ //yields the value of its available low bytes (verified equivalent across full/short/empty/signed/edge
10
+ //cases). Signed reads fall back to an unsigned low-byte read when the buffer is shorter than the type
11
+ //width — at less than full width the high (sign) byte is absent, so the value is always non-negative,
12
+ //exactly as the hex path produced it. 64-bit and float paths keep their existing implementations
13
+ //(64-bit carries clamping semantics; both are comparatively rare).
14
+ //
15
+ //ONE deliberate semantic change vs the old hex path: for a buffer LONGER than the type width, the
16
+ //native readers take the big-endian high bytes (readUInt16BE reads the first 2 octets), whereas the
17
+ //old parseInt→TypedArray path wrapped to the low bytes. Big-endian is the correct network-byte-order
18
+ //reading. This is only reachable via variable-length callers (SV's BER-TLV getValue('buffer')); the
19
+ //fixed-width readBytes(offset,N) callers can never produce an over-wide buffer. Not a round-trip
20
+ //regression (over-wide TLVs are re-normalised on encode); affects only a malformed packet's shown value.
21
+ /** Read a signed 8-bit integer from the start of `buffer` (0 when empty). */
22
+ const BufferToInt8 = (buffer) => buffer.length ? buffer.readInt8(0) : 0;
23
+ exports.BufferToInt8 = BufferToInt8;
24
+ /** Read a big-endian signed 16-bit integer from the start of `buffer` (short buffers read their available low bytes unsigned). */
25
+ const BufferToInt16 = (buffer) => buffer.length >= 2 ? buffer.readInt16BE(0) : (buffer.length ? buffer.readUIntBE(0, buffer.length) : 0);
26
+ exports.BufferToInt16 = BufferToInt16;
27
+ /** Read a big-endian signed 32-bit integer from the start of `buffer` (short buffers read their available low bytes unsigned). */
28
+ const BufferToInt32 = (buffer) => buffer.length >= 4 ? buffer.readInt32BE(0) : (buffer.length ? buffer.readUIntBE(0, buffer.length) : 0);
29
+ exports.BufferToInt32 = BufferToInt32;
30
+ /** Read a big-endian signed 64-bit integer from `buffer` as a bigint (clamped to the int64 range on overflow). */
31
+ const BufferToInt64 = (buffer) => (0, HexToNumber_1.HexToInt64)(buffer.toString('hex'));
32
+ exports.BufferToInt64 = BufferToInt64;
33
+ /** Read an unsigned 8-bit integer from the start of `buffer` (0 when empty). */
34
+ const BufferToUInt8 = (buffer) => buffer.length ? buffer.readUInt8(0) : 0;
35
+ exports.BufferToUInt8 = BufferToUInt8;
36
+ /** Read a big-endian unsigned 16-bit integer from the start of `buffer` (short buffers read their available low bytes). */
37
+ const BufferToUInt16 = (buffer) => buffer.length >= 2 ? buffer.readUInt16BE(0) : (buffer.length ? buffer.readUIntBE(0, buffer.length) : 0);
38
+ exports.BufferToUInt16 = BufferToUInt16;
39
+ /** Read a big-endian unsigned 32-bit integer from the start of `buffer` (short buffers read their available low bytes). */
40
+ const BufferToUInt32 = (buffer) => buffer.length >= 4 ? buffer.readUInt32BE(0) : (buffer.length ? buffer.readUIntBE(0, buffer.length) : 0);
41
+ exports.BufferToUInt32 = BufferToUInt32;
42
+ /** Read a big-endian unsigned 64-bit integer from `buffer` as a bigint (clamped to the uint64 range on overflow). */
43
+ const BufferToUInt64 = (buffer) => (0, HexToNumber_1.HexToUInt64)(buffer.toString('hex'));
44
+ exports.BufferToUInt64 = BufferToUInt64;
45
+ /** Read a big-endian IEEE-754 32-bit float from `buffer`. */
46
+ const BufferToFloat32 = (buffer) => (0, HexToNumber_1.HexToFloat32)(buffer.toString('hex'));
47
+ exports.BufferToFloat32 = BufferToFloat32;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Convert hex to buffer
3
+ * @param hex
4
+ * @param bufferLength
5
+ * @constructor
6
+ */
7
+ export declare function HexToBuffer(hex: string, bufferLength?: number): Buffer;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HexToBuffer = HexToBuffer;
4
+ /**
5
+ * Convert hex to buffer
6
+ * @param hex
7
+ * @param bufferLength
8
+ * @constructor
9
+ */
10
+ function HexToBuffer(hex, bufferLength) {
11
+ if (!hex)
12
+ return Buffer.alloc(0);
13
+ const inputHex = hex.length % 2 ? hex.padStart(hex.length + 1, '0') : hex;
14
+ const outputBufferLength = bufferLength ? bufferLength : inputHex.length / 2;
15
+ let buffer = Buffer.from(inputHex, 'hex');
16
+ if (buffer.length > outputBufferLength) {
17
+ buffer.subarray(0, outputBufferLength);
18
+ }
19
+ else if (buffer.length < outputBufferLength) {
20
+ const paddingLength = outputBufferLength - buffer.length;
21
+ buffer = Buffer.concat([
22
+ Buffer.alloc(paddingLength, 0x00),
23
+ buffer
24
+ ]);
25
+ }
26
+ return buffer;
27
+ }
@@ -0,0 +1,18 @@
1
+ /** Parse a hex string as a signed 8-bit integer (two's complement). */
2
+ export declare const HexToInt8: (hex: string) => number;
3
+ /** Parse a big-endian hex string as a signed 16-bit integer (two's complement). */
4
+ export declare const HexToInt16: (hex: string) => number;
5
+ /** Parse a big-endian hex string as a signed 32-bit integer (two's complement). */
6
+ export declare const HexToInt32: (hex: string) => number;
7
+ /** Parse a big-endian hex string as a signed 64-bit bigint (clamped to the int64 range on overflow). */
8
+ export declare const HexToInt64: (hex: string) => bigint;
9
+ /** Parse a hex string as an unsigned 8-bit integer. */
10
+ export declare const HexToUInt8: (hex: string) => number;
11
+ /** Parse a big-endian hex string as an unsigned 16-bit integer. */
12
+ export declare const HexToUInt16: (hex: string) => number;
13
+ /** Parse a big-endian hex string as an unsigned 32-bit integer. */
14
+ export declare const HexToUInt32: (hex: string) => number;
15
+ /** Parse a big-endian hex string as an unsigned 64-bit bigint (clamped to the uint64 range on overflow). */
16
+ export declare const HexToUInt64: (hex: string) => bigint;
17
+ /** Parse a big-endian hex string as an IEEE-754 32-bit float. */
18
+ export declare const HexToFloat32: (hex: string) => number;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HexToFloat32 = exports.HexToUInt64 = exports.HexToUInt32 = exports.HexToUInt16 = exports.HexToUInt8 = exports.HexToInt64 = exports.HexToInt32 = exports.HexToInt16 = exports.HexToInt8 = void 0;
4
+ /** Parse a hex string as a signed 8-bit integer (two's complement). */
5
+ const HexToInt8 = (hex) => Int8Array.from([parseInt(hex, 16)])[0];
6
+ exports.HexToInt8 = HexToInt8;
7
+ /** Parse a big-endian hex string as a signed 16-bit integer (two's complement). */
8
+ const HexToInt16 = (hex) => Int16Array.from([parseInt(hex, 16)])[0];
9
+ exports.HexToInt16 = HexToInt16;
10
+ /** Parse a big-endian hex string as a signed 32-bit integer (two's complement). */
11
+ const HexToInt32 = (hex) => Int32Array.from([parseInt(hex, 16)])[0];
12
+ exports.HexToInt32 = HexToInt32;
13
+ /** Parse a big-endian hex string as a signed 64-bit bigint (clamped to the int64 range on overflow). */
14
+ const HexToInt64 = (hex) => {
15
+ const INT64_MAX = BigInt('9223372036854775807');
16
+ const INT64_MIN = BigInt('-9223372036854775808');
17
+ const bigIntValue = BigInt(`0x${hex}`);
18
+ if (bigIntValue < INT64_MIN || bigIntValue > INT64_MAX)
19
+ return INT64_MAX;
20
+ return bigIntValue;
21
+ };
22
+ exports.HexToInt64 = HexToInt64;
23
+ /** Parse a hex string as an unsigned 8-bit integer. */
24
+ const HexToUInt8 = (hex) => Uint8Array.from([parseInt(hex, 16)])[0];
25
+ exports.HexToUInt8 = HexToUInt8;
26
+ /** Parse a big-endian hex string as an unsigned 16-bit integer. */
27
+ const HexToUInt16 = (hex) => Uint16Array.from([parseInt(hex, 16)])[0];
28
+ exports.HexToUInt16 = HexToUInt16;
29
+ /** Parse a big-endian hex string as an unsigned 32-bit integer. */
30
+ const HexToUInt32 = (hex) => Uint32Array.from([parseInt(hex, 16)])[0];
31
+ exports.HexToUInt32 = HexToUInt32;
32
+ /** Parse a big-endian hex string as an unsigned 64-bit bigint (clamped to the uint64 range on overflow). */
33
+ const HexToUInt64 = (hex) => {
34
+ const INT64_MAX = BigInt('18446744073709551615');
35
+ const bigIntValue = BigInt(`0x${hex}`);
36
+ if (bigIntValue < 0n || bigIntValue > INT64_MAX)
37
+ return INT64_MAX;
38
+ return bigIntValue;
39
+ };
40
+ exports.HexToUInt64 = HexToUInt64;
41
+ /** Parse a big-endian hex string as an IEEE-754 32-bit float. */
42
+ const HexToFloat32 = (hex) => {
43
+ const buffer = new ArrayBuffer(4);
44
+ const dataView = new DataView(buffer);
45
+ dataView.setUint32(0, parseInt(hex, 16), false);
46
+ return dataView.getFloat32(0, false);
47
+ };
48
+ exports.HexToFloat32 = HexToFloat32;