Skip to content

Commit

Permalink
Allow ArrayBufferView in Switch.Service dispatch functions
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Dec 23, 2024
1 parent 0ac92cf commit 61278b4
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
5 changes: 5 additions & 0 deletions .changeset/early-meals-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nx.js/runtime": patch
---

Allow `ArrayBufferView` in `Switch.Service` dispatch functions
14 changes: 9 additions & 5 deletions packages/runtime/src/switch/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface ServiceDispatchParams {
//SfBufferAttrs buffer_attrs;
//SfBuffer buffers[8];
bufferAttrs?: number[];
buffers?: ArrayBuffer[];
buffers?: (ArrayBuffer | ArrayBufferView)[];

//bool in_send_pid;
inSendPid?: boolean;
Expand Down Expand Up @@ -56,22 +56,26 @@ export class Service {
this.dispatchInOut(rid, undefined, undefined, params);
}

dispatchIn(rid: number, inData: ArrayBuffer, parmas?: ServiceDispatchParams) {
dispatchIn(
rid: number,
inData: ArrayBuffer | ArrayBufferView,
parmas?: ServiceDispatchParams,
) {
this.dispatchInOut(rid, inData, undefined, parmas);
}

dispatchOut(
rid: number,
outData: ArrayBuffer,
outData: ArrayBuffer | ArrayBufferView,
params?: ServiceDispatchParams,
) {
this.dispatchInOut(rid, undefined, outData, params);
}

dispatchInOut(
rid: number,
inData?: ArrayBuffer,
outData?: ArrayBuffer,
inData?: ArrayBuffer | ArrayBufferView,
outData?: ArrayBuffer | ArrayBufferView,
params?: ServiceDispatchParams,
) {
stub();
Expand Down
17 changes: 5 additions & 12 deletions source/service.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "service.h"
#include "error.h"
#include "util.h"

static JSClassID nx_service_class_id;

Expand Down Expand Up @@ -82,16 +83,10 @@ static JSValue nx_service_dispatch_in_out(JSContext *ctx, JSValueConst this_val,
}

size_t in_data_size = 0;
void *in_data = NULL;
if (JS_IsArrayBuffer(argv[1])) {
in_data = JS_GetArrayBuffer(ctx, &in_data_size, argv[1]);
}
void *in_data = NX_GetArrayBufferView(ctx, &in_data_size, argv[1]);

size_t out_data_size = 0;
void *out_data = NULL;
if (JS_IsArrayBuffer(argv[2])) {
out_data = JS_GetArrayBuffer(ctx, &out_data_size, argv[2]);
}
void *out_data = NX_GetArrayBufferView(ctx, &out_data_size, argv[2]);

SfDispatchParams disp = {0};
if (JS_IsObject(argv[3])) {
Expand Down Expand Up @@ -171,10 +166,8 @@ static JSValue nx_service_dispatch_in_out(JSContext *ctx, JSValueConst this_val,
}
for (u32 i = 0; i < length; i++) {
JSValue v = JS_GetPropertyUint32(ctx, buffers_val, i);
if (JS_IsArrayBuffer(v)) {
disp.buffers[i].ptr =
JS_GetArrayBuffer(ctx, &disp.buffers[i].size, v);
}
disp.buffers[i].ptr =
NX_GetArrayBufferView(ctx, &disp.buffers[i].size, v);
JS_FreeValue(ctx, v);
}
}
Expand Down

0 comments on commit 61278b4

Please sign in to comment.