Treat transport codes and path as their own segments

This commit is contained in:
2026-03-11 15:42:00 +01:00
parent 10c7092313
commit 6daadc97fc

View File

@@ -119,48 +119,68 @@ export class Packet implements IPacket {
this.structure = [
/* Header segment */
{ name: "header", data: new Uint8Array([this.header, this.pathLength, ...this.path]), fields: [
/* Header flags */
{
name: "flags",
type: FieldType.BITS,
size: 1,
bits: [
{ name: "payload version", size: 2 },
{ name: "payload type", size: 4 },
{ name: "route type", size: 2 },
]
},
/* Transport codes */
...(Packet.hasTransportCodes(this.routeType) ? [
{
name: "header",
data: new Uint8Array([this.header]),
fields: [
/* Header flags */
{
name: "flags",
type: FieldType.BITS,
size: 1,
bits: [
{ name: "payload version", size: 2 },
{ name: "payload type", size: 4 },
{ name: "route type", size: 2 },
]
},
]
},
/* Transport codes */
...(Packet.hasTransportCodes(this.routeType) ? [{
name: "transport codes",
data: new Uint8Array([
(this.transport![0] >> 8) & 0xff, this.transport![0] & 0xff,
(this.transport![1] >> 8) & 0xff, this.transport![1] & 0xff
]),
fields: [
{
name: "transport code 1",
type: FieldType.UINT16_BE,
size: 2
size: 2,
value: this.transport![0]
},
{
name: "transport code 2",
type: FieldType.UINT16_BE,
size: 2
size: 2,
value: this.transport![1]
},
] : []),
]
}] : []),
/* Path length and hashes */
{
name: "path length",
type: FieldType.UINT8,
size: 1,
bits: [
{ name: "path hash size", size: 2 },
{ name: "path hash count", size: 6 },
]
},
{
name: "path hashes",
type: pathHashType,
size: this.path.length
}
]},
/* Path length and hashes */
{
name: "path",
data: new Uint8Array([this.pathLength, ...this.path]),
fields: [
{
name: "path length",
type: FieldType.UINT8,
size: 1,
bits: [
{ name: "path hash size", size: 2 },
{ name: "path hash count", size: 6 },
]
},
{
name: "path hashes",
type: pathHashType,
size: this.path.length
}
]
},
]
}