diff web/lib/avro.ts @ 2395:ef3cde3e81e8

switch collector output from json to avro (still over WS)
author drewp@bigasterisk.com
date Thu, 16 May 2024 15:03:50 -0700
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/web/lib/avro.ts	Thu May 16 15:03:50 2024 -0700
@@ -0,0 +1,12 @@
+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;
+  }
+}