diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2018-10-30 20:58:55 +0100 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2018-10-30 12:58:55 -0700 |
commit | 946acbc559fab050d13b5f2f66088254ec96f83d (patch) | |
tree | 93cd12b60e8d91a482b550949c857bbf4a83cbd0 /js/resources.ts | |
parent | 8b39d2c99ef41736bb1d5b74ccda2f3aa6223e84 (diff) |
Add resources op (#1119)
Diffstat (limited to 'js/resources.ts')
-rw-r--r-- | js/resources.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/js/resources.ts b/js/resources.ts new file mode 100644 index 000000000..a28270fca --- /dev/null +++ b/js/resources.ts @@ -0,0 +1,25 @@ +// 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; +} |