node-osc 11.1.0 → 11.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
+ var node_buffer = require('node:buffer');
4
+
3
5
  // OSC 1.0 Protocol Implementation
4
6
  // Based on http://opensoundcontrol.org/spec-1_0
5
7
 
6
- // Helper functions for OSC encoding/decoding
7
8
 
8
9
  function padString(str) {
9
10
  const nullTerminated = str + '\0';
@@ -23,7 +24,7 @@ function readString(buffer, offset) {
23
24
  }
24
25
 
25
26
  function writeInt32(value) {
26
- const buffer = Buffer.alloc(4);
27
+ const buffer = node_buffer.Buffer.alloc(4);
27
28
  buffer.writeInt32BE(value, 0);
28
29
  return buffer;
29
30
  }
@@ -34,7 +35,7 @@ function readInt32(buffer, offset) {
34
35
  }
35
36
 
36
37
  function writeFloat32(value) {
37
- const buffer = Buffer.alloc(4);
38
+ const buffer = node_buffer.Buffer.alloc(4);
38
39
  buffer.writeFloatBE(value, 0);
39
40
  return buffer;
40
41
  }
@@ -48,8 +49,8 @@ function writeBlob(value) {
48
49
  const length = value.length;
49
50
  const lengthBuffer = writeInt32(length);
50
51
  const padding = 4 - (length % 4);
51
- const paddingBuffer = Buffer.alloc(padding === 4 ? 0 : padding);
52
- return Buffer.concat([lengthBuffer, value, paddingBuffer]);
52
+ const paddingBuffer = node_buffer.Buffer.alloc(padding === 4 ? 0 : padding);
53
+ return node_buffer.Buffer.concat([lengthBuffer, value, paddingBuffer]);
53
54
  }
54
55
 
55
56
  function readBlob(buffer, offset) {
@@ -64,7 +65,7 @@ function readBlob(buffer, offset) {
64
65
  function writeTimeTag(value) {
65
66
  // For now, treat timetag as a double (8 bytes)
66
67
  // OSC timetag is 64-bit: 32-bit seconds since 1900, 32-bit fractional
67
- const buffer = Buffer.alloc(8);
68
+ const buffer = node_buffer.Buffer.alloc(8);
68
69
  if (typeof value === 'number') {
69
70
  // Convert to OSC timetag format
70
71
  const seconds = Math.floor(value);
@@ -99,9 +100,9 @@ function readTimeTag(buffer, offset) {
99
100
 
100
101
  function writeMidi(value) {
101
102
  // MIDI message is 4 bytes: port id, status byte, data1, data2
102
- const buffer = Buffer.alloc(4);
103
+ const buffer = node_buffer.Buffer.alloc(4);
103
104
 
104
- if (Buffer.isBuffer(value)) {
105
+ if (node_buffer.Buffer.isBuffer(value)) {
105
106
  if (value.length !== 4) {
106
107
  throw new Error('MIDI message must be exactly 4 bytes');
107
108
  }
@@ -140,7 +141,7 @@ function encodeArgument(arg) {
140
141
  return { tag: 'f', data: writeFloat32(arg.value) };
141
142
  case 's':
142
143
  case 'string':
143
- return { tag: 's', data: Buffer.from(padString(arg.value)) };
144
+ return { tag: 's', data: node_buffer.Buffer.from(padString(arg.value)) };
144
145
  case 'b':
145
146
  case 'blob':
146
147
  return { tag: 'b', data: writeBlob(arg.value) };
@@ -150,7 +151,7 @@ function encodeArgument(arg) {
150
151
  return { tag: 'f', data: writeFloat32(arg.value) };
151
152
  case 'T':
152
153
  case 'boolean':
153
- return arg.value ? { tag: 'T', data: Buffer.alloc(0) } : { tag: 'F', data: Buffer.alloc(0) };
154
+ return arg.value ? { tag: 'T', data: node_buffer.Buffer.alloc(0) } : { tag: 'F', data: node_buffer.Buffer.alloc(0) };
154
155
  case 'm':
155
156
  case 'midi':
156
157
  return { tag: 'm', data: writeMidi(arg.value) };
@@ -168,11 +169,11 @@ function encodeArgument(arg) {
168
169
  return { tag: 'f', data: writeFloat32(arg) };
169
170
  }
170
171
  case 'string':
171
- return { tag: 's', data: Buffer.from(padString(arg)) };
172
+ return { tag: 's', data: node_buffer.Buffer.from(padString(arg)) };
172
173
  case 'boolean':
173
- return arg ? { tag: 'T', data: Buffer.alloc(0) } : { tag: 'F', data: Buffer.alloc(0) };
174
+ return arg ? { tag: 'T', data: node_buffer.Buffer.alloc(0) } : { tag: 'F', data: node_buffer.Buffer.alloc(0) };
174
175
  default:
175
- if (Buffer.isBuffer(arg)) {
176
+ if (node_buffer.Buffer.isBuffer(arg)) {
176
177
  return { tag: 'b', data: writeBlob(arg) };
177
178
  }
178
179
  throw new Error(`Don't know how to encode argument: ${arg}`);
@@ -217,15 +218,15 @@ function encodeMessageToBuffer(message) {
217
218
  // Arguments (encoded according to type tags)
218
219
 
219
220
  const address = padString(message.address);
220
- const addressBuffer = Buffer.from(address);
221
+ const addressBuffer = node_buffer.Buffer.from(address);
221
222
 
222
223
  const encodedArgs = message.args.map(encodeArgument);
223
224
  const typeTags = ',' + encodedArgs.map(arg => arg.tag).join('');
224
- const typeTagsBuffer = Buffer.from(padString(typeTags));
225
+ const typeTagsBuffer = node_buffer.Buffer.from(padString(typeTags));
225
226
 
226
227
  const argumentBuffers = encodedArgs.map(arg => arg.data);
227
228
 
228
- return Buffer.concat([addressBuffer, typeTagsBuffer, ...argumentBuffers]);
229
+ return node_buffer.Buffer.concat([addressBuffer, typeTagsBuffer, ...argumentBuffers]);
229
230
  }
230
231
 
231
232
  function encodeBundleToBuffer(bundle) {
@@ -235,7 +236,7 @@ function encodeBundleToBuffer(bundle) {
235
236
  // Elements (each prefixed with size)
236
237
 
237
238
  const bundleString = padString('#bundle');
238
- const bundleStringBuffer = Buffer.from(bundleString);
239
+ const bundleStringBuffer = node_buffer.Buffer.from(bundleString);
239
240
 
240
241
  const timetagBuffer = writeTimeTag(bundle.timetag);
241
242
 
@@ -247,10 +248,10 @@ function encodeBundleToBuffer(bundle) {
247
248
  elementBuffer = encodeMessageToBuffer(element);
248
249
  }
249
250
  const sizeBuffer = writeInt32(elementBuffer.length);
250
- return Buffer.concat([sizeBuffer, elementBuffer]);
251
+ return node_buffer.Buffer.concat([sizeBuffer, elementBuffer]);
251
252
  });
252
253
 
253
- return Buffer.concat([bundleStringBuffer, timetagBuffer, ...elementBuffers]);
254
+ return node_buffer.Buffer.concat([bundleStringBuffer, timetagBuffer, ...elementBuffers]);
254
255
  }
255
256
 
256
257
  function fromBuffer(buffer) {
@@ -3,6 +3,8 @@
3
3
 
4
4
  // Helper functions for OSC encoding/decoding
5
5
 
6
+ import { Buffer } from 'node:buffer';
7
+
6
8
  function padString(str) {
7
9
  const nullTerminated = str + '\0';
8
10
  const padding = 4 - (nullTerminated.length % 4);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "node-osc",
3
3
  "description": "pyOSC inspired library for sending and receiving OSC messages",
4
- "version": "11.1.0",
4
+ "version": "11.1.1",
5
5
  "exports": {
6
6
  "require": "./dist/lib/index.js",
7
7
  "default": "./lib/index.mjs"
package/rollup.config.mjs CHANGED
@@ -34,8 +34,10 @@ function walkLib(config) {
34
34
  external: [
35
35
  'node:dgram',
36
36
  'node:events',
37
+ 'node:buffer',
37
38
  'jspack',
38
- '#decode'
39
+ '#decode',
40
+ '#osc'
39
41
  ]
40
42
  });
41
43
  });
@@ -57,9 +59,11 @@ function walkTest(config) {
57
59
  external: [
58
60
  'node:dgram',
59
61
  'node:net',
62
+ 'node:buffer',
60
63
  'node-osc',
61
64
  'tap',
62
- '#decode'
65
+ '#decode',
66
+ '#osc'
63
67
  ]
64
68
  });
65
69
  });