@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,145 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MPLS = 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 StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
8
+ /**
9
+ * MPLS — Multiprotocol Label Switching (RFC 3032), carried directly in an Ethernet II frame with
10
+ * EtherType 0x8847 (unicast) or 0x8848 (multicast) — an Ethernet child, no IP/UDP below it. The MPLS
11
+ * shim is a label stack: a sequence of 4-byte entries, each packing a 20-bit Label, a 3-bit Traffic
12
+ * Class / Experimental field (TC/EXP), a 1-bit Bottom-of-Stack flag (S), and an 8-bit Time To Live
13
+ * (TTL). The stack repeats until an entry with S=1 (the bottom of stack); the encapsulated packet
14
+ * (typically IPv4/IPv6, dispatched by the first payload nibble) follows immediately after it.
15
+ *
16
+ * This codec is the label-stack leaf: it decodes the stack (each entry's structured label/tc/s/ttl)
17
+ * up to and including the S=1 entry, then keeps the encapsulated packet after it as an opaque `payload`
18
+ * hex field so MPLS is a self-contained byte-perfect leaf. (It deliberately consumes the payload rather
19
+ * than leaving it to the codec's recursion: with IPv4/IPv6.match unchanged the inner IP would not fall
20
+ * to RawData but be claimed by the greedy EthernetII content heuristic, which emits an un-re-encodable
21
+ * layer for a short trailer. Owning the bytes keeps decode→encode from ever throwing.) Each entry and
22
+ * the payload are re-emitted verbatim, so a well-formed shim round-trips byte-for-byte. Structured inner
23
+ * IPv4/IPv6 recursion is a serial follow-up (IPv4/IPv6.match must learn an 'mpls' parent branch
24
+ * dispatching on the first payload nibble, at which point `payload` becomes real child layers).
25
+ */
26
+ class MPLS extends BaseHeader_1.BaseHeader {
27
+ constructor() {
28
+ super(...arguments);
29
+ this.id = 'mpls';
30
+ this.name = 'Multiprotocol Label Switching';
31
+ this.nickname = 'MPLS';
32
+ this.matchKeys = ['ethertype:8847', 'ethertype:8848'];
33
+ //A leaf header for this slice: the encapsulated packet is left to the codec's recursion (inner IP
34
+ //recursion is a serial follow-up — see the class doc), so nothing demuxes off MPLS yet.
35
+ this.demuxProducers = [];
36
+ }
37
+ static #schemaCache;
38
+ get SCHEMA() {
39
+ return (MPLS.#schemaCache ??= MPLS.#buildSchema());
40
+ }
41
+ static #buildSchema() {
42
+ return {
43
+ type: 'object',
44
+ summary: 'MPLS ${entries.length} labels',
45
+ properties: {
46
+ entries: {
47
+ type: 'array',
48
+ label: 'Label Stack',
49
+ items: {
50
+ type: 'object',
51
+ label: 'Label Stack Entry',
52
+ properties: {
53
+ label: { type: 'integer', label: 'Label', minimum: 0, maximum: 1048575 },
54
+ tc: { type: 'integer', label: 'Traffic Class', minimum: 0, maximum: 7 },
55
+ s: { type: 'integer', label: 'Bottom of Stack', minimum: 0, maximum: 1 },
56
+ ttl: { type: 'integer', label: 'Time To Live', minimum: 0, maximum: 255 }
57
+ }
58
+ },
59
+ decode: function () {
60
+ //The label stack has no length field of its own — it runs until an entry with S=1
61
+ //(bottom of stack). Bound the walk by the remaining frame bytes, reading each
62
+ //4-byte entry as label(20)+tc(3)+s(1)+ttl(8), MSB-first. A truncated final entry
63
+ //(fewer than 4 bytes left) stops the walk without being consumed.
64
+ const available = this.packet.length - this.startPos;
65
+ const entries = [];
66
+ let offset = 0;
67
+ while (offset + 4 <= available) {
68
+ const label = this.readBits(offset, 4, 0, 20);
69
+ const tc = this.readBits(offset, 4, 20, 3);
70
+ const s = this.readBits(offset, 4, 23, 1);
71
+ const ttl = this.readBits(offset, 4, 24, 8);
72
+ entries.push({ label: label, tc: tc, s: s, ttl: ttl });
73
+ offset += 4;
74
+ //Bottom of stack — the encapsulated payload follows, left to the codec's
75
+ //recursion (do not read into it).
76
+ if (s === 1)
77
+ break;
78
+ }
79
+ this.instance.entries.setValue(entries);
80
+ },
81
+ encode: function () {
82
+ //Faithful executor: emit each supplied entry exactly as given (S and TC kept
83
+ //verbatim), even a stack that never sets S=1 — a crafted frame may be malformed.
84
+ const entries = this.instance.entries.getValue([]);
85
+ let offset = 0;
86
+ if (entries) {
87
+ for (let i = 0; i < entries.length; i++) {
88
+ const entry = entries[i] ? entries[i] : {};
89
+ let label = entry.label ? entry.label : 0;
90
+ //Label is a 20-bit field. A larger value cannot be represented; clamp and
91
+ //record the error rather than letting writeBits wrap it modulo 2^20 (which
92
+ //would silently corrupt the label).
93
+ if (label > 1048575) {
94
+ this.recordError(`entries[${i}].label`, 'Maximum label is 1048575');
95
+ label = 1048575;
96
+ }
97
+ if (label < 0) {
98
+ this.recordError(`entries[${i}].label`, 'Minimum label is 0');
99
+ label = 0;
100
+ }
101
+ //writeBits masks each field to its width, so label/tc/s/ttl never clobber.
102
+ this.writeBits(offset, 4, 0, 20, label);
103
+ this.writeBits(offset, 4, 20, 3, entry.tc ? entry.tc : 0);
104
+ this.writeBits(offset, 4, 23, 1, entry.s ? entry.s : 0);
105
+ this.writeBits(offset, 4, 24, 8, entry.ttl ? entry.ttl : 0);
106
+ offset += 4;
107
+ }
108
+ }
109
+ }
110
+ },
111
+ //The encapsulated packet after the label stack, kept as opaque hex so MPLS owns every
112
+ //byte and is a self-contained byte-perfect leaf (see the class doc for why it is not left
113
+ //to the codec's recursion). It starts right after the stack — entries.length × 4 bytes.
114
+ payload: {
115
+ type: 'string',
116
+ label: 'Payload',
117
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
118
+ decode: function () {
119
+ const stackBytes = (this.instance.entries.getValue([]) || []).length * 4;
120
+ const available = this.packet.length - this.startPos;
121
+ const payloadLength = available - stackBytes;
122
+ this.instance.payload.setValue(payloadLength > 0 ? (0, BufferToHex_1.BufferToHex)(this.readBytes(stackBytes, payloadLength)) : '');
123
+ },
124
+ encode: function () {
125
+ const stackBytes = (this.instance.entries.getValue([]) || []).length * 4;
126
+ const payload = this.instance.payload.getValue('');
127
+ if (payload)
128
+ this.writeBytes(stackBytes, (0, HexToBuffer_1.HexToBuffer)(payload));
129
+ }
130
+ }
131
+ }
132
+ };
133
+ }
134
+ match() {
135
+ //An Ethernet child selected by EtherType 0x8847 (unicast) or 0x8848 (multicast), stored as a
136
+ //lowercase 4-hex string on the parent. Require at least one 4-byte label stack entry.
137
+ if (!this.prevCodecModule)
138
+ return false;
139
+ const etherType = this.prevCodecModule.instance.etherType.getValue();
140
+ if (etherType !== '8847' && etherType !== '8848')
141
+ return false;
142
+ return this.packet.length - this.startPos >= 4;
143
+ }
144
+ }
145
+ exports.MPLS = MPLS;
@@ -0,0 +1,30 @@
1
+ import { BaseHeader } from '../abstracts/BaseHeader';
2
+ import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
3
+ import { DemuxProducer } from '../types/DemuxProducer';
4
+ /**
5
+ * MQTT — Message Queuing Telemetry Transport (OASIS MQTT 3.1.1 / 5.0), a lightweight publish/subscribe
6
+ * messaging protocol on TCP port 1883 (8883 for TLS). Every Control Packet begins with a 2-to-5 byte
7
+ * Fixed Header: a first byte carrying the 4-bit Message Type (1 CONNECT, 2 CONNACK, 3 PUBLISH, 8
8
+ * SUBSCRIBE, 12 PINGREQ, 13 PINGRESP, 14 DISCONNECT, …) and 4 header Flags (for PUBLISH these are
9
+ * DUP / QoS(2 bits) / RETAIN; for every other type they are a fixed reserved value), followed by the
10
+ * Remaining Length — a 1-to-4 byte variable-length integer counting the bytes of the Variable Header
11
+ * plus Payload that follow.
12
+ *
13
+ * This codec decodes the Fixed Header structurally (message type, the flags nibble, and the decoded
14
+ * Remaining Length value) and keeps the Variable Header + Payload region verbatim as `payload` hex —
15
+ * sub-decoding it depends on the message type and, for PUBLISH/SUBSCRIBE, on session/topic state that is
16
+ * cross-packet, not a single-packet concern. The Remaining Length is re-emitted as a canonical varint on
17
+ * encode: honored when supplied, else derived from the payload byte length. Because valid MQTT uses the
18
+ * minimal (canonical) varint encoding, a well-formed packet round-trips byte-for-byte; a hand-crafted
19
+ * frame that used a non-minimal (redundant) varint would not reproduce those extra continuation bytes.
20
+ */
21
+ export declare class MQTT extends BaseHeader {
22
+ #private;
23
+ get SCHEMA(): ProtocolJSONSchema;
24
+ readonly id: string;
25
+ readonly name: string;
26
+ readonly nickname: string;
27
+ readonly matchKeys: string[];
28
+ match(): boolean;
29
+ readonly demuxProducers: DemuxProducer[];
30
+ }
@@ -0,0 +1,173 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MQTT = 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 StringContentEncodingEnum_1 = require("../lib/StringContentEncodingEnum");
9
+ /**
10
+ * MQTT — Message Queuing Telemetry Transport (OASIS MQTT 3.1.1 / 5.0), a lightweight publish/subscribe
11
+ * messaging protocol on TCP port 1883 (8883 for TLS). Every Control Packet begins with a 2-to-5 byte
12
+ * Fixed Header: a first byte carrying the 4-bit Message Type (1 CONNECT, 2 CONNACK, 3 PUBLISH, 8
13
+ * SUBSCRIBE, 12 PINGREQ, 13 PINGRESP, 14 DISCONNECT, …) and 4 header Flags (for PUBLISH these are
14
+ * DUP / QoS(2 bits) / RETAIN; for every other type they are a fixed reserved value), followed by the
15
+ * Remaining Length — a 1-to-4 byte variable-length integer counting the bytes of the Variable Header
16
+ * plus Payload that follow.
17
+ *
18
+ * This codec decodes the Fixed Header structurally (message type, the flags nibble, and the decoded
19
+ * Remaining Length value) and keeps the Variable Header + Payload region verbatim as `payload` hex —
20
+ * sub-decoding it depends on the message type and, for PUBLISH/SUBSCRIBE, on session/topic state that is
21
+ * cross-packet, not a single-packet concern. The Remaining Length is re-emitted as a canonical varint on
22
+ * encode: honored when supplied, else derived from the payload byte length. Because valid MQTT uses the
23
+ * minimal (canonical) varint encoding, a well-formed packet round-trips byte-for-byte; a hand-crafted
24
+ * frame that used a non-minimal (redundant) varint would not reproduce those extra continuation bytes.
25
+ */
26
+ class MQTT extends BaseHeader_1.BaseHeader {
27
+ constructor() {
28
+ super(...arguments);
29
+ //Byte length of the Remaining Length varint for the current packet. Set when the remainingLength
30
+ //field decodes/encodes and read by the payload field to locate the start of the Variable Header +
31
+ //Payload region (offset 1 + this many bytes). Per-instance; decode/encode create fresh instances.
32
+ this.#varintLength = 1;
33
+ this.id = 'mqtt';
34
+ this.name = 'MQTT';
35
+ this.nickname = 'MQTT';
36
+ this.matchKeys = ['tcpport:1883'];
37
+ //A leaf header — the Variable Header + Payload is kept as hex, not demuxed further.
38
+ this.demuxProducers = [];
39
+ }
40
+ static #schemaCache;
41
+ get SCHEMA() {
42
+ return (MQTT.#schemaCache ??= MQTT.#buildSchema());
43
+ }
44
+ //Byte length of the Remaining Length varint for the current packet. Set when the remainingLength
45
+ //field decodes/encodes and read by the payload field to locate the start of the Variable Header +
46
+ //Payload region (offset 1 + this many bytes). Per-instance; decode/encode create fresh instances.
47
+ #varintLength;
48
+ /** Decode the Remaining Length variable-length integer at `offset` (MQTT algorithm: low 7 bits are
49
+ * value, high bit 0x80 means "more bytes follow", up to 4 bytes). Returns the decoded value and how
50
+ * many bytes it occupied. */
51
+ #readRemainingLength(offset) {
52
+ let value = 0;
53
+ let multiplier = 1;
54
+ let byteLength = 0;
55
+ for (let i = 0; i < 4; i++) {
56
+ const byte = (0, BufferToNumber_1.BufferToUInt8)(this.readBytes(offset + i, 1));
57
+ value += (byte & 0x7f) * multiplier;
58
+ multiplier *= 128;
59
+ byteLength++;
60
+ if ((byte & 0x80) === 0)
61
+ break;
62
+ }
63
+ return { value: value, byteLength: byteLength };
64
+ }
65
+ /** Encode `value` as a canonical (minimal) MQTT Remaining Length varint. */
66
+ #writeRemainingLength(value) {
67
+ const bytes = [];
68
+ let remaining = value >= 0 ? value : 0;
69
+ do {
70
+ let encodedByte = remaining % 128;
71
+ remaining = Math.floor(remaining / 128);
72
+ if (remaining > 0)
73
+ encodedByte |= 0x80;
74
+ bytes.push(encodedByte);
75
+ } while (remaining > 0 && bytes.length < 4);
76
+ return Buffer.from(bytes);
77
+ }
78
+ static #buildSchema() {
79
+ return {
80
+ type: 'object',
81
+ summary: 'MQTT type=${messageType}',
82
+ properties: {
83
+ //First byte, high nibble (bits 7-4): the Control Packet type.
84
+ messageType: {
85
+ type: 'integer',
86
+ label: 'Message Type',
87
+ minimum: 0,
88
+ maximum: 15,
89
+ decode: function () {
90
+ this.instance.messageType.setValue(this.readBits(0, 1, 0, 4));
91
+ },
92
+ encode: function () {
93
+ this.writeBits(0, 1, 0, 4, this.instance.messageType.getValue(0));
94
+ }
95
+ },
96
+ //First byte, low nibble (bits 3-0): the header flags. For PUBLISH these are DUP / QoS(2) /
97
+ //RETAIN; for other types a fixed reserved value. Kept as the raw nibble (byte-perfect).
98
+ flags: {
99
+ type: 'integer',
100
+ label: 'Flags',
101
+ minimum: 0,
102
+ maximum: 15,
103
+ decode: function () {
104
+ this.instance.flags.setValue(this.readBits(0, 1, 4, 4));
105
+ },
106
+ encode: function () {
107
+ this.writeBits(0, 1, 4, 4, this.instance.flags.getValue(0));
108
+ }
109
+ },
110
+ //The decoded value of the Remaining Length varint (length of Variable Header + Payload).
111
+ remainingLength: {
112
+ type: 'integer',
113
+ label: 'Remaining Length',
114
+ minimum: 0,
115
+ maximum: 268435455,
116
+ decode: function () {
117
+ const result = this.#readRemainingLength(1);
118
+ this.#varintLength = result.byteLength;
119
+ this.instance.remainingLength.setValue(result.value);
120
+ },
121
+ encode: function () {
122
+ //Honored when supplied (a crafted packet may carry any value); else derived from the
123
+ //payload byte length. Re-emitted as a canonical varint — reproduces the wire bytes
124
+ //for well-formed (minimally encoded) frames.
125
+ const provided = this.instance.remainingLength.getValue();
126
+ const value = (provided !== undefined && provided !== null)
127
+ ? provided
128
+ : (0, HexToBuffer_1.HexToBuffer)(this.instance.payload.getValue('')).length;
129
+ this.instance.remainingLength.setValue(value);
130
+ const varint = this.#writeRemainingLength(value);
131
+ this.#varintLength = varint.length;
132
+ this.writeBytes(1, varint);
133
+ }
134
+ },
135
+ //Variable Header + Payload, kept verbatim. Starts after the fixed header (offset 1 + the
136
+ //varint bytes) and spans Remaining Length bytes, clamped to the captured bytes so a
137
+ //truncated frame stays in-bounds and trailing/pipelined data is left to the codec's recursion.
138
+ payload: {
139
+ type: 'string',
140
+ label: 'Payload',
141
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
142
+ decode: function () {
143
+ const remaining = this.packet.length - this.startPos;
144
+ const start = 1 + this.#varintLength;
145
+ const length = this.instance.remainingLength.getValue(0);
146
+ let end = start + length;
147
+ if (end > remaining)
148
+ end = remaining;
149
+ this.instance.payload.setValue(end > start ? (0, BufferToHex_1.BufferToHex)(this.readBytes(start, end - start)) : '');
150
+ },
151
+ encode: function () {
152
+ const payload = this.instance.payload.getValue('');
153
+ if (payload)
154
+ this.writeBytes(1 + this.#varintLength, (0, HexToBuffer_1.HexToBuffer)(payload));
155
+ }
156
+ }
157
+ }
158
+ };
159
+ }
160
+ match() {
161
+ //MQTT rides on TCP port 1883. Require at least the 2-byte minimum Fixed Header and a plausible
162
+ //Control Packet type (1..15; 0 is forbidden) as a content signature so non-MQTT 1883 traffic
163
+ //falls through to raw.
164
+ if (!this.prevCodecModule || this.prevCodecModule.id !== 'tcp')
165
+ return false;
166
+ if (this.packet.length - this.startPos < 2)
167
+ return false;
168
+ const byte0 = (0, BufferToNumber_1.BufferToUInt8)(this.readBytes(0, 1, true));
169
+ const messageType = byte0 >> 4;
170
+ return messageType >= 1 && messageType <= 15;
171
+ }
172
+ }
173
+ exports.MQTT = MQTT;
@@ -0,0 +1,34 @@
1
+ import { BaseHeader } from '../abstracts/BaseHeader';
2
+ import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
3
+ import { DemuxProducer } from '../types/DemuxProducer';
4
+ /**
5
+ * MQTT-SN — MQTT for Sensor Networks (v1.2), the UDP-datagram publish/subscribe protocol for
6
+ * constrained/wireless sensor networks (commonly gateway UDP ports 1883 or 10000). NOT to be confused
7
+ * with MQTT itself, which is the TCP/1883 stream protocol handled by the separate `mqtt` header.
8
+ *
9
+ * Every message begins with a variable-length Length field: the first octet is either the whole
10
+ * message length (1..255, counting the Length field itself + the Message Type + the body), OR the
11
+ * escape value 0x01, in which case the next TWO octets are the real length as a big-endian uint16
12
+ * (used when the message is 256..65535 octets). The Length is followed by a 1-octet Message Type
13
+ * (0x00 ADVERTISE, 0x04 CONNECT, 0x05 CONNACK, 0x0C PUBLISH, 0x12 SUBSCRIBE, …) and then the
14
+ * type-specific body.
15
+ *
16
+ * Because the per-type body layout (flags, topic ids/names, QoS, will) is message-type dependent and,
17
+ * for PUBLISH/SUBSCRIBE, ties into cross-datagram topic-registration state, this single-datagram codec
18
+ * keeps the body verbatim as `body` hex (byte-perfect) and does not sub-decode it. The Length is
19
+ * honored when supplied (a crafted datagram may lie), else derived from the body; the wire form (1- vs
20
+ * 3-octet Length) is derived from the Length value (>255 ⇒ 3-octet escape form), matching how a
21
+ * conformant sender chooses it, so a well-formed datagram round-trips byte-for-byte. The message is
22
+ * bounded by its Length and the UDP payload, so trailing bytes fall through to the codec's recursion /
23
+ * RawData.
24
+ */
25
+ export declare class MQTTSN extends BaseHeader {
26
+ #private;
27
+ get SCHEMA(): ProtocolJSONSchema;
28
+ readonly id: string;
29
+ readonly name: string;
30
+ readonly nickname: string;
31
+ readonly matchKeys: string[];
32
+ match(): boolean;
33
+ readonly demuxProducers: DemuxProducer[];
34
+ }
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MQTTSN = 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
+ * MQTT-SN — MQTT for Sensor Networks (v1.2), the UDP-datagram publish/subscribe protocol for
12
+ * constrained/wireless sensor networks (commonly gateway UDP ports 1883 or 10000). NOT to be confused
13
+ * with MQTT itself, which is the TCP/1883 stream protocol handled by the separate `mqtt` header.
14
+ *
15
+ * Every message begins with a variable-length Length field: the first octet is either the whole
16
+ * message length (1..255, counting the Length field itself + the Message Type + the body), OR the
17
+ * escape value 0x01, in which case the next TWO octets are the real length as a big-endian uint16
18
+ * (used when the message is 256..65535 octets). The Length is followed by a 1-octet Message Type
19
+ * (0x00 ADVERTISE, 0x04 CONNECT, 0x05 CONNACK, 0x0C PUBLISH, 0x12 SUBSCRIBE, …) and then the
20
+ * type-specific body.
21
+ *
22
+ * Because the per-type body layout (flags, topic ids/names, QoS, will) is message-type dependent and,
23
+ * for PUBLISH/SUBSCRIBE, ties into cross-datagram topic-registration state, this single-datagram codec
24
+ * keeps the body verbatim as `body` hex (byte-perfect) and does not sub-decode it. The Length is
25
+ * honored when supplied (a crafted datagram may lie), else derived from the body; the wire form (1- vs
26
+ * 3-octet Length) is derived from the Length value (>255 ⇒ 3-octet escape form), matching how a
27
+ * conformant sender chooses it, so a well-formed datagram round-trips byte-for-byte. The message is
28
+ * bounded by its Length and the UDP payload, so trailing bytes fall through to the codec's recursion /
29
+ * RawData.
30
+ */
31
+ class MQTTSN extends BaseHeader_1.BaseHeader {
32
+ constructor() {
33
+ super(...arguments);
34
+ this.id = 'mqttsn';
35
+ this.name = 'MQTT for Sensor Networks';
36
+ this.nickname = 'MQTT-SN';
37
+ //MQTT-SN rides UDP at gateway ports 1883 / 10000. It carries no fixed content magic (the first
38
+ //octet is a length), so selection stays port-bucketed with a minimum-length guard; no
39
+ //heuristicFallback (a length-led header has no signature reliable enough to claim arbitrary ports).
40
+ this.matchKeys = ['udpport:1883', 'udpport:10000'];
41
+ //A leaf header — the per-type body needs message-type-dependent, cross-datagram parsing.
42
+ this.demuxProducers = [];
43
+ }
44
+ static #schemaCache;
45
+ get SCHEMA() {
46
+ return (MQTTSN.#schemaCache ??= MQTTSN.#buildSchema());
47
+ }
48
+ /** The MQTT-SN message length bounded by the UDP datagram (so retained FCS/padding is not absorbed). */
49
+ #payloadLength() {
50
+ let available = this.packet.length - this.startPos;
51
+ if (this.prevCodecModule && this.prevCodecModule.id === 'udp') {
52
+ const udpLength = this.prevCodecModule.instance.length.getValue(0);
53
+ if (udpLength >= 8 && udpLength - 8 < available)
54
+ available = udpLength - 8;
55
+ }
56
+ return available < 0 ? 0 : available;
57
+ }
58
+ /** Wire size of the Length field as seen on decode: the escape octet 0x01 ⇒ 3-octet form, else 1-octet. */
59
+ #decodePrefixSize() {
60
+ return (0, BufferToNumber_1.BufferToUInt8)(this.readBytes(0, 1, true)) === 0x01 ? 3 : 1;
61
+ }
62
+ /** Wire size of the Length field for a given Length value: >255 needs the 3-octet escape form. */
63
+ static #prefixSizeFor(length) {
64
+ return length > 255 ? 3 : 1;
65
+ }
66
+ static #buildSchema() {
67
+ return {
68
+ type: 'object',
69
+ summary: 'MQTT-SN type=${msgType} len=${length}',
70
+ properties: {
71
+ //The whole-message octet count (Length field + Message Type + body). 1-octet on the wire
72
+ //when <256, else the 0x01 escape octet followed by a big-endian uint16. Honored when
73
+ //supplied (a crafted datagram may lie); else derived from the body byte length.
74
+ length: {
75
+ type: 'integer',
76
+ label: 'Length',
77
+ minimum: 0,
78
+ maximum: 65535,
79
+ decode: function () {
80
+ if (this.#payloadLength() < 1) {
81
+ this.instance.length.setValue(0);
82
+ return;
83
+ }
84
+ const b0 = (0, BufferToNumber_1.BufferToUInt8)(this.readBytes(0, 1));
85
+ //Escape form: the next 2 octets are the real length (big-endian). readBytes
86
+ //clamps at the buffer end and BufferToUInt16 tolerates a short read, so a
87
+ //truncated escape-form Length never throws.
88
+ this.instance.length.setValue(b0 === 0x01 ? (0, BufferToNumber_1.BufferToUInt16)(this.readBytes(1, 2)) : b0);
89
+ },
90
+ encode: function () {
91
+ const provided = this.instance.length.getValue();
92
+ let value;
93
+ if (provided !== undefined && provided !== null) {
94
+ value = provided;
95
+ }
96
+ else {
97
+ //Derive: whole-message = 1-octet-Length(1) + Message Type(1) + body. If that
98
+ //overflows the 1-octet form (>255) the escape form adds 2 more Length octets.
99
+ const bodyLength = (0, HexToBuffer_1.HexToBuffer)(this.instance.body.getValue('')).length;
100
+ value = 2 + bodyLength;
101
+ if (value > 255)
102
+ value = 4 + bodyLength;
103
+ }
104
+ if (value > 65535) {
105
+ this.recordError(this.instance.length.getPath(), 'Maximum value is 65535');
106
+ value = 65535;
107
+ }
108
+ if (value < 0) {
109
+ this.recordError(this.instance.length.getPath(), 'Minimum value is 0');
110
+ value = 0;
111
+ }
112
+ this.instance.length.setValue(value);
113
+ if (value > 255) {
114
+ this.writeBytes(0, Buffer.from([0x01, (value >> 8) & 0xff, value & 0xff]));
115
+ }
116
+ else {
117
+ this.writeBytes(0, (0, NumberToBuffer_1.UInt8ToBuffer)(value));
118
+ }
119
+ }
120
+ },
121
+ //Message Type octet (0x00 ADVERTISE, 0x04 CONNECT, 0x05 CONNACK, 0x0C PUBLISH, 0x12
122
+ //SUBSCRIBE, …). Kept as a plain uint so any on-wire type value round-trips.
123
+ msgType: {
124
+ type: 'integer',
125
+ label: 'Message Type',
126
+ minimum: 0,
127
+ maximum: 255,
128
+ decode: function () {
129
+ this.instance.msgType.setValue((0, BufferToNumber_1.BufferToUInt8)(this.readBytes(this.#decodePrefixSize(), 1)));
130
+ },
131
+ encode: function () {
132
+ const node = this.instance.msgType;
133
+ let value = node.getValue(0, (nodePath) => this.recordError(nodePath, 'Not Found'));
134
+ if (value > 255) {
135
+ this.recordError(node.getPath(), 'Maximum value is 255');
136
+ value = 255;
137
+ }
138
+ if (value < 0) {
139
+ this.recordError(node.getPath(), 'Minimum value is 0');
140
+ value = 0;
141
+ }
142
+ node.setValue(value);
143
+ this.writeBytes(MQTTSN.#prefixSizeFor(this.instance.length.getValue(0)), (0, NumberToBuffer_1.UInt8ToBuffer)(value));
144
+ }
145
+ },
146
+ //The type-specific body after the Length + Message Type, kept verbatim. Bounded by the
147
+ //message Length and the UDP payload, so trailing/pipelined data is left to the codec's
148
+ //recursion / RawData.
149
+ body: {
150
+ type: 'string',
151
+ label: 'Body',
152
+ contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
153
+ decode: function () {
154
+ const prefix = this.#decodePrefixSize();
155
+ const available = this.#payloadLength();
156
+ let end = this.instance.length.getValue(0);
157
+ if (end > available)
158
+ end = available;
159
+ const bodyStart = prefix + 1;
160
+ this.instance.body.setValue(end > bodyStart ? (0, BufferToHex_1.BufferToHex)(this.readBytes(bodyStart, end - bodyStart)) : '');
161
+ },
162
+ encode: function () {
163
+ const body = this.instance.body.getValue('');
164
+ if (body)
165
+ this.writeBytes(MQTTSN.#prefixSizeFor(this.instance.length.getValue(0)) + 1, (0, HexToBuffer_1.HexToBuffer)(body));
166
+ }
167
+ }
168
+ }
169
+ };
170
+ }
171
+ match() {
172
+ //Require at least the minimal 1-octet Length + Message Type within the UDP payload, so a shorter
173
+ //datagram on the port falls through to raw rather than claiming an un-decodable layer.
174
+ return !!this.prevCodecModule && this.prevCodecModule.id === 'udp' && this.#payloadLength() >= 2;
175
+ }
176
+ }
177
+ exports.MQTTSN = MQTTSN;
@@ -0,0 +1,32 @@
1
+ import { BaseHeader } from '../abstracts/BaseHeader';
2
+ import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
3
+ import { DemuxProducer } from '../types/DemuxProducer';
4
+ /**
5
+ * Marker Protocol — the Link Aggregation Marker Protocol (IEEE 802.3ad / 802.1AX), the second of the
6
+ * Slow Protocols carried directly in an Ethernet II frame with EtherType 0x8809 (an Ethernet child — no
7
+ * IP/UDP). It shares the frame type with LACP and is disambiguated by byte 0, the Slow-Protocols
8
+ * Subtype: 1 = LACP (claimed by the LACP header), 2 = Marker (claimed here). Byte 1 is the Version.
9
+ * What follows is a flat sequence of TLVs — each a 1-byte Type + 1-byte Length (the Length counts the 2
10
+ * header octets, so the value is Length-2 bytes) + value bytes: the Marker Information TLV (type 0x01,
11
+ * len 0x10) or Marker Response TLV (type 0x02, len 0x10) — carrying Requester_Port (2), Requester_System
12
+ * (6), Requester_Transaction_ID (4) and Pad (2) — then the Terminator (type 0x00, len 0x00). After the
13
+ * Terminator the PDU is padded with reserved octets to fill the fixed PDU length. Marker has no length
14
+ * field of its own — it runs to the end of the frame.
15
+ *
16
+ * TLVs are carried generically (type + on-wire length + verbatim hex value) so every TLV round-trips
17
+ * byte-for-byte; per-TLV semantic decoding (requester port/system/transaction id) is a later enrichment.
18
+ * The Length is honored verbatim on encode when supplied (a crafted PDU may lie), else derived from the
19
+ * value (2 + value bytes; 0 for the Terminator). The walk stops at the Terminator (type 0) or when the
20
+ * frame is exhausted; any bytes after the Terminator are the reserved padding, kept verbatim in
21
+ * `reserved` so the frame is reproduced exactly.
22
+ */
23
+ export declare class MarkerProtocol extends BaseHeader {
24
+ #private;
25
+ get SCHEMA(): ProtocolJSONSchema;
26
+ readonly id: string;
27
+ readonly name: string;
28
+ readonly nickname: string;
29
+ readonly matchKeys: string[];
30
+ match(): boolean;
31
+ readonly demuxProducers: DemuxProducer[];
32
+ }