1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-13 16:26:08 -05:00
denoland-deno/js/resources.ts
2018-10-30 12:58:55 -07:00

25 lines
874 B
TypeScript

// Copyright 2018 the Deno authors. All rights reserved. MIT license.
import * as msg from "gen/msg_generated";
import * as flatbuffers from "./flatbuffers";
import { assert } from "./util";
import * as dispatch from "./dispatch";
export function resources(): { [key: number]: string } {
const builder = flatbuffers.createBuilder();
msg.Resources.startResources(builder);
const inner = msg.Resource.endResource(builder);
const baseRes = dispatch.sendSync(builder, msg.Any.Resources, inner);
assert(baseRes !== null);
assert(msg.Any.ResourcesRes === baseRes!.innerType());
const res = new msg.ResourcesRes();
assert(baseRes!.inner(res) !== null);
const resources: { [key: number]: string } = {};
for (let i = 0; i < res.resourcesLength(); i++) {
const item = res.resources(i)!;
resources[item.rid()!] = item.repr()!;
}
return resources;
}