@netkitty/codec 2.1.0 → 2.2.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.
- package/CHANGELOG.md +188 -0
- package/README.md +21 -1
- package/README.zh-CN.md +19 -1
- package/dist/Codec.d.ts +4 -3
- package/dist/Codec.js +44 -5
- package/dist/PacketHeaders.d.ts +2 -0
- package/dist/PacketHeaders.js +8 -4
- package/dist/abstracts/BaseHeader.d.ts +17 -0
- package/dist/abstracts/BaseHeader.js +22 -0
- package/dist/headers/ARP.d.ts +3 -1
- package/dist/headers/ARP.js +8 -1
- package/dist/headers/BACnetIP.js +2 -1
- package/dist/headers/BGP.js +3 -2
- package/dist/headers/Babel.js +1 -1
- package/dist/headers/Codesys.js +3 -2
- package/dist/headers/DHCP.js +2 -1
- package/dist/headers/DNP3.d.ts +12 -7
- package/dist/headers/DNP3.js +98 -18
- package/dist/headers/DTLS.js +5 -3
- package/dist/headers/Diameter.js +2 -1
- package/dist/headers/Elasticsearch.js +3 -2
- package/dist/headers/EthernetII.d.ts +1 -0
- package/dist/headers/EthernetII.js +3 -0
- package/dist/headers/Goose.d.ts +31 -7
- package/dist/headers/Goose.js +409 -168
- package/dist/headers/HARTIP.js +2 -2
- package/dist/headers/IEC104_I_Frame.d.ts +28 -0
- package/dist/headers/IEC104_I_Frame.js +246 -160
- package/dist/headers/IEC104_S_Frame.js +3 -3
- package/dist/headers/IEC104_U_Frame.js +5 -3
- package/dist/headers/IEC61850SampledValues.d.ts +1 -0
- package/dist/headers/IEC61850SampledValues.js +16 -1
- package/dist/headers/IPFIX.js +2 -1
- package/dist/headers/IPv4.d.ts +1 -0
- package/dist/headers/IPv4.js +6 -0
- package/dist/headers/IPv6.d.ts +1 -0
- package/dist/headers/IPv6.js +6 -0
- package/dist/headers/IPv6HopByHopOptions.js +8 -0
- package/dist/headers/KNXnetIP.js +3 -2
- package/dist/headers/LACP.js +2 -1
- package/dist/headers/LDP.js +2 -2
- package/dist/headers/MQTT.js +3 -1
- package/dist/headers/MarkerProtocol.js +2 -1
- package/dist/headers/NetFlowV5.js +2 -1
- package/dist/headers/OPCUA.js +4 -0
- package/dist/headers/OSPF.d.ts +2 -2
- package/dist/headers/OSPF.js +26 -5
- package/dist/headers/OSPFv3.d.ts +37 -0
- package/dist/headers/OSPFv3.js +314 -0
- package/dist/headers/PPTP.js +2 -2
- package/dist/headers/QUIC.js +8 -3
- package/dist/headers/RGoose.js +2 -1
- package/dist/headers/RIP.js +3 -2
- package/dist/headers/RIPng.js +3 -2
- package/dist/headers/RTCP.js +3 -2
- package/dist/headers/RTP.js +3 -2
- package/dist/headers/SFlow.js +4 -2
- package/dist/headers/SLMP.js +2 -1
- package/dist/headers/SLP.js +2 -1
- package/dist/headers/SLPv1.js +2 -1
- package/dist/headers/SMB1.js +3 -2
- package/dist/headers/SMB2.js +3 -2
- package/dist/headers/STUN.js +2 -1
- package/dist/headers/TLS_Handshake.d.ts +6 -0
- package/dist/headers/TLS_Handshake.js +28 -3
- package/dist/headers/TacacsPlus.js +3 -1
- package/dist/headers/Trailer.d.ts +30 -0
- package/dist/headers/Trailer.js +63 -0
- package/dist/headers/VLAN_802dot1Q.d.ts +1 -0
- package/dist/headers/VLAN_802dot1Q.js +3 -0
- package/dist/headers/WakeOnLAN.js +2 -1
- package/dist/headers/WireGuard.js +3 -2
- package/dist/headers/Zabbix.js +2 -2
- package/dist/lib/BERElement.d.ts +51 -0
- package/dist/lib/BERElement.js +125 -0
- package/package.json +2 -2
package/dist/headers/BGP.js
CHANGED
|
@@ -41,8 +41,9 @@ class BGP extends BaseHeader_1.BaseHeader {
|
|
|
41
41
|
summary: 'BGP type=${type} len=${length}',
|
|
42
42
|
properties: {
|
|
43
43
|
//The 16-byte Marker. In RFC 4271 (no authentication) it is all ones (0xFF); kept
|
|
44
|
-
//verbatim so any legacy/authenticated marker still round-trips.
|
|
45
|
-
|
|
44
|
+
//verbatim so any legacy/authenticated marker still round-trips. Default all ones: what
|
|
45
|
+
//match() requires.
|
|
46
|
+
marker: { ...this.fieldHex('marker', 0, 16, 'Marker'), default: 'ff'.repeat(16) },
|
|
46
47
|
length: {
|
|
47
48
|
type: 'integer',
|
|
48
49
|
autoCalculated: true,
|
package/dist/headers/Babel.js
CHANGED
|
@@ -61,7 +61,7 @@ class Babel extends BaseHeader_1.BaseHeader {
|
|
|
61
61
|
summary: 'Babel v${version} ${tlvs.length} TLVs',
|
|
62
62
|
properties: {
|
|
63
63
|
//The Magic byte, always 42 (0x2a) for Babel — also the match signature on UDP 6696.
|
|
64
|
-
magic: this.fieldUInt('magic', 0, 1, 'Magic'),
|
|
64
|
+
magic: { ...this.fieldUInt('magic', 0, 1, 'Magic'), default: 42 },
|
|
65
65
|
//The protocol version, always 2 (RFC 8966).
|
|
66
66
|
version: this.fieldUInt('version', 1, 1, 'Version'),
|
|
67
67
|
//The octet count of the packet body (the TLV sequence) following this 4-byte header, NOT
|
package/dist/headers/Codesys.js
CHANGED
|
@@ -47,8 +47,9 @@ class Codesys extends BaseHeader_1.BaseHeader {
|
|
|
47
47
|
summary: 'CODESYS len=${length}',
|
|
48
48
|
properties: {
|
|
49
49
|
//The 4-byte block-driver magic (00 01 17 e8). Kept verbatim (not enum-constrained) so any
|
|
50
|
-
//observed frame round-trips even if a variant carries a different signature.
|
|
51
|
-
|
|
50
|
+
//observed frame round-trips even if a variant carries a different signature. Default
|
|
51
|
+
//000117e8: what match() requires.
|
|
52
|
+
magic: { ...this.fieldHex('magic', 0, 4, 'Block Driver Magic'), default: Codesys.#MAGIC },
|
|
52
53
|
//Block-driver payload byte count that follows the 8-byte header. LITTLE-ENDIAN 32-bit.
|
|
53
54
|
//Honored when supplied (a crafted frame may lie); else derived from the payload bytes.
|
|
54
55
|
length: {
|
package/dist/headers/DHCP.js
CHANGED
|
@@ -53,7 +53,8 @@ class DHCP extends BaseHeader_1.BaseHeader {
|
|
|
53
53
|
chaddr: this.fieldHex('chaddr', 28, 16, 'Client Hardware Address'),
|
|
54
54
|
sname: this.fieldHex('sname', 44, 64, 'Server Host Name'),
|
|
55
55
|
file: this.fieldHex('file', 108, 128, 'Boot File Name'),
|
|
56
|
-
|
|
56
|
+
//Default 0x63825363: the DHCP Magic Cookie (RFC 2131 §3), and what match() requires.
|
|
57
|
+
magicCookie: { ...this.fieldHex('magicCookie', 236, 4, 'Magic Cookie'), default: '63825363' },
|
|
57
58
|
options: {
|
|
58
59
|
type: 'array',
|
|
59
60
|
label: 'Options',
|
package/dist/headers/DNP3.d.ts
CHANGED
|
@@ -9,13 +9,18 @@ import { DemuxProducer } from '../types/DemuxProducer';
|
|
|
9
9
|
* Source address, and a header CRC. The user data that follows is carried in blocks of up to 16 octets
|
|
10
10
|
* each with its own trailing 2-byte CRC.
|
|
11
11
|
*
|
|
12
|
-
* This codec decodes the link header structurally and
|
|
13
|
-
*
|
|
14
|
-
* the transport/application layer is a cross-frame
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
12
|
+
* This codec decodes the link header structurally and carries the data-block region in one of two hex
|
|
13
|
+
* fields. `userData` is the user data with the block CRCs removed (transport header + application data,
|
|
14
|
+
* not decoded further: reassembling the transport/application layer is a cross-frame concern); `payload`
|
|
15
|
+
* is the region verbatim, block CRCs included. Decode emits exactly one of them: `userData` when the
|
|
16
|
+
* region is complete and every block CRC verifies, otherwise `payload` plus a warning naming each bad or
|
|
17
|
+
* truncated block. On encode a given `payload` wins and is written as given (how a frame with a wrong
|
|
18
|
+
* block CRC is crafted; a `userData` given alongside it is ignored with a warning); otherwise `userData`
|
|
19
|
+
* is split into 16-octet blocks, each followed by its CRC-16/DNP, low octet first. Length and the header
|
|
20
|
+
* CRC are written as given; left out, Length counts the user data octets (the block CRCs excluded) and
|
|
21
|
+
* the header CRC is computed (CRC-16/DNP over the first 8 octets). A frame round-trips byte-for-byte
|
|
22
|
+
* either way; the frame's extent is derived from the Length field so a pipelined/trailing frame is left
|
|
23
|
+
* to RawData.
|
|
19
24
|
*/
|
|
20
25
|
export declare class DNP3 extends BaseHeader {
|
|
21
26
|
#private;
|
package/dist/headers/DNP3.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var _a;
|
|
2
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
exports.DNP3 = void 0;
|
|
4
5
|
const BaseHeader_1 = require("../abstracts/BaseHeader");
|
|
@@ -16,13 +17,18 @@ const Crc_1 = require("../helper/Crc");
|
|
|
16
17
|
* Source address, and a header CRC. The user data that follows is carried in blocks of up to 16 octets
|
|
17
18
|
* each with its own trailing 2-byte CRC.
|
|
18
19
|
*
|
|
19
|
-
* This codec decodes the link header structurally and
|
|
20
|
-
*
|
|
21
|
-
* the transport/application layer is a cross-frame
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
20
|
+
* This codec decodes the link header structurally and carries the data-block region in one of two hex
|
|
21
|
+
* fields. `userData` is the user data with the block CRCs removed (transport header + application data,
|
|
22
|
+
* not decoded further: reassembling the transport/application layer is a cross-frame concern); `payload`
|
|
23
|
+
* is the region verbatim, block CRCs included. Decode emits exactly one of them: `userData` when the
|
|
24
|
+
* region is complete and every block CRC verifies, otherwise `payload` plus a warning naming each bad or
|
|
25
|
+
* truncated block. On encode a given `payload` wins and is written as given (how a frame with a wrong
|
|
26
|
+
* block CRC is crafted; a `userData` given alongside it is ignored with a warning); otherwise `userData`
|
|
27
|
+
* is split into 16-octet blocks, each followed by its CRC-16/DNP, low octet first. Length and the header
|
|
28
|
+
* CRC are written as given; left out, Length counts the user data octets (the block CRCs excluded) and
|
|
29
|
+
* the header CRC is computed (CRC-16/DNP over the first 8 octets). A frame round-trips byte-for-byte
|
|
30
|
+
* either way; the frame's extent is derived from the Length field so a pipelined/trailing frame is left
|
|
31
|
+
* to RawData.
|
|
26
32
|
*/
|
|
27
33
|
class DNP3 extends BaseHeader_1.BaseHeader {
|
|
28
34
|
constructor() {
|
|
@@ -31,12 +37,12 @@ class DNP3 extends BaseHeader_1.BaseHeader {
|
|
|
31
37
|
this.name = 'Distributed Network Protocol 3';
|
|
32
38
|
this.nickname = 'DNP3';
|
|
33
39
|
this.matchKeys = ['tcpport:20000', 'udpport:20000'];
|
|
34
|
-
//A leaf header — the transport/application layers require
|
|
40
|
+
//A leaf header — the transport/application layers require reassembly across frames.
|
|
35
41
|
this.demuxProducers = [];
|
|
36
42
|
}
|
|
37
43
|
static #schemaCache;
|
|
38
44
|
get SCHEMA() {
|
|
39
|
-
return (
|
|
45
|
+
return (_a.#schemaCache ??= _a.#buildSchema());
|
|
40
46
|
}
|
|
41
47
|
/** A single bit of the Control octet (byte 3, bit 0 = MSB). */
|
|
42
48
|
static #flagBit(name, bitOffset, label) {
|
|
@@ -68,6 +74,50 @@ class DNP3 extends BaseHeader_1.BaseHeader {
|
|
|
68
74
|
const rest = payloadOctets % 18;
|
|
69
75
|
return Math.floor(payloadOctets / 18) * 16 + (rest > 2 ? rest - 2 : 0);
|
|
70
76
|
}
|
|
77
|
+
/** A block CRC-16/DNP as it goes on the wire, low octet first. */
|
|
78
|
+
static #blockCrc(data) {
|
|
79
|
+
const crc = (0, Crc_1.Crc16Dnp)(data);
|
|
80
|
+
return Buffer.from([crc & 0xff, (crc >> 8) & 0xff]);
|
|
81
|
+
}
|
|
82
|
+
/** `userData` split into 16-octet blocks, each followed by its CRC. */
|
|
83
|
+
static #toDataBlocks(userData) {
|
|
84
|
+
const blocks = [];
|
|
85
|
+
for (let offset = 0; offset < userData.length; offset += 16) {
|
|
86
|
+
const data = userData.subarray(offset, offset + 16);
|
|
87
|
+
blocks.push(data, _a.#blockCrc(data));
|
|
88
|
+
}
|
|
89
|
+
return Buffer.concat(blocks);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Read the data-block region (bounded by the Length-derived frame extent and the captured bytes) and
|
|
93
|
+
* de-block it along the block sizes the Length field implies. `faults` names every block whose CRC
|
|
94
|
+
* does not verify and a block the capture cuts short; `userData` (the data octets, CRCs removed) is
|
|
95
|
+
* only meaningful when there are none.
|
|
96
|
+
*/
|
|
97
|
+
#dataBlocks() {
|
|
98
|
+
const frameLength = this.#frameLength();
|
|
99
|
+
const remaining = this.packet.length - this.startPos;
|
|
100
|
+
const end = frameLength > remaining ? remaining : frameLength;
|
|
101
|
+
const region = end > 10 ? this.readBytes(10, end - 10) : Buffer.alloc(0);
|
|
102
|
+
const data = [];
|
|
103
|
+
const faults = [];
|
|
104
|
+
let offset = 0;
|
|
105
|
+
for (let block = 1; offset < frameLength - 10; block++) {
|
|
106
|
+
const size = Math.min(18, frameLength - 10 - offset);
|
|
107
|
+
if (offset + size > region.length) {
|
|
108
|
+
faults.push(`Data block ${block} is truncated: ${region.length - offset} of ${size} octets`);
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
const blockData = region.subarray(offset, offset + size - 2);
|
|
112
|
+
const crc = (0, BufferToHex_1.BufferToHex)(region.subarray(offset + size - 2, offset + size));
|
|
113
|
+
const expected = (0, BufferToHex_1.BufferToHex)(_a.#blockCrc(blockData));
|
|
114
|
+
if (crc !== expected)
|
|
115
|
+
faults.push(`Data block ${block} CRC ${crc} does not match the computed ${expected}`);
|
|
116
|
+
data.push(blockData);
|
|
117
|
+
offset += size;
|
|
118
|
+
}
|
|
119
|
+
return { region: region, userData: Buffer.concat(data), faults: faults };
|
|
120
|
+
}
|
|
71
121
|
static #buildSchema() {
|
|
72
122
|
return {
|
|
73
123
|
type: 'object',
|
|
@@ -75,7 +125,8 @@ class DNP3 extends BaseHeader_1.BaseHeader {
|
|
|
75
125
|
properties: {
|
|
76
126
|
//Default 0x0564: the start octets every DNP3 frame begins with, and what match() requires.
|
|
77
127
|
start: { ...this.fieldHex('start', 0, 2, 'Start'), default: '0564' },
|
|
78
|
-
//Octets from Control through the user data, the block CRCs excluded: 5 + user data octets
|
|
128
|
+
//Octets from Control through the user data, the block CRCs excluded: 5 + user data octets,
|
|
129
|
+
//counted from whichever of payload / userData is written.
|
|
79
130
|
length: {
|
|
80
131
|
type: 'integer',
|
|
81
132
|
autoCalculated: true,
|
|
@@ -90,7 +141,10 @@ class DNP3 extends BaseHeader_1.BaseHeader {
|
|
|
90
141
|
this.writeBytes(2, (0, NumberToBuffer_1.UInt8ToBuffer)(this.instance.length.getValue(0)));
|
|
91
142
|
return;
|
|
92
143
|
}
|
|
93
|
-
|
|
144
|
+
const userDataOctets = this.isLeftOut(this.instance.payload)
|
|
145
|
+
? (0, HexToBuffer_1.HexToBuffer)(this.instance.userData.getValue('')).length
|
|
146
|
+
: _a.#userDataOctets((0, HexToBuffer_1.HexToBuffer)(this.instance.payload.getValue('')).length);
|
|
147
|
+
let length = 5 + userDataOctets;
|
|
94
148
|
if (length > 255) {
|
|
95
149
|
this.recordError(this.instance.length.getPath(), 'Maximum value is 255');
|
|
96
150
|
length = 255;
|
|
@@ -168,18 +222,43 @@ class DNP3 extends BaseHeader_1.BaseHeader {
|
|
|
168
222
|
this.writeBytes(8, crcBuffer);
|
|
169
223
|
}
|
|
170
224
|
},
|
|
171
|
-
//The data
|
|
172
|
-
//
|
|
225
|
+
//The user data (transport header + application data) with the block CRCs removed. Decoded
|
|
226
|
+
//when the data-block region is complete and every block CRC verifies; encoded into 16-octet
|
|
227
|
+
//blocks, each followed by its CRC, unless a payload is given.
|
|
228
|
+
userData: {
|
|
229
|
+
type: 'string',
|
|
230
|
+
label: 'User Data',
|
|
231
|
+
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
232
|
+
decode: function () {
|
|
233
|
+
const blocks = this.#dataBlocks();
|
|
234
|
+
if (!blocks.faults.length)
|
|
235
|
+
this.instance.userData.setValue((0, BufferToHex_1.BufferToHex)(blocks.userData));
|
|
236
|
+
},
|
|
237
|
+
encode: function () {
|
|
238
|
+
if (this.isLeftOut(this.instance.userData))
|
|
239
|
+
return;
|
|
240
|
+
if (!this.isLeftOut(this.instance.payload)) {
|
|
241
|
+
this.recordError(this.instance.userData.getPath(), 'Ignored: payload is given and is written verbatim instead');
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
this.writeBytes(10, _a.#toDataBlocks((0, HexToBuffer_1.HexToBuffer)(this.instance.userData.getValue(''))));
|
|
245
|
+
}
|
|
246
|
+
},
|
|
247
|
+
//The data-block region verbatim: transport header + application data + per-block CRCs.
|
|
248
|
+
//Decoded instead of userData when a block CRC is wrong or the capture cuts a block short;
|
|
249
|
+
//given on encode, it is written as given. Bounded by the Length-derived frame extent so a
|
|
250
|
+
//pipelined/trailing frame is left to raw.
|
|
173
251
|
payload: {
|
|
174
252
|
type: 'string',
|
|
175
253
|
label: 'Payload',
|
|
176
254
|
contentEncoding: StringContentEncodingEnum_1.StringContentEncodingEnum.HEX,
|
|
177
255
|
decode: function () {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
256
|
+
if (!this.instance.userData.isUndefined())
|
|
257
|
+
return;
|
|
258
|
+
const blocks = this.#dataBlocks();
|
|
259
|
+
this.instance.payload.setValue((0, BufferToHex_1.BufferToHex)(blocks.region));
|
|
260
|
+
for (const fault of blocks.faults)
|
|
261
|
+
this.recordError(this.instance.payload.getPath(), `${fault}; the data blocks are kept verbatim as payload`, 'warning');
|
|
183
262
|
},
|
|
184
263
|
encode: function () {
|
|
185
264
|
const payload = this.instance.payload.getValue('');
|
|
@@ -203,3 +282,4 @@ class DNP3 extends BaseHeader_1.BaseHeader {
|
|
|
203
282
|
}
|
|
204
283
|
}
|
|
205
284
|
exports.DNP3 = DNP3;
|
|
285
|
+
_a = DNP3;
|
package/dist/headers/DTLS.js
CHANGED
|
@@ -64,11 +64,13 @@ class DTLS extends BaseHeader_1.BaseHeader {
|
|
|
64
64
|
summary: 'DTLS type=${contentType} len=${length}',
|
|
65
65
|
properties: {
|
|
66
66
|
//ContentType (20 change_cipher_spec, 21 alert, 22 handshake, 23 application_data,
|
|
67
|
-
//24 heartbeat). Kept as an integer — the record header is otherwise opaque here.
|
|
68
|
-
|
|
67
|
+
//24 heartbeat). Kept as an integer — the record header is otherwise opaque here. Default
|
|
68
|
+
//22 (handshake): match() requires a type in 20..25.
|
|
69
|
+
contentType: { ...this.fieldUInt('contentType', 0, 1, 'Content Type'), default: 22 },
|
|
69
70
|
//Version — 0xfeff DTLS 1.0 / 0xfefd DTLS 1.2. Stored as a lower-case hex string so any
|
|
70
71
|
//value round-trips verbatim (the match gate restricts real selection to feff/fefd).
|
|
71
|
-
|
|
72
|
+
//Default fefd (DTLS 1.2).
|
|
73
|
+
version: { ...this.fieldHex('version', 1, 2, 'Version'), default: 'fefd' },
|
|
72
74
|
epoch: this.fieldUInt('epoch', 3, 2, 'Epoch'),
|
|
73
75
|
//48-bit per-epoch sequence number, kept verbatim as hex (exceeds the 32-bit fieldUInt path).
|
|
74
76
|
sequenceNumber: this.fieldHex('sequenceNumber', 5, 6, 'Sequence Number'),
|
package/dist/headers/Diameter.js
CHANGED
|
@@ -65,7 +65,8 @@ class Diameter extends BaseHeader_1.BaseHeader {
|
|
|
65
65
|
type: 'object',
|
|
66
66
|
summary: 'Diameter cmd=${commandCode}',
|
|
67
67
|
properties: {
|
|
68
|
-
|
|
68
|
+
//Default 1: the only Diameter version (RFC 6733 §3), and what match() requires.
|
|
69
|
+
version: { ...this.fieldUInt('version', 0, 1, 'Version'), default: 1 },
|
|
69
70
|
messageLength: {
|
|
70
71
|
type: 'integer',
|
|
71
72
|
autoCalculated: true,
|
|
@@ -43,8 +43,9 @@ class Elasticsearch extends BaseHeader_1.BaseHeader {
|
|
|
43
43
|
type: 'object',
|
|
44
44
|
summary: 'Elasticsearch reqId=${requestId} len=${messageLength}',
|
|
45
45
|
properties: {
|
|
46
|
-
//The 'ES' magic (0x4553) — kept verbatim as hex so any prefix still round-trips.
|
|
47
|
-
|
|
46
|
+
//The 'ES' magic (0x4553) — kept verbatim as hex so any prefix still round-trips. Default
|
|
47
|
+
//'ES': what match() requires.
|
|
48
|
+
magic: { ...this.fieldHex('magic', 0, 2, 'Magic'), default: '4553' },
|
|
48
49
|
messageLength: {
|
|
49
50
|
type: 'integer',
|
|
50
51
|
autoCalculated: true,
|
|
@@ -101,6 +101,9 @@ class EthernetII extends BaseHeader_1.BaseHeader {
|
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
|
+
payloadEnd() {
|
|
105
|
+
return this.ieee802dot3PayloadEnd(this.instance.etherType);
|
|
106
|
+
}
|
|
104
107
|
match() {
|
|
105
108
|
//Fewer bytes than the 14-octet header cannot be reproduced by these fields (encode always writes
|
|
106
109
|
//a whole header): leave them to raw so they round-trip byte-exact.
|
package/dist/headers/Goose.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ProtocolJSONSchema } from '../schema/ProtocolJSONSchema';
|
|
2
2
|
import { BaseHeader } from '../abstracts/BaseHeader';
|
|
3
|
-
import
|
|
3
|
+
import { BERElement } from '../lib/BERElement';
|
|
4
4
|
declare enum ItemDataType {
|
|
5
5
|
Boolean = "Boolean",
|
|
6
6
|
INT8 = "INT8",
|
|
@@ -78,10 +78,21 @@ type StructureDataItem = {
|
|
|
78
78
|
dataType: ItemDataType.Structure;
|
|
79
79
|
value: DataItem[];
|
|
80
80
|
};
|
|
81
|
-
|
|
81
|
+
/**
|
|
82
|
+
* How a goosePdu element was encoded on the wire, where that differs from the form encode writes by
|
|
83
|
+
* default (the minimal BER length, the minimal INTEGER content). Decode records it only for such
|
|
84
|
+
* elements, so a tree without it encodes exactly as before; encode follows it while the value fits.
|
|
85
|
+
*/
|
|
86
|
+
type ElementEncoding = {
|
|
87
|
+
lengthOctets?: number;
|
|
88
|
+
width?: number;
|
|
89
|
+
content?: string;
|
|
90
|
+
};
|
|
91
|
+
type DataItem = (BooleanDataItem | INT8DataItem | INT16DataItem | INT32DataItem | INT64DataItem | INT8UDataItem | INT16UDataItem | INT32UDataItem | FLOAT32DataItem | CODEDENUMDataItem | OCTETSTRINGDataItem | VISIBLESTRINGDataItem | TimeStampDataItem | QualityDataItem | StructureDataItem) & {
|
|
92
|
+
encoding?: ElementEncoding;
|
|
93
|
+
};
|
|
82
94
|
export declare class Goose extends BaseHeader {
|
|
83
|
-
|
|
84
|
-
protected TLVChild: TLV[];
|
|
95
|
+
#private;
|
|
85
96
|
/**
|
|
86
97
|
* True when at least one structured goosePdu field decoded/was supplied. Used to
|
|
87
98
|
* decide whether the raw-passthrough fallback applies.
|
|
@@ -96,10 +107,11 @@ export declare class Goose extends BaseHeader {
|
|
|
96
107
|
SCHEMA: ProtocolJSONSchema;
|
|
97
108
|
/**
|
|
98
109
|
* Decode data TLV items
|
|
99
|
-
* @param
|
|
110
|
+
* @param dataElements
|
|
111
|
+
* @param path
|
|
100
112
|
* @protected
|
|
101
113
|
*/
|
|
102
|
-
protected decodeDataTLVItem(
|
|
114
|
+
protected decodeDataTLVItem(dataElements: BERElement[], path: string): DataItem[];
|
|
103
115
|
/**
|
|
104
116
|
* Decode a BIT STRING (tag 0x84) data item
|
|
105
117
|
* CODED-ENUM is 2 octets and Quality 3 octets (the leading unused-bits octet included in the
|
|
@@ -130,16 +142,28 @@ export declare class Goose extends BaseHeader {
|
|
|
130
142
|
* @protected
|
|
131
143
|
*/
|
|
132
144
|
protected decodeUnsignedIntegerItem(value: Buffer, path: string): DataItem;
|
|
145
|
+
/**
|
|
146
|
+
* Decode a FLOATING-POINT (tag 0x87) data item
|
|
147
|
+
* The first content octet is the exponent width, not part of the number: IEC 61850-8-1 encodes a
|
|
148
|
+
* FLOAT32 as 08 followed by the 4 octets of an IEEE 754 single. A FLOAT64 (exponent width 11, 8
|
|
149
|
+
* octets) keeps its value; other forms read as 0. Either way the item re-encodes as captured until
|
|
150
|
+
* its value changes.
|
|
151
|
+
* @param value
|
|
152
|
+
* @param path
|
|
153
|
+
* @protected
|
|
154
|
+
*/
|
|
155
|
+
protected decodeFloatingPointItem(value: Buffer, path: string): DataItem;
|
|
133
156
|
/**
|
|
134
157
|
* Encode data TLV items
|
|
135
158
|
* @param dataItems
|
|
136
159
|
* @protected
|
|
137
160
|
*/
|
|
138
|
-
protected encodeDataTLVItem(dataItems: DataItem[]):
|
|
161
|
+
protected encodeDataTLVItem(dataItems: DataItem[]): Buffer[];
|
|
139
162
|
readonly id: string;
|
|
140
163
|
readonly matchKeys: string[];
|
|
141
164
|
readonly name: string;
|
|
142
165
|
readonly nickname: string;
|
|
143
166
|
match(): boolean;
|
|
167
|
+
payloadEnd(): number | undefined;
|
|
144
168
|
}
|
|
145
169
|
export {};
|