@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,342 @@
1
+ <p align="center">
2
+ <img src="https://raw.githubusercontent.com/myq1991/netkitty/main/assets/NetKittyLogo.webp" alt="NetKitty" width="180">
3
+ </p>
4
+
5
+ # @netkitty/codec
6
+
7
+ schema 驱动的协议编解码器,负责把报文各层协议头在字节和结构之间来回转换——覆盖**189 种协议**,贯穿整个
8
+ 协议栈。每一个协议头都是一份**可执行的 JSON Schema**,
9
+ 同一份声明同时充当字段树、字节级编解码逻辑、输入校验器,以及界面所需的表单元数据。它的设计取向是从一个
10
+ 图形化的报文编辑器(可编程的 Wireshark)倒推出来的,而不是追求吞吐的解析器。纯 TypeScript,不依赖任何
11
+ 原生模块:全程只操作内存里的 `Buffer`,因此**在 Node 和浏览器里都能原样运行**。
12
+
13
+ **协议覆盖**贯穿链路层与网络层(Ethernet、VLAN/802.1Q、ARP、IPv4/IPv6、ICMP/ICMPv6、MPLS、GRE、VXLAN、
14
+ GENEVE)、传输层(TCP、UDP、SCTP、DCCP、QUIC),以及主流应用层(HTTP、HTTP/2、TLS/DTLS、DNS/mDNS、
15
+ DHCP/DHCPv6、MQTT/MQTT-SN、CoAP、AMQP、Kafka、MongoDB、MySQL、PostgreSQL、Redis、SSH、LDAP、Kerberos、
16
+ SNMP、NTP、PTP、SIP/RTP/RTCP、RTSP、SMB、NFS、RADIUS、Diameter、WireGuard、GTP)。而它真正的差异化在于一整套
17
+ **工业 / OT / SCADA** 协议:Modbus(TCP/UDP)、DNP3、IEC 104、IEC 61850(GOOSE、Sampled Values、MMS、
18
+ R-GOOSE)、S7comm、OPC UA(含 PubSub)、PROFINET RT、EtherCAT、EtherNet/IP、BACnet/IP、POWERLINK、
19
+ HART-IP、Omron FINS、SLMP、CODESYS、C37.118、SercosIII、GE-SRTP。
20
+
21
+ > English docs: [README.md](./README.md)
22
+
23
+ ## 安装
24
+
25
+ ```bash
26
+ npm i @netkitty/codec
27
+ # 或者用聚合包:import {Codec} from 'netkitty/codec'
28
+ # 协议头类和转换 helper 都从 netkitty/codec 一并导出
29
+ ```
30
+
31
+ ## 快速上手
32
+
33
+ 解码把原始字节变成一列有序的协议层,编码则把协议层还原成字节。解码得到的结果本身就是一份合法的编码输入,
34
+ 所以两者是严格互逆的(读取 → 修改 → 重新生成)。
35
+
36
+ ```ts
37
+ import {Codec, HexToBuffer} from '@netkitty/codec'
38
+
39
+ const codec = new Codec()
40
+
41
+ // 解码:Buffer → 分层结果(最外层在前)
42
+ const packet = HexToBuffer('ffffffffffff0011223344550806...')
43
+ const layers = await codec.decode(packet)
44
+
45
+ layers[0] // {id: 'eth', name: 'Ethernet II', nickname: 'ETH', protocol: true, errors: [], data: {...}}
46
+ layers[0].data // {dmac: 'ff:ff:ff:ff:ff:ff', smac: '00:11:22:33:44:55', etherType: '0806'}
47
+ layers[0].errors // [] —— 逐字段的错误累积在这里,解码永远不会抛异常
48
+
49
+ // 编码:分层结果 → Buffer。把解码得到的各层直接喂回去,就能重新生成这个报文。
50
+ const {packet: rebuilt, errors} = await codec.encode(layers)
51
+ rebuilt.equals(packet) // 对于结构完好的报文为 true —— 解码/编码严格往返一致
52
+ ```
53
+
54
+ 想从零构造一个报文,只要按从外到内的顺序给 `encode` 传一组 `{id, data}` 输入即可;没填的字段会用
55
+ schema 里的默认值补齐,表单传来的字符串也会被自动转换成对应类型:
56
+
57
+ ```ts
58
+ const {packet} = await codec.encode([
59
+ {id: 'eth', data: {dmac: 'ff:ff:ff:ff:ff:ff', smac: '00:11:22:33:44:55', etherType: '0800'}},
60
+ {id: 'ipv4', data: {sip: '192.168.0.1', dip: '192.168.0.2', protocol: 17}},
61
+ {id: 'udp', data: {srcport: 12345, dstport: 53}}
62
+ ])
63
+ ```
64
+
65
+ ### 方法签名
66
+
67
+ ```ts
68
+ class Codec {
69
+ constructor(customCodecs?: CodecModuleConstructor[]) // 覆盖或扩展内置协议头
70
+ decode(packet: Buffer): Promise<CodecDecodeResult[]>
71
+ encode(inputs: CodecEncodeInput[]): Promise<CodecEncodeResult>
72
+ }
73
+
74
+ type CodecDecodeResult = {
75
+ id: string // 协议 id,如 'eth'、'ipv4'、'tcp'
76
+ name: string // 可读名称,如 'Ethernet II'
77
+ nickname: string // 简称,如 'ETH'
78
+ protocol: boolean // 该层是否为真正的协议(原始载荷为 false)
79
+ errors: CodecErrorInfo[] // {id, path, message}[] —— 用字段路径定位的解码错误
80
+ data: HeaderTreeNode // 解码出来的字段树
81
+ }
82
+
83
+ type CodecEncodeInput = Pick<CodecDecodeResult, 'id' | 'data'> & Partial<Omit<CodecDecodeResult, 'id' | 'data'>>
84
+ type CodecEncodeResult = {packet: Buffer, errors: CodecErrorInfo[]}
85
+ ```
86
+
87
+ ## 关键概念
88
+
89
+ ### 一份可执行 schema,四重身份
90
+
91
+ 每个协议头都继承 `BaseHeader`,并声明一份 `SCHEMA`(即 `ProtocolJSONSchema`)。这一份声明同时扮演
92
+ 四个角色:
93
+
94
+ 1. **字段树结构**——决定解码/编码后数据的形状。
95
+ 2. **编解码逻辑**——每个字段内嵌 `decode`/`encode` 闭包,通过 `this.readBytes/writeBytes` 和
96
+ `this.readBits/writeBits` 读写共享的报文缓冲区(偏移量都相对于当前协议头;写入时缓冲区会自动扩容,
97
+ 因此无需预先计算长度)。字段值存放在 `this.instance` 上,它是一个 `FlexibleObject`——一个会记录
98
+ 路径的代理对象,深层访问永远不会抛异常,并能给出精确的点分字段路径(如 `options[3].kind`),用来把
99
+ 错误绑定到界面上对应的输入框。
100
+ 3. **输入校验**——`encode` 会用 Ajv 按 schema 校验每一份输入。`useDefaults` 让 schema 同时充当报文
101
+ 模板(缺失字段自动补齐);`coerceTypes` 则容忍来自表单的字符串输入。
102
+ 4. **界面表单元数据**——自定义关键字(`label`、`hidden`、`contentEncoding`),加上 `enum`/`min`/`max`
103
+ 以及 `anyOf` + `const` 判别式,共同描述表单该如何渲染每个字段。
104
+
105
+ ### 解码永不失败,错误只累积不抛出
106
+
107
+ 畸形报文本身就是合法输入。某个字段的字节被截断或取值非法时,会通过 `recordError()` 记录一条错误(即该
108
+ 层 `errors` 上的一条 `{id, path, message}`),并把值收敛到一个尽力而为的结果——而不是抛异常。因此解码
109
+ 总能返回一份完整的、尽力而为的分层结果,外加一份用字段路径定位的错误清单,供界面高亮问题。唯一刻意的
110
+ 快速失败,是 `encode` 入口处的 Ajv 形状校验。
111
+
112
+ ### RawData 兜底
113
+
114
+ 解码会遍历整个报文,对每一层在当前偏移处选出第一个 demux 值或内容特征匹配的协议头,解出后前移偏移并
115
+ 递归,直到把报文消费完。`RawData` 是被强制放在最后的兜底项,且永远匹配成功,所以无法识别或畸形的尾部
116
+ 字节会直接变成一层 `raw`,解码绝不会走进死胡同。
117
+
118
+ ### 声明式外壳与命令式内核
119
+
120
+ `PROTOCOL_SCHEMA` 是剥离了闭包之后的 schema(通过 `JSON.parse(JSON.stringify())` 往返——JSON 序列化
121
+ 会丢弃函数,这正是刻意划出的边界)。剥离后剩下的是纯粹、可序列化的 JSON Schema,可以直接下发给前端去
122
+ 驱动表单;而字节偏移、位字段、TLV/BER 解析这些则留在闭包里。新增字段时请守住这条分界:表单需要的东西
123
+ 必须是可序列化的 schema,过程性的东西一律放进闭包。
124
+
125
+ ### 跨层修正走 post handler
126
+
127
+ 长度字段和校验和往往依赖其他层稍后才最终确定的字节。协议头会为这类修正注册带优先级的 post
128
+ encode/decode 处理器;报文级的 post encode 处理器按后进先出执行(外层依赖内层最终生成的字节),post
129
+ decode 处理器按先进先出执行(内层语义依赖外层上下文,例如 TCP 校验和需要 IPv4 的地址)。
130
+
131
+ ### 自定义与新增协议头
132
+
133
+ `new Codec(customCodecs)` 接受一组协议头类。自定义类会替换掉 `PROTOCOL_ID` 相同的内置协议头;id 全新
134
+ 的类则被追加进来。若要新增一个内置协议,实现一个 `BaseHeader` 子类,并在 `PacketHeaders.ts` 中注册
135
+ (同时从包的入口文件里重新导出)。
136
+
137
+ ### 编辑器辅助方法
138
+
139
+ 除 `decode`/`encode` 之外,`Codec` 还在同一次解码之上提供若干只读投影,用来搭建编辑器界面:
140
+ `dissect(packet)` 返回一棵字段树,每个字段都标注了它占据的精确字节区间、标签,以及错误/正常的严重级别
141
+ (类似 Wireshark 的字节到字段视图);`summary(decoded)` 渲染出一行描述(相当于 Wireshark 的 Info 列);
142
+ `allowedNextLayers`、`childDiscriminator` 和 `checkConsistency` 则描述并校验哪一层可以接在哪一层之后。
143
+
144
+ ## 内置协议头
145
+
146
+ 默认注册了 189 个协议头(`raw` 是强制兜底)。向 `new Codec(customCodecs)` 传入自定义类可覆盖同 id 的内置头或新增协议头。
147
+
148
+ | id | name |
149
+ | ---------------- | --------------------------------------------------- |
150
+ | `adsams` | Beckhoff ADS/AMS |
151
+ | `ah` | IP Authentication Header |
152
+ | `amqp` | AMQP 0-9-1 |
153
+ | `arp` | Address Resolution Protocol |
154
+ | `babel` | Babel Routing Protocol |
155
+ | `bacnet` | BACnet/IP |
156
+ | `bfd` | Bidirectional Forwarding Detection |
157
+ | `bgp` | Border Gateway Protocol |
158
+ | `bittorrent` | BitTorrent Peer Wire Protocol |
159
+ | `bsap` | Bristol/Emerson BSAP over IP |
160
+ | `c37118` | IEEE C37.118 Synchrophasor |
161
+ | `capwap` | Control And Provisioning of Wireless Access Points |
162
+ | `cdp` | Cisco Discovery Protocol |
163
+ | `cms` | CMS (China Substation Communication, DL/T 2811) |
164
+ | `coap` | Constrained Application Protocol |
165
+ | `codesys` | CODESYS V3 |
166
+ | `collectd` | collectd Network Protocol |
167
+ | `cotp` | COTP |
168
+ | `cql` | Cassandra CQL |
169
+ | `dccp` | Datagram Congestion Control Protocol |
170
+ | `dhcp` | Dynamic Host Configuration Protocol |
171
+ | `dhcpfo` | DHCP Failover |
172
+ | `dhcpv6` | Dynamic Host Configuration Protocol for IPv6 |
173
+ | `diameter` | Diameter |
174
+ | `dnp3` | Distributed Network Protocol 3 |
175
+ | `dns` | Domain Name System |
176
+ | `dtls` | Datagram Transport Layer Security |
177
+ | `eapol` | EAP over LAN |
178
+ | `ecat` | EtherCAT |
179
+ | `eigrp` | Enhanced Interior Gateway Routing Protocol |
180
+ | `elasticsearch` | Elasticsearch Transport |
181
+ | `enip` | EtherNet/IP |
182
+ | `esp` | IP Encapsulating Security Payload |
183
+ | `eth` | Ethernet II |
184
+ | `fcoe` | Fibre Channel over Ethernet |
185
+ | `ffhse` | FOUNDATION Fieldbus HSE |
186
+ | `finger` | Finger |
187
+ | `fins` | OMRON FINS |
188
+ | `ftp` | File Transfer Protocol |
189
+ | `gelf` | Graylog Extended Log Format |
190
+ | `geneve` | Generic Network Virtualization Encapsulation |
191
+ | `gesrtp` | GE-SRTP |
192
+ | `git` | Git Smart Protocol |
193
+ | `glbp` | Gateway Load Balancing Protocol |
194
+ | `goose` | IEC61850 GOOSE |
195
+ | `gopher` | Internet Gopher Protocol |
196
+ | `gre` | Generic Routing Encapsulation |
197
+ | `gtp` | GPRS Tunnelling Protocol, User plane |
198
+ | `gtpv2` | GPRS Tunnelling Protocol version 2, Control plane |
199
+ | `hartip` | HART-IP |
200
+ | `hsr` | High-availability Seamless Redundancy |
201
+ | `hsrp` | Hot Standby Router Protocol |
202
+ | `http` | Hypertext Transfer Protocol |
203
+ | `http2` | Hypertext Transfer Protocol 2 |
204
+ | `iax2` | Inter-Asterisk eXchange v2 |
205
+ | `icmp` | Internet Control Message Protocol |
206
+ | `icmpv6` | Internet Control Message Protocol v6 |
207
+ | `ident` | Identification Protocol |
208
+ | `IEC104_I_Frame` | IEC 60870-5-104 |
209
+ | `IEC104_S_Frame` | IEC 60870-5-104 |
210
+ | `IEC104_U_Frame` | IEC 60870-5-104 |
211
+ | `igmp` | Internet Group Management Protocol |
212
+ | `imap` | Internet Message Access Protocol |
213
+ | `ipfix` | IP Flow Information Export |
214
+ | `ipv4` | Internet Protocol Version 4 |
215
+ | `ipv6` | Internet Protocol Version 6 |
216
+ | `ipv6-hopopt` | IPv6 Hop-by-Hop Option |
217
+ | `irc` | Internet Relay Chat |
218
+ | `isakmp` | ISAKMP/IKE |
219
+ | `iscsi` | Internet Small Computer Systems Interface |
220
+ | `isis` | Intermediate System to Intermediate System |
221
+ | `iso-session` | ISO Session |
222
+ | `kafka` | Kafka |
223
+ | `kerberos` | Kerberos |
224
+ | `knxnetip` | KNXnet/IP |
225
+ | `l2tp` | Layer Two Tunneling Protocol |
226
+ | `lacp` | Link Aggregation Control Protocol |
227
+ | `ldap` | LDAP |
228
+ | `ldp` | Label Distribution Protocol |
229
+ | `lisp` | Locator/ID Separation Protocol |
230
+ | `llc` | Logical Link Control |
231
+ | `lldp` | Link Layer Discovery Protocol |
232
+ | `llmnr` | Link-Local Multicast Name Resolution |
233
+ | `lpd` | Line Printer Daemon Protocol |
234
+ | `macsec` | MAC Security |
235
+ | `marker` | Link Aggregation Marker Protocol |
236
+ | `mdns` | Multicast DNS |
237
+ | `megaco` | Media Gateway Control Protocol (H.248/Megaco) |
238
+ | `memcached` | Memcached |
239
+ | `mgcp` | Media Gateway Control Protocol |
240
+ | `mms` | Manufacturing Message Specification |
241
+ | `modbus` | Modbus/TCP |
242
+ | `modbusudp` | Modbus/UDP |
243
+ | `mongodb` | MongoDB Wire Protocol |
244
+ | `mpls` | Multiprotocol Label Switching |
245
+ | `mqtt` | MQTT |
246
+ | `mqttsn` | MQTT for Sensor Networks |
247
+ | `mysql` | MySQL Protocol |
248
+ | `nats` | NATS Client Protocol |
249
+ | `nbds` | NetBIOS Datagram Service |
250
+ | `nbns` | NetBIOS Name Service |
251
+ | `nbss` | NetBIOS Session Service |
252
+ | `netflow5` | NetFlow v5 |
253
+ | `nfs` | Network File System |
254
+ | `nhrp` | NBMA Next Hop Resolution Protocol |
255
+ | `nntp` | Network News Transfer Protocol |
256
+ | `ntp` | Network Time Protocol |
257
+ | `olsr` | Optimized Link State Routing |
258
+ | `opcua` | OPC UA Connection Protocol |
259
+ | `opcua-pubsub` | OPC UA PubSub |
260
+ | `openflow` | OpenFlow |
261
+ | `openvpn` | OpenVPN Protocol |
262
+ | `ospf` | Open Shortest Path First |
263
+ | `pcworx` | PCWorx |
264
+ | `pgsql` | PostgreSQL Protocol |
265
+ | `pim` | Protocol Independent Multicast |
266
+ | `pnio` | PROFINET Real-Time |
267
+ | `pop3` | Post Office Protocol v3 |
268
+ | `powerlink` | Ethernet POWERLINK |
269
+ | `pppoe-disc` | PPP-over-Ethernet Discovery |
270
+ | `pppoe-sess` | PPP-over-Ethernet Session |
271
+ | `pptp` | Point-to-Point Tunnelling Protocol |
272
+ | `ptp` | Precision Time Protocol |
273
+ | `quic` | QUIC Transport |
274
+ | `r-session` | IEC 61850-90-5 Session |
275
+ | `radius` | Remote Authentication Dial-In User Service |
276
+ | `raw` | Raw Data |
277
+ | `rdp` | Remote Desktop Protocol |
278
+ | `redis` | Redis Serialization Protocol |
279
+ | `rfb` | RFB (VNC) |
280
+ | `rip` | Routing Information Protocol |
281
+ | `ripng` | RIP for IPv6 |
282
+ | `rlogin` | Rlogin |
283
+ | `rmcp` | Remote Management Control Protocol |
284
+ | `rsvp` | Resource ReSerVation Protocol |
285
+ | `rsync` | Rsync Daemon Protocol |
286
+ | `rtcp` | RTP Control Protocol |
287
+ | `rtp` | Real-time Transport Protocol |
288
+ | `rtps` | Real-Time Publish-Subscribe Wire Protocol |
289
+ | `rtsp` | Real Time Streaming Protocol |
290
+ | `s7comm` | S7 Communication |
291
+ | `sctp` | Stream Control Transmission Protocol |
292
+ | `sercos3` | Sercos III |
293
+ | `sflow` | sFlow v5 |
294
+ | `sip` | Session Initiation Protocol |
295
+ | `skinny` | Skinny Client Control Protocol |
296
+ | `slmp` | SeamLess Message Protocol |
297
+ | `slp` | Service Location Protocol |
298
+ | `slpv1` | Service Location Protocol Version 1 |
299
+ | `smb1` | SMB1 |
300
+ | `smb2` | SMB2 |
301
+ | `smpp` | Short Message Peer-to-Peer |
302
+ | `smtp` | Simple Mail Transfer Protocol |
303
+ | `snap` | Sub-Network Access Protocol |
304
+ | `snmp` | Simple Network Management Protocol |
305
+ | `socks4` | SOCKS4 |
306
+ | `socks5` | SOCKS5 |
307
+ | `ssdp` | Simple Service Discovery Protocol |
308
+ | `ssh` | SSH |
309
+ | `statsd` | StatsD Metrics Protocol |
310
+ | `stomp` | Simple Text Oriented Messaging Protocol |
311
+ | `stp` | Spanning Tree Protocol |
312
+ | `stun` | Session Traversal Utilities for NAT |
313
+ | `sunrpc` | ONC RPC |
314
+ | `sv` | IEC61850 Sampled Values |
315
+ | `syslog` | Syslog |
316
+ | `tacacs` | TACACS+ |
317
+ | `tcp` | Transmission Control Protocol |
318
+ | `telnet` | Telnet |
319
+ | `teredo` | Teredo IPv6 over UDP tunneling |
320
+ | `tftp` | Trivial File Transfer Protocol |
321
+ | `timeproto` | Time Protocol |
322
+ | `tls-alert` | Transport Layer Security(Alert Protocol) |
323
+ | `tls-appdata` | Transport Layer Security(Application Data Protocol) |
324
+ | `tls-ccsp` | Transport Layer Security(ChangeCipherSpec Protocol) |
325
+ | `tls-handshake` | Transport Layer Security(Handshake Protocol) |
326
+ | `tls-heartbeat` | Transport Layer Security(Heartbeat Protocol) |
327
+ | `tpkt` | TPKT |
328
+ | `udp` | User Datagram Protocol |
329
+ | `vlan` | 802.1Q Virtual LAN |
330
+ | `vrrp` | Virtual Router Redundancy Protocol |
331
+ | `vxlan` | Virtual eXtensible Local Area Network |
332
+ | `wccp` | Web Cache Communication Protocol |
333
+ | `whois` | WHOIS |
334
+ | `wireguard` | WireGuard |
335
+ | `wol` | Wake-on-LAN |
336
+ | `wsdiscovery` | Web Services Dynamic Discovery |
337
+ | `xmpp` | Extensible Messaging and Presence Protocol |
338
+ | `zabbix` | Zabbix Protocol |
339
+
340
+ ## 许可证
341
+
342
+ MIT
@@ -0,0 +1,133 @@
1
+ import { CodecModuleConstructor } from './types/CodecModuleConstructor';
2
+ import { CodecModule } from './types/CodecModule';
3
+ import { CodecDecodeResult } from './types/CodecDecodeResult';
4
+ import { CodecEncodeInput } from './types/CodecEncodeInput';
5
+ import { CodecData } from './types/CodecData';
6
+ import { CodecSchema } from './types/CodecSchema';
7
+ import { CodecEncodeResult } from './types/CodecEncodeResult';
8
+ import { NextLayer, ConsistencyIssue } from './types/LayerGraph';
9
+ import { DissectionLayer } from './types/Dissection';
10
+ /**
11
+ * The schema-driven packet codec: the entry point a consumer uses to turn bytes into a
12
+ * layered field tree and back.
13
+ *
14
+ * `decode(bytes)` walks the packet layer by layer, selecting each next header by an O(1)
15
+ * dispatch table keyed on the previous layer's demux value (`ethertype:`/`ipproto:`/
16
+ * `tcpport:`…), falling back to a content-heuristic chain for headers that must inspect
17
+ * their own bytes (TLS, IEC104, tunnels), and finally to `RawData` — so decode never
18
+ * throws and always yields a best-effort result plus a field-path-addressed error list.
19
+ * `encode(layers)` looks each layer up by protocol id and re-emits it in the given order.
20
+ * Cross-layer fixups (lengths, checksums) run as post-handlers afterwards. Read-only
21
+ * projections over the same decode are exposed via `dissect()`, `summary()`,
22
+ * `allowedNextLayers()`, `childDiscriminator()` and `checkConsistency()`.
23
+ */
24
+ export declare class Codec {
25
+ #private;
26
+ protected get HEADER_CODECS(): CodecModuleConstructor[];
27
+ get CODEC_SCHEMAS(): CodecSchema[];
28
+ /**
29
+ * Build a codec over the built-in protocol headers, optionally extended with custom ones.
30
+ * Each custom codec whose `PROTOCOL_ID` matches a built-in replaces it in place; the rest
31
+ * are appended. The dispatch table and heuristic chain are then built from the final set.
32
+ * @param codecModuleConstructors custom header codecs to override built-ins or add new protocols
33
+ */
34
+ constructor(codecModuleConstructors?: CodecModuleConstructor[]);
35
+ /**
36
+ * Load codec schemas
37
+ * @protected
38
+ */
39
+ protected loadCodecSchemas(): CodecSchema[];
40
+ /**
41
+ * Load header codecs
42
+ * @protected
43
+ */
44
+ protected loadHeaderCodecs(): CodecModuleConstructor[];
45
+ /**
46
+ * Build the dispatch table and heuristic list from the registered codecs.
47
+ * Called once after all codecs (built-in + custom overrides/additions) are
48
+ * assembled. RawData is pulled out as the explicit fallback.
49
+ * @protected
50
+ */
51
+ protected buildDispatchTable(): void;
52
+ /**
53
+ * Derive the demux keys exposed by the previously decoded layer.
54
+ * The layer order is decided entirely at runtime from these values, so a
55
+ * packet with or without a given header (e.g. an IPv6 packet with or
56
+ * without a Hop-by-Hop header) is handled purely by what its next-header
57
+ * fields actually say — the table itself encodes no layer ordering.
58
+ *
59
+ * etherType → 'ethertype:<value>' namespace.
60
+ * protocol AND nxt → shared 'ipproto:<value>' namespace, so a header
61
+ * registered under 'ipproto:6' (TCP) is reachable above both IPv4
62
+ * (protocol) and IPv6 (nxt).
63
+ * @param prevCodecModule
64
+ * @protected
65
+ */
66
+ protected computeDemuxKeys(prevCodecModule: CodecModule | undefined): string[];
67
+ /**
68
+ * Select the codec for the next layer: dispatch table → content-heuristic
69
+ * list → RawData. Never returns undefined; RawData always matches unknown
70
+ * or malformed data, so decode cannot fail.
71
+ * @param codecData
72
+ * @param codecModules
73
+ * @protected
74
+ */
75
+ protected selectCodec(codecData: CodecData, codecModules: CodecModule[], rootLinktype?: number): CodecModuleConstructor;
76
+ /**
77
+ * Decode packet
78
+ * @param packet
79
+ * @param linktype optional pcap link-layer type (DLT) to select the root layer (e.g. 1 = Ethernet,
80
+ * 127 = radiotap). Omit to use the default Ethernet-first root — existing callers are unaffected.
81
+ */
82
+ decode(packet: Buffer, linktype?: number): Promise<CodecDecodeResult[]>;
83
+ /**
84
+ * Encode packet
85
+ * @param inputs
86
+ */
87
+ encode(inputs: CodecEncodeInput[]): Promise<CodecEncodeResult>;
88
+ /**
89
+ * Editor helper (read-only projection over the same demux graph decode uses): the layers that
90
+ * may follow `parentLayerId`, each tagged with the {field,value} to set on the parent so decode
91
+ * would route to it. Derived by reversing the dispatch table over the parent's producer fields.
92
+ * RawData is always appended as the custom/fallback layer that may follow anything.
93
+ * @param parentLayerId
94
+ */
95
+ allowedNextLayers(parentLayerId: string): NextLayer[];
96
+ /**
97
+ * The {field,value} to set on `parentLayerId` so `childLayerId` follows it — used to auto-fill
98
+ * the parent discriminator when a child is added, and to suggest a fix for a consistency issue.
99
+ * Null when the child is not reachable from that parent via the demux graph (RawData, or a
100
+ * content-heuristic child such as TLS/IEC104 whose match is port/content based).
101
+ * @param parentLayerId
102
+ * @param childLayerId
103
+ */
104
+ childDiscriminator(parentLayerId: string, childLayerId: string): {
105
+ field: string;
106
+ value: string | number;
107
+ } | null;
108
+ /**
109
+ * Editor helper: report parent layers whose discriminator field does not point at the child that
110
+ * actually follows (e.g. eth.etherType says IPv6 but the next layer is IPv4). This is advisory
111
+ * only — encode never blocks on it, since a deliberately-inconsistent packet is a valid crafted
112
+ * packet. Only demux-based relationships are checked; content-heuristic children (TLS/IEC104) are
113
+ * not flagged. RawData may follow anything and is never flagged.
114
+ * @param decoded
115
+ */
116
+ checkConsistency(decoded: CodecDecodeResult[]): ConsistencyIssue[];
117
+ /**
118
+ * Wireshark-style dissection: decode the packet with byte-range tracking on, then project each
119
+ * layer into a field tree carrying the value, the schema label, the exact packet bytes the field
120
+ * occupies, and an error/ok severity. A read-only view over the SAME decode — not a second
121
+ * parser. Normal decode() is untouched (ranges are collected only here).
122
+ * @param packet
123
+ */
124
+ dissect(packet: Buffer): Promise<DissectionLayer[]>;
125
+ /**
126
+ * One-line human summary of a decoded packet (Wireshark's Info column). The innermost layer that
127
+ * declares a `summary` template in its schema wins (the most specific layer describes the packet);
128
+ * the template's ${dotted.field} placeholders are filled from that layer's decoded data. Falls back
129
+ * to the innermost non-raw layer's name when no template is declared. Read-only projection.
130
+ * @param decoded
131
+ */
132
+ summary(decoded: CodecDecodeResult[]): string;
133
+ }