(wasm) Treat arbitrary byte data as Uint8Array, instead of base64url marshalling.

This commit is contained in:
Brandon Vandegrift
2023-09-20 00:46:45 -04:00
parent a7b073cddb
commit 80afa19678
17 changed files with 452 additions and 116 deletions

View File

@@ -1,13 +1,23 @@
// TextEncoder/TextDecoder are used to solve for "The Unicode Problem" https://stackoverflow.com/a/30106551
export const textDecoder = new TextDecoder();
export const textEncoder = new TextEncoder();
export function marshall(data: string) {
const byteString = bytesToString(new TextEncoder().encode(data));
// TextEncoder/TextDecoder are used to solve for "The Unicode Problem" https://stackoverflow.com/a/30106551
export function marshallString(data: string) {
return marshallBytes(textEncoder.encode(data));
}
export function unmarshallString(b64: string) {
return textDecoder.decode(unmarshallBytes(b64));
}
export function marshallBytes(data: Uint8Array) {
const byteString = bytesToString(data);
return base64UrlEncode(byteString);
}
export function unmarshall(b64: string) {
export function unmarshallBytes(b64: string) {
const byteString = base64UrlDecode(b64);
return new TextDecoder().decode(stringToBytes(byteString));
return stringToBytes(byteString);
}
function base64UrlEncode(data: string) {