add function to guess type and decode

This commit is contained in:
2024-10-21 12:44:43 -05:00
parent 5449c8ec5b
commit aa1cae428b
2 changed files with 55 additions and 0 deletions
+14
View File
@@ -1,3 +1,17 @@
import { bundleFromBuffer } from './bundle';
import { messageFromBuffer } from './message';
import { OSCBundle, OSCMessage } from './models';
export * from './models';
export * from './message';
export * from './bundle';
export function fromBuffer(bytes: Uint8Array): [OSCBundle | OSCMessage | undefined, Uint8Array | undefined] {
if (bytes[0] === 47) { // starts with '/'
return messageFromBuffer(bytes);
} else if (bytes[0] === 35) { // starts with '#'
return bundleFromBuffer(bytes)
} else {
throw new Error('bytes do not look like an OSC message or bundle');
}
}