Skip to content

Commit

Permalink
Remove dispatch.ts and move assignCmdId to util.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Aug 2, 2018
1 parent df82085 commit 421358e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 39 deletions.
1 change: 0 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ run_node("bundle") {
"js/assets.ts",
"js/console.ts",
"js/deno.d.ts",
"js/dispatch.ts",
"js/globals.ts",
"js/lib.deno.d.ts",
"js/main.ts",
Expand Down
29 changes: 0 additions & 29 deletions js/dispatch.ts

This file was deleted.

10 changes: 1 addition & 9 deletions js/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,9 @@
/// <reference path="deno.d.ts" />
import { flatbuffers } from "flatbuffers";
import { deno as fbs } from "gen/msg_generated";
import { assert, log } from "./util";
import { assert, log, assignCmdId } from "./util";
import * as runtime from "./runtime";

let cmdIdCounter = 0;
function assignCmdId(): number {
// TODO(piscisaureus) Safely re-use so they don't overflow.
const cmdId = ++cmdIdCounter;
assert(cmdId < 2 ** 32, "cmdId overflow");
return cmdId;
}

function startMsg(cmdId: number): Uint8Array {
const builder = new flatbuffers.Builder();
fbs.Start.startStart(builder);
Expand Down
8 changes: 8 additions & 0 deletions js/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ export function assert(cond: boolean, msg = "assert") {
}
}

let cmdIdCounter = 0;
export function assignCmdId(): number {
// TODO(piscisaureus) Safely re-use so they don't overflow.
const cmdId = ++cmdIdCounter;
assert(cmdId < 2 ** 32, "cmdId overflow");
return cmdId;
}

export function typedArrayToArrayBuffer(ta: TypedArray): ArrayBuffer {
const ab = ta.buffer.slice(ta.byteOffset, ta.byteOffset + ta.byteLength);
return ab as ArrayBuffer;
Expand Down

0 comments on commit 421358e

Please sign in to comment.