1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

use flatbuffer create functions to add fields (#2046)

This commit is contained in:
Jonathon Orsi 2019-04-07 20:51:43 -04:00 committed by Ryan Dahl
parent 86aee7f137
commit 3452a10840
26 changed files with 98 additions and 197 deletions

View file

@ -9,10 +9,7 @@ function req(
): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
const builder = flatbuffers.createBuilder();
const path_ = builder.createString(path);
msg.Chmod.startChmod(builder);
msg.Chmod.addPath(builder, path_);
msg.Chmod.addMode(builder, mode);
const inner = msg.Chmod.endChmod(builder);
const inner = msg.Chmod.createChmod(builder, path_, mode);
return [builder, msg.Any.Chmod, inner];
}

View file

@ -10,10 +10,7 @@ function req(
const builder = flatbuffers.createBuilder();
const from_ = builder.createString(from);
const to_ = builder.createString(to);
msg.CopyFile.startCopyFile(builder);
msg.CopyFile.addFrom(builder, from_);
msg.CopyFile.addTo(builder, to_);
const inner = msg.CopyFile.endCopyFile(builder);
const inner = msg.CopyFile.createCopyFile(builder, from_, to_);
return [builder, msg.Any.CopyFile, inner];
}

View file

@ -30,8 +30,6 @@ export function cwd(): string {
export function chdir(directory: string): void {
const builder = flatbuffers.createBuilder();
const directory_ = builder.createString(directory);
msg.Chdir.startChdir(builder);
msg.Chdir.addDirectory(builder, directory_);
const inner = msg.Chdir.endChdir(builder);
const inner = msg.Chdir.createChdir(builder, directory_);
sendSync(builder, msg.Any.Chdir, inner);
}

View file

@ -31,12 +31,16 @@ function sendInternal(
sync = true
): [number, null | Uint8Array] {
const cmdId = nextCmdId++;
msg.Base.startBase(builder);
msg.Base.addInner(builder, inner);
msg.Base.addInnerType(builder, innerType);
msg.Base.addSync(builder, sync);
msg.Base.addCmdId(builder, cmdId);
builder.finish(msg.Base.endBase(builder));
const message = msg.Base.createBase(
builder,
cmdId,
sync,
0,
0,
innerType,
inner
);
builder.finish(message);
const control = builder.asUint8Array();
const response = core.dispatch(control, zeroCopy);

View file

@ -308,32 +308,29 @@ function msgHttpRequest(
method: null | string,
headers: null | domTypes.Headers
): flatbuffers.Offset {
const methodOffset = !method ? -1 : builder.createString(method);
let fieldsOffset: flatbuffers.Offset = -1;
const methodOffset = !method ? 0 : builder.createString(method);
let fieldsOffset: flatbuffers.Offset = 0;
const urlOffset = builder.createString(url);
if (headers) {
const kvOffsets: flatbuffers.Offset[] = [];
for (const [key, val] of headers.entries()) {
const keyOffset = builder.createString(key);
const valOffset = builder.createString(val);
msg.KeyValue.startKeyValue(builder);
msg.KeyValue.addKey(builder, keyOffset);
msg.KeyValue.addValue(builder, valOffset);
kvOffsets.push(msg.KeyValue.endKeyValue(builder));
kvOffsets.push(
msg.KeyValue.createKeyValue(builder, keyOffset, valOffset)
);
}
fieldsOffset = msg.HttpHeader.createFieldsVector(builder, kvOffsets);
} else {
}
msg.HttpHeader.startHttpHeader(builder);
msg.HttpHeader.addIsRequest(builder, true);
msg.HttpHeader.addUrl(builder, urlOffset);
if (methodOffset >= 0) {
msg.HttpHeader.addMethod(builder, methodOffset);
}
if (fieldsOffset >= 0) {
msg.HttpHeader.addFields(builder, fieldsOffset);
}
return msg.HttpHeader.endHttpHeader(builder);
return msg.HttpHeader.createHttpHeader(
builder,
true,
methodOffset,
urlOffset,
0,
fieldsOffset
);
}
function deserializeHeaderFields(m: msg.HttpHeader): Array<[string, string]> {
@ -405,12 +402,10 @@ export async function fetch(
// Send Fetch message
const builder = flatbuffers.createBuilder();
const headerOff = msgHttpRequest(builder, url, method, headers);
msg.Fetch.startFetch(builder);
msg.Fetch.addHeader(builder, headerOff);
const resBase = await sendAsync(
builder,
msg.Any.Fetch,
msg.Fetch.endFetch(builder),
msg.Fetch.createFetch(builder, headerOff),
body
);

View file

@ -22,10 +22,7 @@ function reqOpen(
const builder = flatbuffers.createBuilder();
const filename_ = builder.createString(filename);
const mode_ = builder.createString(mode);
msg.Open.startOpen(builder);
msg.Open.addFilename(builder, filename_);
msg.Open.addMode(builder, mode_);
const inner = msg.Open.endOpen(builder);
const inner = msg.Open.createOpen(builder, filename_, 0, mode_);
return [builder, msg.Any.Open, inner];
}
@ -66,9 +63,7 @@ function reqRead(
p: Uint8Array
): [flatbuffers.Builder, msg.Any, flatbuffers.Offset, Uint8Array] {
const builder = flatbuffers.createBuilder();
msg.Read.startRead(builder);
msg.Read.addRid(builder, rid);
const inner = msg.Read.endRead(builder);
const inner = msg.Read.createRead(builder, rid);
return [builder, msg.Any.Read, inner, p];
}
@ -114,9 +109,7 @@ function reqWrite(
p: Uint8Array
): [flatbuffers.Builder, msg.Any, flatbuffers.Offset, Uint8Array] {
const builder = flatbuffers.createBuilder();
msg.Write.startWrite(builder);
msg.Write.addRid(builder, rid);
const inner = msg.Write.endWrite(builder);
const inner = msg.Write.createWrite(builder, rid);
return [builder, msg.Any.Write, inner, p];
}
@ -163,11 +156,7 @@ function reqSeek(
whence: SeekMode
): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
const builder = flatbuffers.createBuilder();
msg.Seek.startSeek(builder);
msg.Seek.addRid(builder, rid);
msg.Seek.addOffset(builder, offset);
msg.Seek.addWhence(builder, whence);
const inner = msg.Seek.endSeek(builder);
const inner = msg.Seek.createSeek(builder, rid, offset, whence);
return [builder, msg.Any.Seek, inner];
}
@ -198,9 +187,7 @@ export async function seek(
/** Close the file ID. */
export function close(rid: number): void {
const builder = flatbuffers.createBuilder();
msg.Close.startClose(builder);
msg.Close.addRid(builder, rid);
const inner = msg.Close.endClose(builder);
const inner = msg.Close.createClose(builder, rid);
dispatch.sendSync(builder, msg.Any.Close, inner);
}

View file

@ -7,9 +7,7 @@ import { assert } from "./util";
export function formatError(errString: string): string {
const builder = flatbuffers.createBuilder();
const errString_ = builder.createString(errString);
msg.FormatError.startFormatError(builder);
msg.FormatError.addError(builder, errString_);
const offset = msg.FormatError.endFormatError(builder);
const offset = msg.FormatError.createFormatError(builder, errString_);
const baseRes = sendSync(builder, msg.Any.FormatError, offset);
assert(baseRes != null);
assert(msg.Any.FormatErrorRes === baseRes!.innerType());

View file

@ -16,20 +16,15 @@ function req({
suffix
}: MakeTempDirOptions): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
const builder = flatbuffers.createBuilder();
const fbDir = dir == null ? -1 : builder.createString(dir);
const fbPrefix = prefix == null ? -1 : builder.createString(prefix);
const fbSuffix = suffix == null ? -1 : builder.createString(suffix);
msg.MakeTempDir.startMakeTempDir(builder);
if (dir != null) {
msg.MakeTempDir.addDir(builder, fbDir);
}
if (prefix != null) {
msg.MakeTempDir.addPrefix(builder, fbPrefix);
}
if (suffix != null) {
msg.MakeTempDir.addSuffix(builder, fbSuffix);
}
const inner = msg.MakeTempDir.endMakeTempDir(builder);
const fbDir = dir == null ? 0 : builder.createString(dir);
const fbPrefix = prefix == null ? 0 : builder.createString(prefix);
const fbSuffix = suffix == null ? 0 : builder.createString(suffix);
const inner = msg.MakeTempDir.createMakeTempDir(
builder,
fbDir,
fbPrefix,
fbSuffix
);
return [builder, msg.Any.MakeTempDir, inner];
}

View file

@ -14,8 +14,7 @@ export interface Metrics {
function req(): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
const builder = flatbuffers.createBuilder();
msg.Metrics.startMetrics(builder);
const inner = msg.Metrics.endMetrics(builder);
const inner = msg.Metrics.createMetrics(builder);
return [builder, msg.Any.Metrics, inner];
}

View file

@ -10,11 +10,7 @@ function req(
): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
const builder = flatbuffers.createBuilder();
const path_ = builder.createString(path);
msg.Mkdir.startMkdir(builder);
msg.Mkdir.addPath(builder, path_);
msg.Mkdir.addRecursive(builder, recursive);
msg.Mkdir.addMode(builder, mode);
const inner = msg.Mkdir.endMkdir(builder);
const inner = msg.Mkdir.createMkdir(builder, path_, recursive, mode);
return [builder, msg.Any.Mkdir, inner];
}

View file

@ -37,10 +37,7 @@ enum ShutdownMode {
function shutdown(rid: number, how: ShutdownMode): void {
const builder = flatbuffers.createBuilder();
msg.Shutdown.startShutdown(builder);
msg.Shutdown.addRid(builder, rid);
msg.Shutdown.addHow(builder, how);
const inner = msg.Shutdown.endShutdown(builder);
const inner = msg.Shutdown.createShutdown(builder, rid, how);
const baseRes = dispatch.sendSync(builder, msg.Any.Shutdown, inner);
assert(baseRes == null);
}
@ -84,9 +81,7 @@ class ListenerImpl implements Listener {
async accept(): Promise<Conn> {
const builder = flatbuffers.createBuilder();
msg.Accept.startAccept(builder);
msg.Accept.addRid(builder, this.rid);
const inner = msg.Accept.endAccept(builder);
const inner = msg.Accept.createAccept(builder, this.rid);
const baseRes = await dispatch.sendAsync(builder, msg.Any.Accept, inner);
assert(baseRes != null);
assert(msg.Any.NewConn === baseRes!.innerType());
@ -140,10 +135,7 @@ export function listen(network: Network, address: string): Listener {
const builder = flatbuffers.createBuilder();
const network_ = builder.createString(network);
const address_ = builder.createString(address);
msg.Listen.startListen(builder);
msg.Listen.addNetwork(builder, network_);
msg.Listen.addAddress(builder, address_);
const inner = msg.Listen.endListen(builder);
const inner = msg.Listen.createListen(builder, network_, address_);
const baseRes = dispatch.sendSync(builder, msg.Any.Listen, inner);
assert(baseRes != null);
assert(msg.Any.ListenRes === baseRes!.innerType());
@ -183,10 +175,7 @@ export async function dial(network: Network, address: string): Promise<Conn> {
const builder = flatbuffers.createBuilder();
const network_ = builder.createString(network);
const address_ = builder.createString(address);
msg.Dial.startDial(builder);
msg.Dial.addNetwork(builder, network_);
msg.Dial.addAddress(builder, address_);
const inner = msg.Dial.endDial(builder);
const inner = msg.Dial.createDial(builder, network_, address_);
const baseRes = await dispatch.sendAsync(builder, msg.Any.Dial, inner);
assert(baseRes != null);
assert(msg.Any.NewConn === baseRes!.innerType());

View file

@ -36,8 +36,7 @@ interface ResponseModuleMetaData {
*/
export function isTTY(): { stdin: boolean; stdout: boolean; stderr: boolean } {
const builder = flatbuffers.createBuilder();
msg.IsTTY.startIsTTY(builder);
const inner = msg.IsTTY.endIsTTY(builder);
const inner = msg.IsTTY.createIsTTY(builder);
const baseRes = sendSync(builder, msg.Any.IsTTY, inner)!;
assert(msg.Any.IsTTYRes === baseRes.innerType());
const res = new msg.IsTTYRes();
@ -49,9 +48,7 @@ export function isTTY(): { stdin: boolean; stdout: boolean; stderr: boolean } {
/** Exit the Deno process with optional exit code. */
export function exit(exitCode = 0): never {
const builder = flatbuffers.createBuilder();
msg.Exit.startExit(builder);
msg.Exit.addCode(builder, exitCode);
const inner = msg.Exit.endExit(builder);
const inner = msg.Exit.createExit(builder, exitCode);
sendSync(builder, msg.Any.Exit, inner);
return util.unreachable();
}
@ -68,10 +65,11 @@ export function fetchModuleMetaData(
const builder = flatbuffers.createBuilder();
const specifier_ = builder.createString(specifier);
const referrer_ = builder.createString(referrer);
msg.FetchModuleMetaData.startFetchModuleMetaData(builder);
msg.FetchModuleMetaData.addSpecifier(builder, specifier_);
msg.FetchModuleMetaData.addReferrer(builder, referrer_);
const inner = msg.FetchModuleMetaData.endFetchModuleMetaData(builder);
const inner = msg.FetchModuleMetaData.createFetchModuleMetaData(
builder,
specifier_,
referrer_
);
const baseRes = sendSync(builder, msg.Any.FetchModuleMetaData, inner);
assert(baseRes != null);
assert(
@ -94,12 +92,9 @@ export function fetchModuleMetaData(
function setEnv(key: string, value: string): void {
const builder = flatbuffers.createBuilder();
const _key = builder.createString(key);
const _value = builder.createString(value);
msg.SetEnv.startSetEnv(builder);
msg.SetEnv.addKey(builder, _key);
msg.SetEnv.addValue(builder, _value);
const inner = msg.SetEnv.endSetEnv(builder);
const key_ = builder.createString(key);
const value_ = builder.createString(value);
const inner = msg.SetEnv.createSetEnv(builder, key_, value_);
sendSync(builder, msg.Any.SetEnv, inner);
}
@ -137,8 +132,7 @@ export function env(): { [index: string]: string } {
});
*/
const builder = flatbuffers.createBuilder();
msg.Environ.startEnviron(builder);
const inner = msg.Environ.endEnviron(builder);
const inner = msg.Environ.createEnviron(builder);
const baseRes = sendSync(builder, msg.Any.Environ, inner)!;
assert(msg.Any.EnvironRes === baseRes.innerType());
const res = new msg.EnvironRes();
@ -150,8 +144,7 @@ export function env(): { [index: string]: string } {
/** Send to the privileged side that we have setup and are ready. */
function sendStart(): msg.StartRes {
const builder = flatbuffers.createBuilder();
msg.Start.startStart(builder);
const startOffset = msg.Start.endStart(builder);
const startOffset = msg.Start.createStart(builder, 0 /* unused */);
const baseRes = sendSync(builder, msg.Any.Start, startOffset);
assert(baseRes != null);
assert(msg.Any.StartRes === baseRes!.innerType());

View file

@ -18,8 +18,7 @@ export class Performance {
*/
now(): number {
const builder = flatbuffers.createBuilder();
msg.Now.startNow(builder);
const inner = msg.Now.endNow(builder);
const inner = msg.Now.createNow(builder);
const baseRes = sendSync(builder, msg.Any.Now, inner)!;
assert(msg.Any.NowRes === baseRes.innerType());
const res = new msg.NowRes();

View file

@ -19,8 +19,7 @@ export type Permission = keyof Permissions;
function getReq(): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
const builder = flatbuffers.createBuilder();
msg.Permissions.startPermissions(builder);
const inner = msg.Permissions.endPermissions(builder);
const inner = msg.Permissions.createPermissions(builder);
return [builder, msg.Any.Permissions, inner];
}
@ -55,9 +54,10 @@ function revokeReq(
): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
const builder = flatbuffers.createBuilder();
const permission_ = builder.createString(permission);
msg.PermissionRevoke.startPermissionRevoke(builder);
msg.PermissionRevoke.addPermission(builder, permission_);
const inner = msg.PermissionRevoke.endPermissionRevoke(builder);
const inner = msg.PermissionRevoke.createPermissionRevoke(
builder,
permission_
);
return [builder, msg.Any.PermissionRevoke, inner];
}

View file

@ -34,9 +34,7 @@ export interface RunOptions {
async function runStatus(rid: number): Promise<ProcessStatus> {
const builder = flatbuffers.createBuilder();
msg.RunStatus.startRunStatus(builder);
msg.RunStatus.addRid(builder, rid);
const inner = msg.RunStatus.endRunStatus(builder);
const inner = msg.RunStatus.createRunStatus(builder, rid);
const baseRes = await dispatch.sendAsync(builder, msg.Any.RunStatus, inner);
assert(baseRes != null);
@ -154,35 +152,25 @@ export function run(opt: RunOptions): Process {
builder,
opt.args.map(a => builder.createString(a))
);
const cwdOffset = opt.cwd == null ? -1 : builder.createString(opt.cwd);
const cwdOffset = opt.cwd == null ? 0 : builder.createString(opt.cwd);
const kvOffset: flatbuffers.Offset[] = [];
if (opt.env) {
for (const [key, val] of Object.entries(opt.env)) {
const keyOffset = builder.createString(key);
const valOffset = builder.createString(String(val));
msg.KeyValue.startKeyValue(builder);
msg.KeyValue.addKey(builder, keyOffset);
msg.KeyValue.addValue(builder, valOffset);
kvOffset.push(msg.KeyValue.endKeyValue(builder));
kvOffset.push(msg.KeyValue.createKeyValue(builder, keyOffset, valOffset));
}
}
const envOffset = msg.Run.createEnvVector(builder, kvOffset);
msg.Run.startRun(builder);
msg.Run.addArgs(builder, argsOffset);
if (opt.cwd != null) {
msg.Run.addCwd(builder, cwdOffset);
}
msg.Run.addEnv(builder, envOffset);
if (opt.stdin) {
msg.Run.addStdin(builder, stdioMap(opt.stdin!));
}
if (opt.stdout) {
msg.Run.addStdout(builder, stdioMap(opt.stdout!));
}
if (opt.stderr) {
msg.Run.addStderr(builder, stdioMap(opt.stderr!));
}
const inner = msg.Run.endRun(builder);
const inner = msg.Run.createRun(
builder,
argsOffset,
cwdOffset,
envOffset,
opt.stdin ? stdioMap(opt.stdin) : stdioMap("inherit"),
opt.stdout ? stdioMap(opt.stdout) : stdioMap("inherit"),
opt.stderr ? stdioMap(opt.stderr) : stdioMap("inherit")
);
const baseRes = dispatch.sendSync(builder, msg.Any.Run, inner);
assert(baseRes != null);
assert(msg.Any.RunRes === baseRes!.innerType());

View file

@ -8,9 +8,7 @@ import { assert } from "./util";
function req(path: string): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
const builder = flatbuffers.createBuilder();
const path_ = builder.createString(path);
msg.ReadDir.startReadDir(builder);
msg.ReadDir.addPath(builder, path_);
const inner = msg.ReadDir.endReadDir(builder);
const inner = msg.ReadDir.createReadDir(builder, path_);
return [builder, msg.Any.ReadDir, inner];
}

View file

@ -7,9 +7,7 @@ import * as dispatch from "./dispatch";
function req(name: string): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
const builder = flatbuffers.createBuilder();
const name_ = builder.createString(name);
msg.Readlink.startReadlink(builder);
msg.Readlink.addName(builder, name_);
const inner = msg.Readlink.endReadlink(builder);
const inner = msg.Readlink.createReadlink(builder, name_);
return [builder, msg.Any.Readlink, inner];
}

View file

@ -13,10 +13,7 @@ function req(
): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
const builder = flatbuffers.createBuilder();
const path_ = builder.createString(path);
msg.Remove.startRemove(builder);
msg.Remove.addPath(builder, path_);
msg.Remove.addRecursive(builder, !!options.recursive);
const inner = msg.Remove.endRemove(builder);
const inner = msg.Remove.createRemove(builder, path_, !!options.recursive);
return [builder, msg.Any.Remove, inner];
}

View file

@ -10,10 +10,7 @@ function req(
const builder = flatbuffers.createBuilder();
const oldpath_ = builder.createString(oldpath);
const newpath_ = builder.createString(newpath);
msg.Rename.startRename(builder);
msg.Rename.addOldpath(builder, oldpath_);
msg.Rename.addNewpath(builder, newpath_);
const inner = msg.Rename.endRename(builder);
const inner = msg.Rename.createRename(builder, oldpath_, newpath_);
return [builder, msg.Any.Rename, inner];
}

View file

@ -30,10 +30,7 @@ const replCommands = {
function startRepl(historyFile: string): number {
const builder = flatbuffers.createBuilder();
const historyFile_ = builder.createString(historyFile);
msg.ReplStart.startReplStart(builder);
msg.ReplStart.addHistoryFile(builder, historyFile_);
const inner = msg.ReplStart.endReplStart(builder);
const inner = msg.ReplStart.createReplStart(builder, historyFile_);
const baseRes = dispatch.sendSync(builder, msg.Any.ReplStart, inner);
assert(baseRes != null);
@ -48,10 +45,7 @@ function startRepl(historyFile: string): number {
export async function readline(rid: number, prompt: string): Promise<string> {
const builder = flatbuffers.createBuilder();
const prompt_ = builder.createString(prompt);
msg.ReplReadline.startReplReadline(builder);
msg.ReplReadline.addRid(builder, rid);
msg.ReplReadline.addPrompt(builder, prompt_);
const inner = msg.ReplReadline.endReplReadline(builder);
const inner = msg.ReplReadline.createReplReadline(builder, rid, prompt_);
const baseRes = await dispatch.sendAsync(
builder,

View file

@ -13,8 +13,7 @@ export interface ResourceMap {
*/
export function resources(): ResourceMap {
const builder = flatbuffers.createBuilder();
msg.Resources.startResources(builder);
const inner = msg.Resource.endResource(builder);
const inner = msg.Resource.createResource(builder, 0, 0);
const baseRes = dispatch.sendSync(builder, msg.Any.Resources, inner);
assert(baseRes !== null);
assert(msg.Any.ResourcesRes === baseRes!.innerType());

View file

@ -11,10 +11,7 @@ function req(
): [flatbuffers.Builder, msg.Any, flatbuffers.Offset] {
const builder = flatbuffers.createBuilder();
const filename_ = builder.createString(filename);
msg.Stat.startStat(builder);
msg.Stat.addFilename(builder, filename_);
msg.Stat.addLstat(builder, lstat);
const inner = msg.Stat.endStat(builder);
const inner = msg.Stat.createStat(builder, filename_, lstat);
return [builder, msg.Any.Stat, inner];
}

View file

@ -16,10 +16,7 @@ function req(
const builder = flatbuffers.createBuilder();
const oldname_ = builder.createString(oldname);
const newname_ = builder.createString(newname);
msg.Symlink.startSymlink(builder);
msg.Symlink.addOldname(builder, oldname_);
msg.Symlink.addNewname(builder, newname_);
const inner = msg.Symlink.endSymlink(builder);
const inner = msg.Symlink.createSymlink(builder, oldname_, newname_);
return [builder, msg.Any.Symlink, inner];
}

View file

@ -39,8 +39,7 @@ function getTime(): number {
function clearGlobalTimeout(): void {
const builder = flatbuffers.createBuilder();
msg.GlobalTimerStop.startGlobalTimerStop(builder);
const inner = msg.GlobalTimerStop.endGlobalTimerStop(builder);
const inner = msg.GlobalTimerStop.createGlobalTimerStop(builder);
globalTimeoutDue = null;
let res = sendSync(builder, msg.Any.GlobalTimerStop, inner);
assert(res == null);

View file

@ -10,10 +10,7 @@ function req(
const builder = flatbuffers.createBuilder();
const name_ = builder.createString(name);
len = len && len > 0 ? Math.floor(len) : 0;
msg.Truncate.startTruncate(builder);
msg.Truncate.addName(builder, name_);
msg.Truncate.addLen(builder, len);
const inner = msg.Truncate.endTruncate(builder);
const inner = msg.Truncate.createTruncate(builder, name_, len);
return [builder, msg.Any.Truncate, inner];
}

View file

@ -23,9 +23,7 @@ export function decodeMessage(dataIntArray: Uint8Array): any {
function createWorker(specifier: string): number {
const builder = flatbuffers.createBuilder();
const specifier_ = builder.createString(specifier);
msg.CreateWorker.startCreateWorker(builder);
msg.CreateWorker.addSpecifier(builder, specifier_);
const inner = msg.CreateWorker.endCreateWorker(builder);
const inner = msg.CreateWorker.createCreateWorker(builder, specifier_);
const baseRes = sendSync(builder, msg.Any.CreateWorker, inner);
assert(baseRes != null);
assert(
@ -39,18 +37,14 @@ function createWorker(specifier: string): number {
async function hostGetWorkerClosed(rid: number): Promise<void> {
const builder = flatbuffers.createBuilder();
msg.HostGetWorkerClosed.startHostGetWorkerClosed(builder);
msg.HostGetWorkerClosed.addRid(builder, rid);
const inner = msg.HostGetWorkerClosed.endHostGetWorkerClosed(builder);
const inner = msg.HostGetWorkerClosed.createHostGetWorkerClosed(builder, rid);
await sendAsync(builder, msg.Any.HostGetWorkerClosed, inner);
}
function hostPostMessage(rid: number, data: any): void {
const dataIntArray = encodeMessage(data);
const builder = flatbuffers.createBuilder();
msg.HostPostMessage.startHostPostMessage(builder);
msg.HostPostMessage.addRid(builder, rid);
const inner = msg.HostPostMessage.endHostPostMessage(builder);
const inner = msg.HostPostMessage.createHostPostMessage(builder, rid);
const baseRes = sendSync(
builder,
msg.Any.HostPostMessage,
@ -62,9 +56,7 @@ function hostPostMessage(rid: number, data: any): void {
async function hostGetMessage(rid: number): Promise<any> {
const builder = flatbuffers.createBuilder();
msg.HostGetMessage.startHostGetMessage(builder);
msg.HostGetMessage.addRid(builder, rid);
const inner = msg.HostGetMessage.endHostGetMessage(builder);
const inner = msg.HostGetMessage.createHostGetMessage(builder, rid);
const baseRes = await sendAsync(builder, msg.Any.HostGetMessage, inner);
assert(baseRes != null);
assert(
@ -88,8 +80,7 @@ export let onmessage: (e: { data: any }) => void = (): void => {};
export function postMessage(data: any): void {
const dataIntArray = encodeMessage(data);
const builder = flatbuffers.createBuilder();
msg.WorkerPostMessage.startWorkerPostMessage(builder);
const inner = msg.WorkerPostMessage.endWorkerPostMessage(builder);
const inner = msg.WorkerPostMessage.createWorkerPostMessage(builder);
const baseRes = sendSync(
builder,
msg.Any.WorkerPostMessage,
@ -102,8 +93,10 @@ export function postMessage(data: any): void {
export async function getMessage(): Promise<any> {
log("getMessage");
const builder = flatbuffers.createBuilder();
msg.WorkerGetMessage.startWorkerGetMessage(builder);
const inner = msg.WorkerGetMessage.endWorkerGetMessage(builder);
const inner = msg.WorkerGetMessage.createWorkerGetMessage(
builder,
0 /* unused */
);
const baseRes = await sendAsync(builder, msg.Any.WorkerGetMessage, inner);
assert(baseRes != null);
assert(