fromBuffer methods should return any unprocessed results

This commit is contained in:
2024-10-13 15:22:28 -05:00
parent 27585b8f55
commit f47aae936f
2 changed files with 13 additions and 12 deletions
+9 -8
View File
@@ -2,7 +2,7 @@ import { messageFromBuffer, messageToBuffer } from './message';
import { OSCBundle } from './models';
import { oscTypeConverterMap } from './osc-types';
export function bundleFromBuffer(bytes: Uint8Array): OSCBundle | undefined {
export function bundleFromBuffer(bytes: Uint8Array): [OSCBundle | undefined, Uint8Array | undefined] {
if (bytes.length < 8) {
throw new Error('bundle has to be at least 20 bytes');
}
@@ -33,13 +33,13 @@ export function bundleFromBuffer(bytes: Uint8Array): OSCBundle | undefined {
if (bundleContentBytes[0] === 35) {
// # character indicating contents is a bundle
const content = bundleFromBuffer(bundleContentBytes);
const [content, bytesAfterContent] = bundleFromBuffer(bundleContentBytes);
if (content) {
bundleContents.push(content);
}
} else if (bundleContentBytes[0] === 47) {
const content = messageFromBuffer(bundleContentBytes);
if (content) {
const [content, bytesAfterContent] = messageFromBuffer(bundleContentBytes);
if (content && content !== undefined) {
bundleContents.push(content);
}
} else {
@@ -51,12 +51,13 @@ export function bundleFromBuffer(bytes: Uint8Array): OSCBundle | undefined {
endOfBundle = true;
}
}
return [{
timeTag,
contents: bundleContents,
},remainingBytes];
}
return {
timeTag,
contents: bundleContents,
};
return [undefined, undefined]
}
export function bundleToBuffer(bundle: OSCBundle): Uint8Array {
+4 -4
View File
@@ -46,7 +46,7 @@ export function messageToBuffer(message: OSCMessage): Uint8Array {
return buffer;
}
export function messageFromBuffer(bytes: Uint8Array): OSCMessage | undefined {
export function messageFromBuffer(bytes: Uint8Array): [OSCMessage | undefined, Uint8Array | undefined] {
if (bytes[0] !== 47) {
throw new Error('osc message must start with a /');
}
@@ -78,11 +78,11 @@ export function messageFromBuffer(bytes: Uint8Array): OSCMessage | undefined {
}
argsBuffer = remainingBytes;
}
return {
return [{
address,
args: oscArgs,
};
}, argsBuffer];
}
}
return [undefined, undefined]
}