mirror of
https://github.com/jwetzell/osc-js.git
synced 2026-08-12 02:33:40 +00:00
Merge pull request #11 from jwetzell/from-buffer-extra-bytes
fromBuffer methods should return any unprocessed results
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user