Skip to content
Permalink
Browse files

use flatbuffer create functions to add fields (denoland#2046)

  • Loading branch information...
jorsi authored and ry committed Apr 8, 2019
1 parent 86aee7f commit 3452a10840ef47bb5546969ebe776289c7b095f1
Showing with 98 additions and 197 deletions.
  1. +1 −4 js/chmod.ts
  2. +1 −4 js/copy_file.ts
  3. +1 −3 js/dir.ts
  4. +10 −6 js/dispatch.ts
  5. +14 −19 js/fetch.ts
  6. +5 −18 js/files.ts
  7. +1 −3 js/format_error.ts
  8. +9 −14 js/make_temp_dir.ts
  9. +1 −2 js/metrics.ts
  10. +1 −5 js/mkdir.ts
  11. +4 −15 js/net.ts
  12. +12 −19 js/os.ts
  13. +1 −2 js/performance.ts
  14. +5 −5 js/permissions.ts
  15. +12 −24 js/process.ts
  16. +1 −3 js/read_dir.ts
  17. +1 −3 js/read_link.ts
  18. +1 −4 js/remove.ts
  19. +1 −4 js/rename.ts
  20. +2 −8 js/repl.ts
  21. +1 −2 js/resources.ts
  22. +1 −4 js/stat.ts
  23. +1 −4 js/symlink.ts
  24. +1 −2 js/timers.ts
  25. +1 −4 js/truncate.ts
  26. +9 −16 js/workers.ts
@@ -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];
}

@@ -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];
}

@@ -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);
}
@@ -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);
@@ -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
);

@@ -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);
}

@@ -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());
@@ -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];
}

@@ -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];
}

@@ -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];
}

@@ -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());
@@ -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());
@@ -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();
@@ -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];
}

Oops, something went wrong.

0 comments on commit 3452a10

Please sign in to comment.
You can’t perform that action at this time.