mirror of
https://github.com/jwetzell/acn-js.git
synced 2026-09-10 07:49:26 +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;
|
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 {
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ export function decode(bytes: Uint8Array): SessionDataTransportPDU {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
vector,
|
vector,
|
||||||
|
length,
|
||||||
data,
|
data,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user