MCPcopy Create free account
hub / github.com/csound/csound / structBufferToObject

Function structBufferToObject

wasm/browser/src/utils/structure-buffer-to-object.js:5–20  ·  view source on GitHub ↗
(jsStruct, buffer)

Source from the content-addressed store, hash-verified

3import { trimNull } from "./trim-null.js";
4
5export const structBufferToObject = (jsStruct, buffer) => {
6 const [result] = jsStruct.reduce(
7 ([parameters, offset], [parameterName, primitive, ...rest]) => {
8 const currentSize =
9 primitive === "char" ? sizeOfPrimitive[primitive] * rest[0] : sizeOfPrimitive[primitive];
10 const currentValue =
11 primitive === "char"
12 ? trimNull(uint2String(buffer.subarray(offset, currentSize))) || ""
13 : buffer[offset];
14 parameters[parameterName] = currentValue;
15 return [parameters, offset + currentSize];
16 },
17 [{}, 0],
18 );
19 return result;
20};

Callers 2

csoundGetParamsFunction · 0.90
csoundGetMIDIDevListFunction · 0.90

Calls 2

trimNullFunction · 0.90
uint2StringFunction · 0.90

Tested by

no test coverage detected