2019-01-21 14:03:30 -05:00
|
|
|
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
2018-10-30 15:58:55 -04:00
|
|
|
import { assert } from "./util";
|
2019-08-21 20:42:48 -04:00
|
|
|
import { sendSync, msg, flatbuffers } from "./dispatch_flatbuffers";
|
2018-10-30 15:58:55 -04:00
|
|
|
|
2019-03-09 12:30:38 -05:00
|
|
|
export interface ResourceMap {
|
|
|
|
[rid: number]: string;
|
|
|
|
}
|
2018-11-08 23:07:48 -05:00
|
|
|
|
|
|
|
/** Returns a map of open _file like_ resource ids along with their string
|
|
|
|
* representation.
|
|
|
|
*/
|
|
|
|
export function resources(): ResourceMap {
|
2018-10-30 15:58:55 -04:00
|
|
|
const builder = flatbuffers.createBuilder();
|
2019-04-07 20:51:43 -04:00
|
|
|
const inner = msg.Resource.createResource(builder, 0, 0);
|
2019-08-21 20:42:48 -04:00
|
|
|
const baseRes = sendSync(builder, msg.Any.Resources, inner);
|
2018-10-30 15:58:55 -04:00
|
|
|
assert(baseRes !== null);
|
|
|
|
assert(msg.Any.ResourcesRes === baseRes!.innerType());
|
|
|
|
const res = new msg.ResourcesRes();
|
|
|
|
assert(baseRes!.inner(res) !== null);
|
|
|
|
|
2019-03-09 12:30:38 -05:00
|
|
|
const resources: ResourceMap = {};
|
2018-10-30 15:58:55 -04:00
|
|
|
|
|
|
|
for (let i = 0; i < res.resourcesLength(); i++) {
|
|
|
|
const item = res.resources(i)!;
|
|
|
|
resources[item.rid()!] = item.repr()!;
|
|
|
|
}
|
|
|
|
|
|
|
|
return resources;
|
|
|
|
}
|