mirror of
https://github.com/jwetzell/osc-js.git
synced 2026-08-28 10:19:00 +00:00
fix osc bundles not parsing multiple content chunks correctly
This commit is contained in:
+41
-31
@@ -22,42 +22,52 @@ export function bundleFromBuffer(bytes: Uint8Array): [OSCBundle | undefined, Uin
|
|||||||
|
|
||||||
let endOfBundle = false;
|
let endOfBundle = false;
|
||||||
|
|
||||||
let [contentSize, remainingBytes] = oscTypeConverterMap.i.fromBuffer(bytesAfterTimeTag);
|
// let [contentSize, remainingBytes] = oscTypeConverterMap.i.fromBuffer(bytesAfterTimeTag);
|
||||||
if (typeof contentSize === 'number') {
|
let remainingBytes = bytesAfterTimeTag;
|
||||||
while (!endOfBundle) {
|
|
||||||
if (remainingBytes.length < contentSize) {
|
|
||||||
throw new Error('bundle does not contain enough data');
|
|
||||||
}
|
|
||||||
|
|
||||||
const bundleContentBytes = remainingBytes.subarray(0, contentSize);
|
while (!endOfBundle) {
|
||||||
|
let [contentSize, bytesAfterContentSize] = oscTypeConverterMap.i.fromBuffer(remainingBytes);
|
||||||
|
|
||||||
if (bundleContentBytes[0] === 35) {
|
if (typeof contentSize !== 'number') {
|
||||||
// # character indicating contents is a bundle
|
throw new Error('problem decoding content size');
|
||||||
const [content, bytesAfterContent] = bundleFromBuffer(bundleContentBytes);
|
}
|
||||||
if (content) {
|
|
||||||
bundleContents.push(content);
|
remainingBytes = bytesAfterContentSize;
|
||||||
}
|
|
||||||
} else if (bundleContentBytes[0] === 47) {
|
if (remainingBytes.length < contentSize) {
|
||||||
const [content, bytesAfterContent] = messageFromBuffer(bundleContentBytes);
|
throw new Error('bundle does not contain enough data');
|
||||||
if (content && content !== undefined) {
|
}
|
||||||
bundleContents.push(content);
|
|
||||||
}
|
const bundleContentBytes = bytesAfterContentSize.subarray(0, contentSize);
|
||||||
} else {
|
|
||||||
throw new Error('bundle contents does not look like a OSC message or bundle');
|
if (bundleContentBytes[0] === 35) {
|
||||||
}
|
// # character indicating contents is a bundle
|
||||||
|
const [content, bytesAfterContent] = bundleFromBuffer(bundleContentBytes);
|
||||||
remainingBytes = remainingBytes.subarray(contentSize);
|
if (content) {
|
||||||
if (remainingBytes.length === 0) {
|
bundleContents.push(content);
|
||||||
endOfBundle = true;
|
}
|
||||||
}
|
} else if (bundleContentBytes[0] === 47) {
|
||||||
|
const [content, bytesAfterContent] = messageFromBuffer(bundleContentBytes);
|
||||||
|
if (content && content !== undefined) {
|
||||||
|
bundleContents.push(content);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error('bundle contents does not look like a OSC message or bundle');
|
||||||
|
}
|
||||||
|
|
||||||
|
remainingBytes = bytesAfterContentSize.subarray(contentSize);
|
||||||
|
if (remainingBytes.length === 0) {
|
||||||
|
endOfBundle = true;
|
||||||
}
|
}
|
||||||
return [{
|
|
||||||
timeTag,
|
|
||||||
contents: bundleContents,
|
|
||||||
},remainingBytes];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return [undefined, undefined]
|
return [
|
||||||
|
{
|
||||||
|
timeTag,
|
||||||
|
contents: bundleContents,
|
||||||
|
},
|
||||||
|
remainingBytes,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function bundleToBuffer(bundle: OSCBundle): Uint8Array {
|
export function bundleToBuffer(bundle: OSCBundle): Uint8Array {
|
||||||
|
|||||||
Reference in New Issue
Block a user