~starkingdoms/starkingdoms

ref: fb32ad5db3289f5757f2c17960cf64eb2196c4ed starkingdoms/starkingdoms-client/src/save.ts -rw-r--r-- 740 bytes
fb32ad5dcore functioning api 1 year, 8 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
24
25
26
27
28
29
30
31
32
33
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)),
              []
          ],
      )
  );
}