OSC message decoder/encoder with fault tolerant
npm install osc-msg> OSC message decoder/encoder with fault tolerant
bundle and stripnpm:
```
npm install osc-msg
- oscmsg.decode(buffer: Buffer, opts={}): objectopts.strict
- : strictly validation modeopts.strip
- : decode into raw valuesopts.bundle
- : decode as a bundlefromBuffer
- aliases: , toObjectoscmsg.encode(object: object, opts={}): Buffer
- opts.strict
- : strictly validation modeopts.integer
- : use an integer when auto castfromObject
- aliases: , toBuffer
decode
`js
const dgram = require("dgram");
const oscmsg = require("osc-msg");
const socket = dgram.createSocket("udp4");
socket.on("message", (buffer) => {
const bundle = oscmsg.decode(buffer, { strict: true, strip: true, bundle: true });
if (bundle.error) {
return;
}
bundle.elements.forEach((message) => {
console.log(JSON.stringify(message));
});
});
socket.bind(RECV_PORT);
`
encode
`js
const dgram = require("dgram");
const oscmsg = require("osc-msg");
const message = {
address: "/foo",
args: [
{ type: "integer", value: 0 },
{ type: "float", value: 1.5 }
]
};
const buffer = oscmsg.encode(message);
const socket = dgram.createSocket("udp4");
socket.send(buffer, 0, buffer.length, SEND_PORT, "127.0.0.1");
`
_compatible interfaces with osc-min_
- OSC Message
`js`
{
"address": string,
"args": [ arg1, arg2, ...argN ],
"oscType": "message"
}
Where args is an array of OSC Arguments. oscType is optional. args can be a single element.
- OSC Arguments
`js`
{ "type": string, "value": any }
Where the type is one of the following:
- string - string valuefloat
- - numeric valueinteger
- - numeric valueblob
- - Buffer-like valuetrue
- - value is boolean truefalse
- - value is boolean falsenull
- - no valuebang
- - no value (this is the I type tag)timetag
- - [ uint32, uint32 ]array
- - array of OSC Arguments
- OSC Bundle
`js`
{
"timetag": number,
"elements": [ element1, element2, ...elementN ],
"oscType": "bundle"
}
Where the timetag is a javascript-native numeric value of the timetag, and elements is an array of either an OSC Bundle or an OSC Message The oscType` field is optional, but is always returned by api functions.