add support for decoding all PDUs in an SDT PDU

This commit is contained in:
2024-12-08 11:03:40 -06:00
parent b4f406de21
commit 1e3da4571d
3 changed files with 15 additions and 4 deletions
+12 -3
View File
@@ -51,12 +51,21 @@ function decode(bytes: Uint8Array): RootLayerPDU {
const dataOffset = headerOffset + 16; const dataOffset = headerOffset + 16;
// NOTE(jwetzell): flags/lengthH + lengthL + lengthX + vector + header // NOTE(jwetzell): flags/lengthH + lengthL + lengthX + vector + header
const dataLength = length - (1 + 1 + (lengthFlag ? 1 : 0) + 4 + 16); const dataLength = length - (1 + 1 + (lengthFlag ? 1 : 0) + 4 + 16);
let data: SessionDataTransportPDU | Uint8Array = bytes.subarray(dataOffset, dataOffset + dataLength); let data: SessionDataTransportPDU[] | Uint8Array = bytes.subarray(dataOffset, dataOffset + dataLength);
if (vector === Protocol.SDT) { if (vector === Protocol.SDT) {
data = pdu.sdt.decode(data); const blocks: SessionDataTransportPDU[] = [];
let blockDataOffset = 0;
// TODO(jwetzell): this could blow up so might need some attention later?
while (blockDataOffset < dataLength) {
const blockData = pdu.sdt.decode(bytes.subarray(dataOffset + blockDataOffset));
blocks.push(blockData);
blockDataOffset += blockData.length;
}
data = blocks;
} else { } else {
console.error(`unhandled protocol in RLP: ${vector}`) console.error(`unhandled protocol in RLP: ${vector}`);
} }
return { return {
+1
View File
@@ -62,6 +62,7 @@ export function decode(bytes: Uint8Array): SessionDataTransportPDU {
return { return {
vector, vector,
length,
data, data,
}; };
} }
+2 -1
View File
@@ -15,7 +15,7 @@ export type ACNPacket<PreambleType, PDUBlockType, PostambleType> = {
export type RootLayerPDU = { export type RootLayerPDU = {
vector: number; vector: number;
header: string; header: string;
data: SessionDataTransportPDU | Uint8Array; data: SessionDataTransportPDU[] | Uint8Array;
}; };
export type SDTChannelParams = { export type SDTChannelParams = {
@@ -114,6 +114,7 @@ export type SDTGetSessionsData = {
export type SessionDataTransportPDU = { export type SessionDataTransportPDU = {
vector: SDTVector; vector: SDTVector;
length: number;
// TODO(jwetzell): cleanup these types // TODO(jwetzell): cleanup these types
data: data:
| SDTJoinData | SDTJoinData