~starkingdoms/starkingdoms

ref: b7552ba591095ee7d312539348fb9568d0550398 starkingdoms/starkingdoms-client/src/save.ts -rw-r--r-- 645 bytes
b7552ba5 — ghostly_zsh errors output whole lines 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { decode, encode } from "@msgpack/msgpack";

function base64ToBytes(base64: string) {
  const binString = atob(base64);
  // @ts-ignore
  return Uint8Array.from(binString, (m) => m.codePointAt(0));
}

function bytesToBase64(bytes: any) {
  const binString = String.fromCodePoint(...bytes);
  return btoa(binString);
}

export function unpack_save(data: string): any {
  console.log(decode(base64ToBytes(data)));
  // @ts-ignore
  return decode(decode(base64ToBytes(data))[0]);
}

export function __pack_save_for_api(data: any): string {
  console.log([encode(data), []]);
  return bytesToBase64(encode([Array.from(encode(data)), []]));
}