@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,177 @@
1
+ "use strict";
2
+ var _a;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.STOMP = void 0;
5
+ const BaseHeader_1 = require("../abstracts/BaseHeader");
6
+ const BufferToHex_1 = require("../helper/BufferToHex");
7
+ const HexToBuffer_1 = require("../helper/HexToBuffer");
8
+ const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
9
+ /** STOMP frame commands (STOMP 1.2) used only to recognize a frame's start-line. */
10
+ const STOMP_COMMANDS = ['CONNECT', 'STOMP', 'CONNECTED', 'SEND', 'SUBSCRIBE', 'UNSUBSCRIBE', 'ACK', 'NACK', 'BEGIN', 'COMMIT', 'ABORT', 'DISCONNECT', 'MESSAGE', 'RECEIPT', 'ERROR'];
11
+ /**
12
+ * STOMP — the Simple (or Streaming) Text Oriented Messaging Protocol (STOMP 1.2), a text framing for
13
+ * message brokers, carried over TCP (well-known port 61613, the ActiveMQ default). A STOMP frame is
14
+ * US-ASCII text: a COMMAND line, then zero or more `header:value` lines, a blank line, an optional body,
15
+ * and a terminating NUL (0x00):
16
+ *
17
+ * COMMAND{EOL}
18
+ * header1:value1{EOL}
19
+ * header2:value2{EOL}
20
+ * {EOL}
21
+ * body^@
22
+ *
23
+ * where {EOL} is a line feed (STOMP 1.2 also permits CR LF) and ^@ is the NUL octet. Between frames a
24
+ * client/server may send a bare {EOL} as a heartbeat.
25
+ *
26
+ * Like SIP/Ident/HTTP (the verbatim-message pattern): a frame is free-form text — arbitrary header
27
+ * ordering, header-value escaping (\c \n \r \\), and a body of any content-type whose length may be an
28
+ * explicit `content-length` header or run to the NUL — so the exact bytes a peer sees are richer than a
29
+ * form needs and whitespace/ordering is significant. The ENTIRE raw payload is therefore the single
30
+ * source of truth: decoded verbatim to hex in the authoritative `message` field and re-emitted
31
+ * byte-for-byte on encode. On top of that the frame's COMMAND line and a few common display headers
32
+ * (destination, content-type, content-length) are parsed into DISPLAY-ONLY metadata; those carry no
33
+ * codec of their own and never reconstruct the bytes — the message owns them. So any STOMP frame
34
+ * round-trips exactly.
35
+ *
36
+ * Framing: STOMP frames are NUL-terminated and several may be pipelined in one TCP segment, but — like
37
+ * the other text verbatim leaves (SIP/HTTP/Ident) and because TCP carries no per-message length here —
38
+ * this terminal layer consumes to the end of the segment and keeps it as one verbatim `message`. A
39
+ * well-formed single-frame segment round-trips byte-for-byte.
40
+ *
41
+ * Matching rationale (NO heuristicFallback): STOMP is claimed ONLY on the tcp:61613 bucket, and only
42
+ * when the first line is a known STOMP command — a defensive content gate (like SIP's start-line) so
43
+ * non-STOMP traffic on 61613 falls losslessly to raw. Joining the global content-heuristic chain would
44
+ * risk mislabeling arbitrary text TCP payloads on any port, so selection stays port-bucketed.
45
+ */
46
+ class STOMP extends BaseHeader_1.BaseHeader {
47
+ constructor() {
48
+ super(...arguments);
49
+ this.id = 'stomp';
50
+ this.name = 'Simple Text Oriented Messaging Protocol';
51
+ this.nickname = 'STOMP';
52
+ //STOMP is recognized ONLY on the well-known port 61613 — deliberately NOT via heuristicFallback. A
53
+ //STOMP frame is US-ASCII text; joining the global heuristic chain would mislabel arbitrary text TCP
54
+ //payloads on any port. Confining STOMP to tcp:61613 + a command-line gate keeps that impossible;
55
+ //alt-port STOMP is rare and falls losslessly to raw. See the class doc for the full rationale.
56
+ this.matchKeys = ['tcpport:61613'];
57
+ //A leaf header — a STOMP frame's body is an opaque message payload; nothing demuxes off it.
58
+ this.demuxProducers = [];
59
+ }
60
+ static #schemaCache;
61
+ get SCHEMA() {
62
+ return (_a.#schemaCache ??= _a.#buildSchema());
63
+ }
64
+ /** Bytes available to this header: STOMP rides on TCP, which has no per-message length. */
65
+ #payloadLength() {
66
+ const available = this.packet.length - this.startPos;
67
+ return available < 0 ? 0 : available;
68
+ }
69
+ /** The first line of the payload (up to the first LF, CR stripped), or the whole payload if none. */
70
+ static #firstLine(text) {
71
+ const lf = text.indexOf('\n');
72
+ let line = lf >= 0 ? text.slice(0, lf) : text;
73
+ if (line.endsWith('\r'))
74
+ line = line.slice(0, -1);
75
+ return line;
76
+ }
77
+ /**
78
+ * Parse the COMMAND line and a few common headers into the display-only metadata fields. The frame
79
+ * is `COMMAND{EOL}(header:value{EOL})*{EOL}body`. Populated on decode only — these fields have no
80
+ * encode, so they never affect the re-emitted bytes and never mutate `message`. Never throws:
81
+ * missing tokens yield empty strings / 0.
82
+ */
83
+ #parse(text) {
84
+ const command = _a.#firstLine(text);
85
+ this.instance.command.setValue(command);
86
+ //Walk the header lines (COMMAND line already consumed) up to the blank line that ends the
87
+ //headers; pull the common display headers. Header names are case-sensitive in STOMP 1.2.
88
+ let destination = '';
89
+ let contentType = '';
90
+ let contentLength = 0;
91
+ const lines = text.split('\n');
92
+ for (let i = 1; i < lines.length; i++) {
93
+ let line = lines[i];
94
+ if (line.endsWith('\r'))
95
+ line = line.slice(0, -1);
96
+ if (line === '')
97
+ break;
98
+ const colon = line.indexOf(':');
99
+ if (colon < 0)
100
+ continue;
101
+ const key = line.slice(0, colon);
102
+ const value = line.slice(colon + 1);
103
+ if (key === 'destination' && destination === '')
104
+ destination = value;
105
+ else if (key === 'content-type' && contentType === '')
106
+ contentType = value;
107
+ else if (key === 'content-length' && contentLength === 0) {
108
+ const parsed = parseInt(value.trim(), 10);
109
+ if (Number.isFinite(parsed) && parsed > 0)
110
+ contentLength = parsed;
111
+ }
112
+ }
113
+ this.instance.destination.setValue(destination);
114
+ this.instance.contentType.setValue(contentType);
115
+ this.instance.contentLength.setValue(contentLength);
116
+ this.instance.summaryInfo.setValue(destination ? `${command} ${destination}` : command);
117
+ }
118
+ static #buildSchema() {
119
+ return {
120
+ type: 'object',
121
+ summary: 'STOMP ${summaryInfo}',
122
+ properties: {
123
+ //Display-only metadata parsed from the frame on decode (no encode — populated by the
124
+ //`message` field below, never read back). command is the frame's COMMAND line;
125
+ //destination/content-type/content-length are the common headers, present when the frame
126
+ //carries them.
127
+ command: { type: 'string', label: 'Command', default: '' },
128
+ destination: { type: 'string', label: 'Destination', default: '' },
129
+ contentType: { type: 'string', label: 'Content Type', default: '' },
130
+ contentLength: { type: 'integer', label: 'Content Length', minimum: 0, default: 0 },
131
+ //Drives the one-line summary (COMMAND + destination when present).
132
+ summaryInfo: { type: 'string', label: 'Summary', hidden: true, default: '' },
133
+ //The whole raw payload is the single source of truth: decoded verbatim to hex and
134
+ //re-emitted untouched (byte-perfect for any STOMP frame). The COMMAND line and common
135
+ //headers are parsed into the display-only metadata above, which carry no codec of their own.
136
+ message: {
137
+ type: 'string',
138
+ label: 'Message',
139
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
140
+ default: '',
141
+ decode: function () {
142
+ const available = this.#payloadLength();
143
+ if (available <= 0) {
144
+ this.instance.message.setValue('');
145
+ this.#parse('');
146
+ return;
147
+ }
148
+ const raw = this.readBytes(0, available);
149
+ this.instance.message.setValue((0, BufferToHex_1.BufferToHex)(raw));
150
+ this.#parse(raw.toString('latin1'));
151
+ },
152
+ encode: function () {
153
+ //Re-emit the authoritative payload verbatim — never reconstruct from metadata.
154
+ this.writeBytes(0, (0, HexToBuffer_1.HexToBuffer)(this.instance.message.getValue('')));
155
+ }
156
+ }
157
+ }
158
+ };
159
+ }
160
+ match() {
161
+ //Reached only on the tcp:61613 bucket. Recognize STOMP by its start-line signature: the first
162
+ //line (up to the first LF) is a known STOMP command — so non-STOMP traffic on 61613 (and bare
163
+ //heartbeat newlines) falls through to raw rather than claiming an un-decodable text layer.
164
+ if (!this.prevCodecModule)
165
+ return false;
166
+ if (this.prevCodecModule.id !== 'tcp')
167
+ return false;
168
+ if (this.#payloadLength() <= 0)
169
+ return false;
170
+ //Read a small lead window (long enough for the longest command + terminator) without advancing.
171
+ const lead = this.readBytes(0, 16, true).toString('latin1');
172
+ const line = _a.#firstLine(lead);
173
+ return STOMP_COMMANDS.includes(line);
174
+ }
175
+ }
176
+ exports.STOMP = STOMP;
177
+ _a = STOMP;
@@ -0,0 +1,26 @@
1
+ import { BaseHeader } from '../abstracts/BaseHeader';
2
+ import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
3
+ import { DemuxProducer } from '../types/DemuxProducer';
4
+ /**
5
+ * STP — Spanning Tree Protocol BPDU (IEEE 802.1D, and RSTP/MSTP 802.1w/s), carried in an 802.3 frame
6
+ * over LLC with DSAP/SSAP 0x42. Every BPDU opens with a 4-byte fixed part: a 2-byte Protocol Identifier
7
+ * (0x0000), a 1-byte Protocol Version (0 STP, 2 RSTP, 3 MSTP) and a 1-byte BPDU Type (0x00 Configuration,
8
+ * 0x02 RST/MST, 0x80 Topology Change Notification).
9
+ *
10
+ * A Configuration / RST BPDU (type 0x00 / 0x02) then carries the full spanning-tree state — Flags, Root
11
+ * Identifier, Root Path Cost, Bridge Identifier, Port Identifier and the four timers (Message Age, Max
12
+ * Age, Hello Time, Forward Delay) — plus, for RST/MST, a trailing remainder (Version 1 Length + any MST
13
+ * extension) kept verbatim as `extra` hex. A TCN BPDU (type 0x80) is just the 4-byte fixed part. The
14
+ * body fields are decoded/encoded only for Configuration/RST types, so a TCN BPDU round-trips as exactly
15
+ * 4 bytes. A well-formed BPDU round-trips byte-for-byte; trailing 802.3 padding falls to RawData.
16
+ */
17
+ export declare class STP extends BaseHeader {
18
+ #private;
19
+ get SCHEMA(): ProtocolJSONSchema;
20
+ readonly id: string;
21
+ readonly name: string;
22
+ readonly nickname: string;
23
+ readonly matchKeys: string[];
24
+ match(): boolean;
25
+ readonly demuxProducers: DemuxProducer[];
26
+ }
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STP = void 0;
4
+ const BaseHeader_1 = require("../abstracts/BaseHeader");
5
+ const BufferToHex_1 = require("../helper/BufferToHex");
6
+ const HexToBuffer_1 = require("../helper/HexToBuffer");
7
+ const BufferToNumber_1 = require("../helper/BufferToNumber");
8
+ const NumberToBuffer_1 = require("../helper/NumberToBuffer");
9
+ const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
10
+ /**
11
+ * STP — Spanning Tree Protocol BPDU (IEEE 802.1D, and RSTP/MSTP 802.1w/s), carried in an 802.3 frame
12
+ * over LLC with DSAP/SSAP 0x42. Every BPDU opens with a 4-byte fixed part: a 2-byte Protocol Identifier
13
+ * (0x0000), a 1-byte Protocol Version (0 STP, 2 RSTP, 3 MSTP) and a 1-byte BPDU Type (0x00 Configuration,
14
+ * 0x02 RST/MST, 0x80 Topology Change Notification).
15
+ *
16
+ * A Configuration / RST BPDU (type 0x00 / 0x02) then carries the full spanning-tree state — Flags, Root
17
+ * Identifier, Root Path Cost, Bridge Identifier, Port Identifier and the four timers (Message Age, Max
18
+ * Age, Hello Time, Forward Delay) — plus, for RST/MST, a trailing remainder (Version 1 Length + any MST
19
+ * extension) kept verbatim as `extra` hex. A TCN BPDU (type 0x80) is just the 4-byte fixed part. The
20
+ * body fields are decoded/encoded only for Configuration/RST types, so a TCN BPDU round-trips as exactly
21
+ * 4 bytes. A well-formed BPDU round-trips byte-for-byte; trailing 802.3 padding falls to RawData.
22
+ */
23
+ class STP extends BaseHeader_1.BaseHeader {
24
+ constructor() {
25
+ super(...arguments);
26
+ this.id = 'stp';
27
+ this.name = 'Spanning Tree Protocol';
28
+ this.nickname = 'STP';
29
+ this.matchKeys = ['llcsap:66'];
30
+ //A leaf — a BPDU carries no encapsulated protocol.
31
+ this.demuxProducers = [];
32
+ }
33
+ static #schemaCache;
34
+ get SCHEMA() {
35
+ return (STP.#schemaCache ??= STP.#buildSchema());
36
+ }
37
+ /** Configuration (0x00) and RST/MST (0x02) BPDUs carry the full body; TCN (0x80) does not. */
38
+ #isConfig() {
39
+ const type = this.instance.bpduType.getValue(0);
40
+ return type === 0x00 || type === 0x02;
41
+ }
42
+ /** A body field present only on Configuration/RST BPDUs — read/written verbatim, skipped for TCN. */
43
+ static #bodyUInt(name, offset, byteLength, label) {
44
+ const max = byteLength === 1 ? 255 : byteLength === 2 ? 65535 : 4294967295;
45
+ return {
46
+ type: 'integer',
47
+ label: label,
48
+ minimum: 0,
49
+ maximum: max,
50
+ decode: function () {
51
+ if (!this.#isConfig())
52
+ return;
53
+ const buffer = this.readBytes(offset, byteLength);
54
+ const value = byteLength === 1 ? (0, BufferToNumber_1.BufferToUInt8)(buffer) : byteLength === 2 ? (0, BufferToNumber_1.BufferToUInt16)(buffer) : (0, BufferToNumber_1.BufferToUInt32)(buffer);
55
+ this.instance[name].setValue(value);
56
+ },
57
+ encode: function () {
58
+ if (!this.#isConfig())
59
+ return;
60
+ let value = this.instance[name].getValue(0);
61
+ if (value > max)
62
+ value = max;
63
+ if (value < 0)
64
+ value = 0;
65
+ const buffer = byteLength === 1 ? (0, NumberToBuffer_1.UInt8ToBuffer)(value) : byteLength === 2 ? (0, NumberToBuffer_1.UInt16ToBuffer)(value) : (0, NumberToBuffer_1.UInt32ToBuffer)(value);
66
+ this.writeBytes(offset, buffer);
67
+ }
68
+ };
69
+ }
70
+ /** A verbatim-hex body field present only on Configuration/RST BPDUs (identifiers). */
71
+ static #bodyHex(name, offset, byteLength, label) {
72
+ return {
73
+ type: 'string',
74
+ label: label,
75
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
76
+ decode: function () {
77
+ if (!this.#isConfig())
78
+ return;
79
+ this.instance[name].setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(offset, byteLength)));
80
+ },
81
+ encode: function () {
82
+ if (!this.#isConfig())
83
+ return;
84
+ const value = this.instance[name].getValue('');
85
+ if (value)
86
+ this.writeBytes(offset, (0, HexToBuffer_1.HexToBuffer)(value));
87
+ }
88
+ };
89
+ }
90
+ static #buildSchema() {
91
+ return {
92
+ type: 'object',
93
+ summary: 'STP type=${bpduType} version=${protocolVersion}',
94
+ properties: {
95
+ //Fixed 4-byte part, present on every BPDU.
96
+ protocolIdentifier: this.fieldHex('protocolIdentifier', 0, 2, 'Protocol Identifier'),
97
+ protocolVersion: this.fieldUInt('protocolVersion', 2, 1, 'Protocol Version'),
98
+ bpduType: this.fieldUInt('bpduType', 3, 1, 'BPDU Type'),
99
+ //Configuration / RST body (skipped for a 4-byte TCN BPDU).
100
+ flags: this.#bodyUInt('flags', 4, 1, 'Flags'),
101
+ rootIdentifier: this.#bodyHex('rootIdentifier', 5, 8, 'Root Identifier'),
102
+ rootPathCost: this.#bodyUInt('rootPathCost', 13, 4, 'Root Path Cost'),
103
+ bridgeIdentifier: this.#bodyHex('bridgeIdentifier', 17, 8, 'Bridge Identifier'),
104
+ portIdentifier: this.#bodyUInt('portIdentifier', 25, 2, 'Port Identifier'),
105
+ messageAge: this.#bodyUInt('messageAge', 27, 2, 'Message Age'),
106
+ maxAge: this.#bodyUInt('maxAge', 29, 2, 'Max Age'),
107
+ helloTime: this.#bodyUInt('helloTime', 31, 2, 'Hello Time'),
108
+ forwardDelay: this.#bodyUInt('forwardDelay', 33, 2, 'Forward Delay'),
109
+ //RST/MST trailing remainder (Version 1 Length + any MST configuration), kept verbatim.
110
+ //Only an RST/MST BPDU (type 0x02) carries it; a Configuration BPDU (0x00) is exactly 35
111
+ //bytes, so its trailing 802.3 minimum-frame padding is left to RawData rather than absorbed
112
+ //here (which would break the padding's own byte-perfect identity and mislabel it).
113
+ extra: {
114
+ type: 'string',
115
+ label: 'Extra',
116
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
117
+ decode: function () {
118
+ const bpduType = this.instance.bpduType.getValue(0);
119
+ if (bpduType !== 0x02)
120
+ return;
121
+ const available = this.packet.length - this.startPos;
122
+ if (available > 35)
123
+ this.instance.extra.setValue((0, BufferToHex_1.BufferToHex)(this.readBytes(35, available - 35)));
124
+ else
125
+ this.instance.extra.setValue('');
126
+ },
127
+ encode: function () {
128
+ const bpduType = this.instance.bpduType.getValue(0);
129
+ if (bpduType !== 0x02)
130
+ return;
131
+ const extra = this.instance.extra.getValue('');
132
+ if (extra)
133
+ this.writeBytes(35, (0, HexToBuffer_1.HexToBuffer)(extra));
134
+ }
135
+ }
136
+ }
137
+ };
138
+ }
139
+ match() {
140
+ //An LLC child selected by DSAP 0x42 (66). Confirm the parent is LLC and the DSAP byte is 0x42, and
141
+ //require the 4-byte fixed BPDU part.
142
+ const prev = this.prevCodecModule;
143
+ if (!prev || prev.id !== 'llc')
144
+ return false;
145
+ if (prev.instance.dsap.getValue(0) !== 0x42)
146
+ return false;
147
+ return this.packet.length - this.startPos >= 4;
148
+ }
149
+ }
150
+ exports.STP = STP;
@@ -0,0 +1,25 @@
1
+ import { BaseHeader } from '../abstracts/BaseHeader';
2
+ import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
3
+ import { DemuxProducer } from '../types/DemuxProducer';
4
+ /**
5
+ * STUN — Session Traversal Utilities for NAT (RFC 5389, superseded by RFC 8489 with the same wire
6
+ * format). A 20-byte fixed header — Message Type, Message Length, the 0x2112A442 Magic Cookie and a
7
+ * 96-bit Transaction ID (RFC 5389 §6) — followed by zero or more Type-Length-Value attributes
8
+ * (§15), each padded to a 4-byte boundary. Rides UDP/TCP, well-known port 3478.
9
+ *
10
+ * Attributes are carried generically (attribute type + verbatim hex value) so every attribute —
11
+ * standard or unknown — round-trips byte-for-byte; per-attribute semantic decoding (XOR-MAPPED-ADDRESS
12
+ * → ip:port, etc.) is a later enrichment layered on top of this faithful TLV base. Padding bytes are
13
+ * re-emitted as zero (RFC 5389 §15: padding bits are ignored and MAY be any value).
14
+ */
15
+ export declare class STUN extends BaseHeader {
16
+ #private;
17
+ get SCHEMA(): ProtocolJSONSchema;
18
+ readonly id: string;
19
+ readonly name: string;
20
+ readonly nickname: string;
21
+ readonly matchKeys: string[];
22
+ readonly heuristicFallback: boolean;
23
+ match(): boolean;
24
+ readonly demuxProducers: DemuxProducer[];
25
+ }
@@ -0,0 +1,183 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STUN = void 0;
4
+ const BaseHeader_1 = require("../abstracts/BaseHeader");
5
+ const BufferToHex_1 = require("../helper/BufferToHex");
6
+ const BufferToNumber_1 = require("../helper/BufferToNumber");
7
+ const NumberToBuffer_1 = require("../helper/NumberToBuffer");
8
+ const StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
9
+ /**
10
+ * STUN — Session Traversal Utilities for NAT (RFC 5389, superseded by RFC 8489 with the same wire
11
+ * format). A 20-byte fixed header — Message Type, Message Length, the 0x2112A442 Magic Cookie and a
12
+ * 96-bit Transaction ID (RFC 5389 §6) — followed by zero or more Type-Length-Value attributes
13
+ * (§15), each padded to a 4-byte boundary. Rides UDP/TCP, well-known port 3478.
14
+ *
15
+ * Attributes are carried generically (attribute type + verbatim hex value) so every attribute —
16
+ * standard or unknown — round-trips byte-for-byte; per-attribute semantic decoding (XOR-MAPPED-ADDRESS
17
+ * → ip:port, etc.) is a later enrichment layered on top of this faithful TLV base. Padding bytes are
18
+ * re-emitted as zero (RFC 5389 §15: padding bits are ignored and MAY be any value).
19
+ */
20
+ class STUN extends BaseHeader_1.BaseHeader {
21
+ constructor() {
22
+ super(...arguments);
23
+ this.id = 'stun';
24
+ this.name = 'Session Traversal Utilities for NAT';
25
+ this.nickname = 'STUN';
26
+ //Well-known port 3478 (UDP and TCP). heuristicFallback because the 0x2112A442 Magic Cookie is a
27
+ //reliable 32-bit content signature — STUN is used on ephemeral ports too (ICE/WebRTC), so it must
28
+ //also be recognized off 3478 via match().
29
+ this.matchKeys = ['udpport:3478', 'tcpport:3478'];
30
+ this.heuristicFallback = true;
31
+ //Produces no child demux key — STUN attributes are handled internally; nothing rides above it.
32
+ this.demuxProducers = [];
33
+ }
34
+ static #schemaCache;
35
+ get SCHEMA() {
36
+ return (STUN.#schemaCache ??= STUN.#buildSchema());
37
+ }
38
+ static #buildSchema() {
39
+ return {
40
+ type: 'object',
41
+ properties: {
42
+ //Message Type (RFC 5389 §6): 14 bits of class+method, top 2 bits zero. Kept as a plain
43
+ //uint16 (e.g. 0x0001 Binding Request, 0x0101 Binding Success Response) — byte-perfect and
44
+ //editable; the class/method split is UI enrichment for later.
45
+ messageType: this.fieldUInt('messageType', 0, 2, 'Message Type'),
46
+ //Message Length: attribute bytes only (excludes the 20-byte header), including padding.
47
+ //Explicit non-zero is honored (a crafted wrong length is a valid packet); 0 auto-computes
48
+ //from the encoded attributes after they are written.
49
+ messageLength: {
50
+ type: 'integer',
51
+ label: 'Message Length',
52
+ minimum: 0,
53
+ maximum: 65535,
54
+ decode: function () {
55
+ this.instance.messageLength.setValue((0, BufferToNumber_1.BufferToUInt16)(this.readBytes(2, 2)));
56
+ },
57
+ encode: function () {
58
+ const messageLength = this.instance.messageLength.getValue(0);
59
+ if (messageLength) {
60
+ this.instance.messageLength.setValue(messageLength);
61
+ this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(messageLength));
62
+ }
63
+ else {
64
+ this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(0));
65
+ this.instance.messageLength.setValue(0);
66
+ //After every field (attributes included) has encoded, the header length is
67
+ //20 + attribute bytes; fill in the real Message Length.
68
+ this.addPostSelfEncodeHandler(() => {
69
+ const attributeBytes = this.length - 20 < 0 ? 0 : this.length - 20;
70
+ this.instance.messageLength.setValue(attributeBytes);
71
+ this.writeBytes(2, (0, NumberToBuffer_1.UInt16ToBuffer)(attributeBytes));
72
+ }, 1);
73
+ }
74
+ }
75
+ },
76
+ magicCookie: this.fieldHex('magicCookie', 4, 4, 'Magic Cookie'),
77
+ transactionId: this.fieldHex('transactionId', 8, 12, 'Transaction ID'),
78
+ attributes: {
79
+ type: 'array',
80
+ label: 'Attributes',
81
+ items: {
82
+ type: 'object',
83
+ label: 'Attribute',
84
+ properties: {
85
+ type: {
86
+ type: 'integer',
87
+ label: 'Attribute Type',
88
+ minimum: 0,
89
+ maximum: 65535
90
+ },
91
+ value: {
92
+ type: 'string',
93
+ label: 'Value',
94
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX
95
+ },
96
+ //Present only when the on-wire padding is non-zero (RFC 5389 §15 lets it be
97
+ //any value); hidden from the default form since padding is not semantic.
98
+ pad: {
99
+ type: 'string',
100
+ label: 'Padding',
101
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
102
+ hidden: true
103
+ }
104
+ }
105
+ },
106
+ decode: function () {
107
+ const messageLength = this.instance.messageLength.getValue(0);
108
+ //Bound by BOTH the declared Message Length AND the bytes actually present, so a
109
+ //lying Message Length (e.g. 0xFFFF) cannot spawn phantom attributes past the end
110
+ //of the buffer. readBytes clamps at the buffer end and offset always advances by
111
+ //at least 4, so the loop also cannot read out of bounds or run forever.
112
+ const available = this.packet.length - this.startPos;
113
+ const end = Math.min(20 + messageLength, available < 20 ? 20 : available);
114
+ const attributes = [];
115
+ let offset = 20;
116
+ //Each attribute is Type(2) Length(2) Value(Length) then padding to a 4-byte boundary.
117
+ while (offset + 4 <= end) {
118
+ const type = (0, BufferToNumber_1.BufferToUInt16)(this.readBytes(offset, 2));
119
+ const length = (0, BufferToNumber_1.BufferToUInt16)(this.readBytes(offset + 2, 2));
120
+ offset += 4;
121
+ let value = Buffer.alloc(0);
122
+ if (length) {
123
+ value = this.readBytes(offset, length);
124
+ offset += length;
125
+ }
126
+ const padLength = (4 - length % 4) % 4;
127
+ const attribute = { type: type, value: (0, BufferToHex_1.BufferToHex)(value) };
128
+ //Consume the padding so the header length covers it (endPos is exact). Keep
129
+ //the actual bytes only when non-zero, so a byte round-trip is exact for the
130
+ //rare legal non-zero padding without polluting the common zero-padded case.
131
+ if (padLength) {
132
+ const padding = this.readBytes(offset, padLength);
133
+ offset += padLength;
134
+ if (padding.some((byte) => byte !== 0))
135
+ attribute.pad = (0, BufferToHex_1.BufferToHex)(padding);
136
+ }
137
+ attributes.push(attribute);
138
+ }
139
+ this.instance.attributes.setValue(attributes);
140
+ },
141
+ encode: function () {
142
+ const attributes = this.instance.attributes.getValue();
143
+ if (!attributes)
144
+ return;
145
+ let offset = 20;
146
+ attributes.forEach((attribute) => {
147
+ const type = attribute.type ? attribute.type : 0;
148
+ const value = Buffer.from(attribute.value ? attribute.value : '', 'hex');
149
+ const length = value.length;
150
+ this.writeBytes(offset, (0, NumberToBuffer_1.UInt16ToBuffer)(type));
151
+ this.writeBytes(offset + 2, (0, NumberToBuffer_1.UInt16ToBuffer)(length));
152
+ offset += 4;
153
+ if (length) {
154
+ this.writeBytes(offset, value);
155
+ offset += length;
156
+ }
157
+ const padLength = (4 - length % 4) % 4;
158
+ if (padLength) {
159
+ //Re-emit preserved non-zero padding verbatim (sized to padLength: extra
160
+ //dropped, short zero-filled); default zeros when none was carried.
161
+ const padding = Buffer.alloc(padLength, 0);
162
+ if (attribute.pad)
163
+ Buffer.from(attribute.pad, 'hex').copy(padding, 0, 0, padLength);
164
+ this.writeBytes(offset, padding);
165
+ offset += padLength;
166
+ }
167
+ });
168
+ }
169
+ }
170
+ }
171
+ };
172
+ }
173
+ match() {
174
+ if (!this.prevCodecModule)
175
+ return false;
176
+ //Magic Cookie 0x2112A442 at offset 4 (RFC 5389 §6). A 32-bit signature — safe to match on any
177
+ //port. RFC 3489 classic STUN (no cookie) is intentionally not matched.
178
+ if (this.packet.length - this.startPos < 8)
179
+ return false;
180
+ return (0, BufferToHex_1.BufferToHex)(this.readBytes(4, 4)) === '2112a442';
181
+ }
182
+ }
183
+ exports.STUN = STUN;
@@ -0,0 +1,43 @@
1
+ import { BaseHeader } from '../abstracts/BaseHeader';
2
+ import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
3
+ import { DemuxProducer } from '../types/DemuxProducer';
4
+ /**
5
+ * Sercos III — the real-time industrial Ethernet of the Sercos automation bus (IEC 61491 / IEC 61158,
6
+ * IEC 61784 CPF-16), carried directly in an Ethernet II frame with EtherType 0x88CD (an Ethernet child —
7
+ * no IP/UDP). Every communication cycle the master emits Master Data Telegrams (MDT) and the slaves answer
8
+ * with Acknowledge Telegrams (AT); both frame kinds share the same EtherType and are distinguished by the
9
+ * Telegram Type bit in the first header byte.
10
+ *
11
+ * The frame opens with the Sercos III telegram header. This minimal slice structures the fixed leading
12
+ * bytes and keeps the per-device payload verbatim:
13
+ *
14
+ * Byte 0 — Telegram Type field (a bitfield, MSB-first per the Wireshark `siii` dissector):
15
+ * - bit 7 (0x80) channel — 0 = P-Telegram (primary line), 1 = S-Telegram (secondary line)
16
+ * - bit 6 (0x40) telegramType — 0 = MDT (Master Data Telegram), 1 = AT (Acknowledge Telegram)
17
+ * - bit 5 (0x20) cycleCountValid — the MST cycle count is valid
18
+ * - bit 4 (0x10) reserved — preserved verbatim for a byte-perfect round-trip
19
+ * - bits 0..3 (0x0f) telegramNumber— MDT/AT index within the cycle (0..15)
20
+ * Byte 1 — Phase field (the Master Sync Telegram, MST):
21
+ * - the Phase occupies mask 0x8f (bit 7 = phase switching, bits 0..3 = communication phase CP0..CP4),
22
+ * a non-contiguous field kept as one value; the Cycle Count occupies mask 0x70 (bits 4..6).
23
+ * Bytes 2..5 — CRC32 of the MST, kept verbatim (little-endian on the wire per the dissector) and never
24
+ * recomputed, so a captured frame round-trips byte-for-byte.
25
+ *
26
+ * Everything after the 6-byte header (the phase-dependent per-device connection / service-channel data) is
27
+ * command- and topology-dependent, so this slice keeps it verbatim as `data` hex (byte-perfect), bounded by
28
+ * the end of the Ethernet payload (Sercos III has no length field of its own — it runs to the end of the
29
+ * frame, like LLDP/GOOSE). Structuring the per-device bodies (device control/status, service channel, hot
30
+ * plug) is a deferred slice. The MST header is genuine for the CP0–CP2 scanning phases and MDT0; for a
31
+ * CP3/CP4 operational device telegram the byte-1..5 labels are nominal but the bytes are still reproduced
32
+ * exactly because every header field is read and re-emitted verbatim.
33
+ */
34
+ export declare class SercosIII extends BaseHeader {
35
+ #private;
36
+ get SCHEMA(): ProtocolJSONSchema;
37
+ readonly id: string;
38
+ readonly name: string;
39
+ readonly nickname: string;
40
+ readonly matchKeys: string[];
41
+ match(): boolean;
42
+ readonly demuxProducers: DemuxProducer[];
43
+ }