add client receiving base
This commit is contained in:
13
client/tools.ts
Normal file
13
client/tools.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Convert big-endian u32 to native JavaScript number.
|
||||
*/
|
||||
export function uint_bytes_to_num(value: Uint8Array): number {
|
||||
if (value.length != 4) { throw new Error("can't convert non 4-byte integer"); }
|
||||
const data_view = new DataView(value.buffer);
|
||||
return data_view.getUint32(0, false);
|
||||
}
|
||||
|
||||
export function utf8_decode(value: Uint8Array): string {
|
||||
const decoder = new TextDecoder("utf-8");
|
||||
return decoder.decode(value);
|
||||
}
|
Reference in New Issue
Block a user