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 { OSCBundle } from './models';
import { oscTypeConverterMap } from './osc-types'; 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) { if (bytes.length < 8) {
throw new Error('bundle has to be at least 20 bytes'); 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) { if (bundleContentBytes[0] === 35) {
// # character indicating contents is a bundle // # character indicating contents is a bundle
const content = bundleFromBuffer(bundleContentBytes); const [content, bytesAfterContent] = bundleFromBuffer(bundleContentBytes);
if (content) { if (content) {
bundleContents.push(content); bundleContents.push(content);
} }
} else if (bundleContentBytes[0] === 47) { } else if (bundleContentBytes[0] === 47) {
const content = messageFromBuffer(bundleContentBytes); const [content, bytesAfterContent] = messageFromBuffer(bundleContentBytes);
if (content) { if (content && content !== undefined) {
bundleContents.push(content); bundleContents.push(content);
} }
} else { } else {
@@ -51,12 +51,13 @@ export function bundleFromBuffer(bytes: Uint8Array): OSCBundle | undefined {
endOfBundle = true; endOfBundle = true;
} }
} }
return [{
timeTag,
contents: bundleContents,
},remainingBytes];
} }
return { return [undefined, undefined]
timeTag,
contents: bundleContents,
};
} }
export function bundleToBuffer(bundle: OSCBundle): Uint8Array { export function bundleToBuffer(bundle: OSCBundle): Uint8Array {
+4 -4
View File
@@ -46,7 +46,7 @@ export function messageToBuffer(message: OSCMessage): Uint8Array {
return buffer; return buffer;
} }
export function messageFromBuffer(bytes: Uint8Array): OSCMessage | undefined { export function messageFromBuffer(bytes: Uint8Array): [OSCMessage | undefined, Uint8Array | undefined] {
if (bytes[0] !== 47) { if (bytes[0] !== 47) {
throw new Error('osc message must start with a /'); throw new Error('osc message must start with a /');
} }
@@ -78,11 +78,11 @@ export function messageFromBuffer(bytes: Uint8Array): OSCMessage | undefined {
} }
argsBuffer = remainingBytes; argsBuffer = remainingBytes;
} }
return [{
return {
address, address,
args: oscArgs, args: oscArgs,
}; }, argsBuffer];
} }
} }
return [undefined, undefined]
} }