Skip to content

Commit

Permalink
Fix bigint serder
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Oct 3, 2023
1 parent 0ee677d commit a449573
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/utils/networked-behavior-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ import type { CursorBuffer, EntityID } from "./networking-types";

const migrations = new Map<number, Migration>();

type MapValueT = number | string | Map<string, MapValueT>;
type MapValueT = number | string | bigint | Map<string, MapValueT>;

function serMap(key: string, value: MapValueT) {
if (value instanceof Map) {
return {
dataType: "Map",
value: Array.from(value.entries())
};
} else if (typeof value === "bigint") {
return {
dataType: "bigint",
value: value.toString()
};
} else {
return value;
}
Expand All @@ -23,6 +28,8 @@ function desMap(key: any, value: any) {
if (typeof value === "object" && value !== null) {
if (value.dataType === "Map") {
return new Map(value.value);
} else if (value.dataType === "bigint") {
return BigInt(value.value);
}
}
return value;
Expand Down

0 comments on commit a449573

Please sign in to comment.