mirror of
https://github.com/jwetzell/acn-js.git
synced 2026-07-26 10:28:41 +00:00
add support for decoding all PDUs in an SDT PDU
This commit is contained in:
@@ -51,12 +51,21 @@ function decode(bytes: Uint8Array): RootLayerPDU {
|
||||
const dataOffset = headerOffset + 16;
|
||||
// NOTE(jwetzell): flags/lengthH + lengthL + lengthX + vector + header
|
||||
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) {
|
||||
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 {
|
||||
console.error(`unhandled protocol in RLP: ${vector}`)
|
||||
console.error(`unhandled protocol in RLP: ${vector}`);
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -62,6 +62,7 @@ export function decode(bytes: Uint8Array): SessionDataTransportPDU {
|
||||
|
||||
return {
|
||||
vector,
|
||||
length,
|
||||
data,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ export type ACNPacket<PreambleType, PDUBlockType, PostambleType> = {
|
||||
export type RootLayerPDU = {
|
||||
vector: number;
|
||||
header: string;
|
||||
data: SessionDataTransportPDU | Uint8Array;
|
||||
data: SessionDataTransportPDU[] | Uint8Array;
|
||||
};
|
||||
|
||||
export type SDTChannelParams = {
|
||||
@@ -114,6 +114,7 @@ export type SDTGetSessionsData = {
|
||||
|
||||
export type SessionDataTransportPDU = {
|
||||
vector: SDTVector;
|
||||
length: number;
|
||||
// TODO(jwetzell): cleanup these types
|
||||
data:
|
||||
| SDTJoinData
|
||||
|
||||
Reference in New Issue
Block a user