view web/lib/avro.ts @ 2405:69ca2b2fc133

overcomplicated attempt at persisting the pane layout in the rdf graph this was hard because we have to somehow wait for the graph to load before config'ing the panes
author drewp@bigasterisk.com
date Fri, 17 May 2024 16:58:26 -0700
parents ef3cde3e81e8
children
line wrap: on
line source

import * as avrojs from "avro-js";
export namespace avro {
  export async function loadType(typeName: string): Promise<avrojs.types.Type> {
    const schemaSource = await (await fetch(`/avro/${typeName}.avsc`)).json();
    return await avrojs.parse(schemaSource);
  }
  
  export async function parseBlob(type: avrojs.types.Type, b: Blob): Promise<avrojs.types.Record> {
    const jsMsg = type.fromBuffer(Buffer.from(await b.arrayBuffer()));
    return jsMsg;
  }
}