修复buffer再浏览器环境不兼容的问题
This commit is contained in:
51
package-lock.json
generated
51
package-lock.json
generated
@@ -3559,6 +3559,15 @@
|
|||||||
"url": "https://github.com/sponsors/isaacs"
|
"url": "https://github.com/sponsors/isaacs"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/@msgpack/msgpack": {
|
||||||
|
"version": "3.1.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@msgpack/msgpack/-/msgpack-3.1.2.tgz",
|
||||||
|
"integrity": "sha512-JEW4DEtBzfe8HvUYecLU9e6+XJnKDlUAIve8FvPzF3Kzs6Xo/KuZkZJsDH0wJXl/qEZbeeE7edxDNY3kMs39hQ==",
|
||||||
|
"license": "ISC",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 18"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/@napi-rs/wasm-runtime": {
|
"node_modules/@napi-rs/wasm-runtime": {
|
||||||
"version": "0.2.4",
|
"version": "0.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-0.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-0.2.4.tgz",
|
||||||
@@ -5220,16 +5229,6 @@
|
|||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@types/msgpack-lite": {
|
|
||||||
"version": "0.1.11",
|
|
||||||
"resolved": "https://registry.npmjs.org/@types/msgpack-lite/-/msgpack-lite-0.1.11.tgz",
|
|
||||||
"integrity": "sha512-cdCZS/gw+jIN22I4SUZUFf1ZZfVv5JM1//Br/MuZcI373sxiy3eSSoiyLu0oz+BPatTbGGGBO5jrcvd0siCdTQ==",
|
|
||||||
"dev": true,
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"@types/node": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/@types/multer": {
|
"node_modules/@types/multer": {
|
||||||
"version": "1.4.13",
|
"version": "1.4.13",
|
||||||
"resolved": "https://registry.npmjs.org/@types/multer/-/multer-1.4.13.tgz",
|
"resolved": "https://registry.npmjs.org/@types/multer/-/multer-1.4.13.tgz",
|
||||||
@@ -7715,12 +7714,6 @@
|
|||||||
"node": ">=0.10.0"
|
"node": ">=0.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/event-lite": {
|
|
||||||
"version": "0.1.3",
|
|
||||||
"resolved": "https://registry.npmjs.org/event-lite/-/event-lite-0.1.3.tgz",
|
|
||||||
"integrity": "sha512-8qz9nOz5VeD2z96elrEKD2U433+L3DWdUdDkOINLGOJvx1GsMBbMn0aCeu28y8/e85A6mCigBiFlYMnTBEGlSw==",
|
|
||||||
"license": "MIT"
|
|
||||||
},
|
|
||||||
"node_modules/eventemitter3": {
|
"node_modules/eventemitter3": {
|
||||||
"version": "4.0.7",
|
"version": "4.0.7",
|
||||||
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz",
|
"resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz",
|
||||||
@@ -8672,6 +8665,7 @@
|
|||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
|
||||||
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==",
|
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==",
|
||||||
|
"dev": true,
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
"type": "github",
|
"type": "github",
|
||||||
@@ -8861,12 +8855,6 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/int64-buffer": {
|
|
||||||
"version": "0.1.10",
|
|
||||||
"resolved": "https://registry.npmjs.org/int64-buffer/-/int64-buffer-0.1.10.tgz",
|
|
||||||
"integrity": "sha512-v7cSY1J8ydZ0GyjUHqF+1bshJ6cnEVLo9EnjB8p+4HDRPZc9N5jjmvUV7NvEsqQOKyH0pmIBFWXVQbiS0+OBbA==",
|
|
||||||
"license": "MIT"
|
|
||||||
},
|
|
||||||
"node_modules/ip-address": {
|
"node_modules/ip-address": {
|
||||||
"version": "9.0.5",
|
"version": "9.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/ip-address/-/ip-address-9.0.5.tgz",
|
"resolved": "https://registry.npmjs.org/ip-address/-/ip-address-9.0.5.tgz",
|
||||||
@@ -9138,6 +9126,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||||
"integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==",
|
"integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==",
|
||||||
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/isexe": {
|
"node_modules/isexe": {
|
||||||
@@ -11543,21 +11532,6 @@
|
|||||||
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
"integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/msgpack-lite": {
|
|
||||||
"version": "0.1.26",
|
|
||||||
"resolved": "https://registry.npmjs.org/msgpack-lite/-/msgpack-lite-0.1.26.tgz",
|
|
||||||
"integrity": "sha512-SZ2IxeqZ1oRFGo0xFGbvBJWMp3yLIY9rlIJyxy8CGrwZn1f0ZK4r6jV/AM1r0FZMDUkWkglOk/eeKIL9g77Nxw==",
|
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
|
||||||
"event-lite": "^0.1.1",
|
|
||||||
"ieee754": "^1.1.8",
|
|
||||||
"int64-buffer": "^0.1.9",
|
|
||||||
"isarray": "^1.0.0"
|
|
||||||
},
|
|
||||||
"bin": {
|
|
||||||
"msgpack": "bin/msgpack"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/multimatch": {
|
"node_modules/multimatch": {
|
||||||
"version": "5.0.0",
|
"version": "5.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/multimatch/-/multimatch-5.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/multimatch/-/multimatch-5.0.0.tgz",
|
||||||
@@ -15559,7 +15533,7 @@
|
|||||||
"version": "2.2.1",
|
"version": "2.2.1",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"msgpack-lite": "^0.1.26",
|
"@msgpack/msgpack": "^3.0.0",
|
||||||
"tslib": "^2.8.1"
|
"tslib": "^2.8.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
@@ -15572,7 +15546,6 @@
|
|||||||
"@rollup/plugin-node-resolve": "^16.0.1",
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
||||||
"@rollup/plugin-terser": "^0.4.4",
|
"@rollup/plugin-terser": "^0.4.4",
|
||||||
"@types/jest": "^29.5.14",
|
"@types/jest": "^29.5.14",
|
||||||
"@types/msgpack-lite": "^0.1.11",
|
|
||||||
"@types/node": "^20.19.17",
|
"@types/node": "^20.19.17",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"jest-environment-jsdom": "^29.7.0",
|
"jest-environment-jsdom": "^29.7.0",
|
||||||
|
|||||||
@@ -58,7 +58,6 @@
|
|||||||
"@rollup/plugin-node-resolve": "^16.0.1",
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
||||||
"@rollup/plugin-terser": "^0.4.4",
|
"@rollup/plugin-terser": "^0.4.4",
|
||||||
"@types/jest": "^29.5.14",
|
"@types/jest": "^29.5.14",
|
||||||
"@types/msgpack-lite": "^0.1.11",
|
|
||||||
"@types/node": "^20.19.17",
|
"@types/node": "^20.19.17",
|
||||||
"jest": "^29.7.0",
|
"jest": "^29.7.0",
|
||||||
"jest-environment-jsdom": "^29.7.0",
|
"jest-environment-jsdom": "^29.7.0",
|
||||||
@@ -78,7 +77,7 @@
|
|||||||
"directory": "packages/core"
|
"directory": "packages/core"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"msgpack-lite": "^0.1.26",
|
"@msgpack/msgpack": "^3.0.0",
|
||||||
"tslib": "^2.8.1"
|
"tslib": "^2.8.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -742,10 +742,10 @@ export class Scene implements IScene {
|
|||||||
/**
|
/**
|
||||||
* 序列化场景
|
* 序列化场景
|
||||||
*
|
*
|
||||||
* 将场景及其所有实体、组件序列化为JSON字符串或二进制Buffer
|
* 将场景及其所有实体、组件序列化为JSON字符串或二进制Uint8Array
|
||||||
*
|
*
|
||||||
* @param options 序列化选项
|
* @param options 序列化选项
|
||||||
* @returns 序列化后的数据(JSON字符串或二进制Buffer)
|
* @returns 序列化后的数据(JSON字符串或二进制Uint8Array)
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```typescript
|
* ```typescript
|
||||||
@@ -761,7 +761,7 @@ export class Scene implements IScene {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
public serialize(options?: SceneSerializationOptions): string | Buffer {
|
public serialize(options?: SceneSerializationOptions): string | Uint8Array {
|
||||||
return SceneSerializer.serialize(this, options);
|
return SceneSerializer.serialize(this, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -770,7 +770,7 @@ export class Scene implements IScene {
|
|||||||
*
|
*
|
||||||
* 从序列化数据恢复场景状态
|
* 从序列化数据恢复场景状态
|
||||||
*
|
*
|
||||||
* @param saveData 序列化的数据(JSON字符串或二进制Buffer)
|
* @param saveData 序列化的数据(JSON字符串或二进制Uint8Array)
|
||||||
* @param options 反序列化选项
|
* @param options 反序列化选项
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
@@ -786,7 +786,7 @@ export class Scene implements IScene {
|
|||||||
* });
|
* });
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
public deserialize(saveData: string | Buffer, options?: SceneDeserializationOptions): void {
|
public deserialize(saveData: string | Uint8Array, options?: SceneDeserializationOptions): void {
|
||||||
SceneSerializer.deserialize(this, saveData, options);
|
SceneSerializer.deserialize(this, saveData, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -858,7 +858,7 @@ export class Scene implements IScene {
|
|||||||
/**
|
/**
|
||||||
* 应用增量变更到场景
|
* 应用增量变更到场景
|
||||||
*
|
*
|
||||||
* @param incremental 增量快照数据(IncrementalSnapshot对象、JSON字符串或二进制Buffer)
|
* @param incremental 增量快照数据(IncrementalSnapshot对象、JSON字符串或二进制Uint8Array)
|
||||||
* @param componentRegistry 组件类型注册表(可选,默认使用全局注册表)
|
* @param componentRegistry 组件类型注册表(可选,默认使用全局注册表)
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
@@ -870,21 +870,20 @@ export class Scene implements IScene {
|
|||||||
* const jsonData = IncrementalSerializer.serializeIncremental(snapshot, { format: 'json' });
|
* const jsonData = IncrementalSerializer.serializeIncremental(snapshot, { format: 'json' });
|
||||||
* scene.applyIncremental(jsonData);
|
* scene.applyIncremental(jsonData);
|
||||||
*
|
*
|
||||||
* // 从二进制Buffer应用
|
* // 从二进制Uint8Array应用
|
||||||
* const binaryData = IncrementalSerializer.serializeIncremental(snapshot, { format: 'binary' });
|
* const binaryData = IncrementalSerializer.serializeIncremental(snapshot, { format: 'binary' });
|
||||||
* scene.applyIncremental(binaryData);
|
* scene.applyIncremental(binaryData);
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
public applyIncremental(
|
public applyIncremental(
|
||||||
incremental: IncrementalSnapshot | string | Buffer,
|
incremental: IncrementalSnapshot | string | Uint8Array,
|
||||||
componentRegistry?: Map<string, any>
|
componentRegistry?: Map<string, any>
|
||||||
): void {
|
): void {
|
||||||
const isSerializedData = typeof incremental === 'string' ||
|
const isSerializedData = typeof incremental === 'string' ||
|
||||||
(typeof Buffer !== 'undefined' && Buffer.isBuffer(incremental)) ||
|
|
||||||
incremental instanceof Uint8Array;
|
incremental instanceof Uint8Array;
|
||||||
|
|
||||||
const snapshot = isSerializedData
|
const snapshot = isSerializedData
|
||||||
? IncrementalSerializer.deserializeIncremental(incremental as string | Buffer)
|
? IncrementalSerializer.deserializeIncremental(incremental as string | Uint8Array)
|
||||||
: incremental as IncrementalSnapshot;
|
: incremental as IncrementalSnapshot;
|
||||||
|
|
||||||
const registry = componentRegistry || ComponentRegistry.getAllComponentNames() as Map<string, any>;
|
const registry = componentRegistry || ComponentRegistry.getAllComponentNames() as Map<string, any>;
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { Component } from '../Component';
|
|||||||
import { ComponentSerializer, SerializedComponent } from './ComponentSerializer';
|
import { ComponentSerializer, SerializedComponent } from './ComponentSerializer';
|
||||||
import { SerializedEntity } from './EntitySerializer';
|
import { SerializedEntity } from './EntitySerializer';
|
||||||
import { ComponentType } from '../Core/ComponentStorage';
|
import { ComponentType } from '../Core/ComponentStorage';
|
||||||
import * as msgpack from 'msgpack-lite';
|
import { encode, decode } from '@msgpack/msgpack';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 变更操作类型
|
* 变更操作类型
|
||||||
@@ -609,7 +609,7 @@ export class IncrementalSerializer {
|
|||||||
*
|
*
|
||||||
* @param incremental 增量快照
|
* @param incremental 增量快照
|
||||||
* @param options 序列化选项
|
* @param options 序列化选项
|
||||||
* @returns 序列化后的数据(JSON字符串或二进制Buffer)
|
* @returns 序列化后的数据(JSON字符串或二进制Uint8Array)
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* ```typescript
|
* ```typescript
|
||||||
@@ -631,7 +631,7 @@ export class IncrementalSerializer {
|
|||||||
public static serializeIncremental(
|
public static serializeIncremental(
|
||||||
incremental: IncrementalSnapshot,
|
incremental: IncrementalSnapshot,
|
||||||
options?: { format?: IncrementalSerializationFormat; pretty?: boolean }
|
options?: { format?: IncrementalSerializationFormat; pretty?: boolean }
|
||||||
): string | Buffer {
|
): string | Uint8Array {
|
||||||
const opts = {
|
const opts = {
|
||||||
format: 'json' as IncrementalSerializationFormat,
|
format: 'json' as IncrementalSerializationFormat,
|
||||||
pretty: false,
|
pretty: false,
|
||||||
@@ -639,7 +639,7 @@ export class IncrementalSerializer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (opts.format === 'binary') {
|
if (opts.format === 'binary') {
|
||||||
return msgpack.encode(incremental);
|
return encode(incremental);
|
||||||
} else {
|
} else {
|
||||||
return opts.pretty
|
return opts.pretty
|
||||||
? JSON.stringify(incremental, null, 2)
|
? JSON.stringify(incremental, null, 2)
|
||||||
@@ -650,7 +650,7 @@ export class IncrementalSerializer {
|
|||||||
/**
|
/**
|
||||||
* 反序列化增量快照
|
* 反序列化增量快照
|
||||||
*
|
*
|
||||||
* @param data 序列化的数据(JSON字符串或二进制Buffer)
|
* @param data 序列化的数据(JSON字符串或二进制Uint8Array)
|
||||||
* @returns 增量快照
|
* @returns 增量快照
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
@@ -662,13 +662,13 @@ export class IncrementalSerializer {
|
|||||||
* const snapshot = IncrementalSerializer.deserializeIncremental(buffer);
|
* const snapshot = IncrementalSerializer.deserializeIncremental(buffer);
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
public static deserializeIncremental(data: string | Buffer): IncrementalSnapshot {
|
public static deserializeIncremental(data: string | Uint8Array): IncrementalSnapshot {
|
||||||
if (typeof data === 'string') {
|
if (typeof data === 'string') {
|
||||||
// JSON格式
|
// JSON格式
|
||||||
return JSON.parse(data);
|
return JSON.parse(data);
|
||||||
} else {
|
} else {
|
||||||
// 二进制格式(MessagePack)
|
// 二进制格式(MessagePack)
|
||||||
return msgpack.decode(data);
|
return decode(data) as IncrementalSnapshot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import { ComponentType, ComponentRegistry } from '../Core/ComponentStorage';
|
|||||||
import { EntitySerializer, SerializedEntity } from './EntitySerializer';
|
import { EntitySerializer, SerializedEntity } from './EntitySerializer';
|
||||||
import { getComponentTypeName } from '../Decorators';
|
import { getComponentTypeName } from '../Decorators';
|
||||||
import { getSerializationMetadata } from './SerializationDecorators';
|
import { getSerializationMetadata } from './SerializationDecorators';
|
||||||
import * as msgpack from 'msgpack-lite';
|
import { encode, decode } from '@msgpack/msgpack';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 场景序列化格式
|
* 场景序列化格式
|
||||||
@@ -154,9 +154,9 @@ export class SceneSerializer {
|
|||||||
*
|
*
|
||||||
* @param scene 要序列化的场景
|
* @param scene 要序列化的场景
|
||||||
* @param options 序列化选项
|
* @param options 序列化选项
|
||||||
* @returns 序列化后的数据(JSON字符串或二进制Buffer)
|
* @returns 序列化后的数据(JSON字符串或二进制Uint8Array)
|
||||||
*/
|
*/
|
||||||
public static serialize(scene: IScene, options?: SceneSerializationOptions): string | Buffer {
|
public static serialize(scene: IScene, options?: SceneSerializationOptions): string | Uint8Array {
|
||||||
const opts: SceneSerializationOptions = {
|
const opts: SceneSerializationOptions = {
|
||||||
systems: false,
|
systems: false,
|
||||||
format: 'json',
|
format: 'json',
|
||||||
@@ -207,7 +207,7 @@ export class SceneSerializer {
|
|||||||
: JSON.stringify(serializedScene);
|
: JSON.stringify(serializedScene);
|
||||||
} else {
|
} else {
|
||||||
// 二进制格式(使用 MessagePack)
|
// 二进制格式(使用 MessagePack)
|
||||||
return msgpack.encode(serializedScene);
|
return encode(serializedScene);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,12 +215,12 @@ export class SceneSerializer {
|
|||||||
* 反序列化场景
|
* 反序列化场景
|
||||||
*
|
*
|
||||||
* @param scene 目标场景
|
* @param scene 目标场景
|
||||||
* @param saveData 序列化的数据(JSON字符串或二进制Buffer)
|
* @param saveData 序列化的数据(JSON字符串或二进制Uint8Array)
|
||||||
* @param options 反序列化选项
|
* @param options 反序列化选项
|
||||||
*/
|
*/
|
||||||
public static deserialize(
|
public static deserialize(
|
||||||
scene: IScene,
|
scene: IScene,
|
||||||
saveData: string | Buffer,
|
saveData: string | Uint8Array,
|
||||||
options?: SceneDeserializationOptions
|
options?: SceneDeserializationOptions
|
||||||
): void {
|
): void {
|
||||||
const opts: SceneDeserializationOptions = {
|
const opts: SceneDeserializationOptions = {
|
||||||
@@ -237,7 +237,7 @@ export class SceneSerializer {
|
|||||||
serializedScene = JSON.parse(saveData);
|
serializedScene = JSON.parse(saveData);
|
||||||
} else {
|
} else {
|
||||||
// 二进制格式(MessagePack)
|
// 二进制格式(MessagePack)
|
||||||
serializedScene = msgpack.decode(saveData);
|
serializedScene = decode(saveData) as SerializedScene;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`Failed to parse save data: ${error}`);
|
throw new Error(`Failed to parse save data: ${error}`);
|
||||||
|
|||||||
@@ -464,7 +464,7 @@ describe('Incremental Serialization System', () => {
|
|||||||
const incremental = scene.serializeIncremental();
|
const incremental = scene.serializeIncremental();
|
||||||
const binary = IncrementalSerializer.serializeIncremental(incremental, { format: 'binary' });
|
const binary = IncrementalSerializer.serializeIncremental(incremental, { format: 'binary' });
|
||||||
|
|
||||||
expect(Buffer.isBuffer(binary)).toBe(true);
|
expect(binary instanceof Uint8Array).toBe(true);
|
||||||
|
|
||||||
const deserialized = IncrementalSerializer.deserializeIncremental(binary);
|
const deserialized = IncrementalSerializer.deserializeIncremental(binary);
|
||||||
expect(deserialized.version).toBe(incremental.version);
|
expect(deserialized.version).toBe(incremental.version);
|
||||||
|
|||||||
@@ -557,14 +557,14 @@ describe('ECS Serialization System', () => {
|
|||||||
// 二进制序列化
|
// 二进制序列化
|
||||||
const binaryData = scene1.serialize({ format: 'binary' });
|
const binaryData = scene1.serialize({ format: 'binary' });
|
||||||
|
|
||||||
// 验证是Buffer类型
|
// 验证是Uint8Array类型
|
||||||
expect(Buffer.isBuffer(binaryData)).toBe(true);
|
expect(binaryData instanceof Uint8Array).toBe(true);
|
||||||
|
|
||||||
// JSON序列化对比
|
// JSON序列化对比
|
||||||
const jsonData = scene1.serialize({ format: 'json', pretty: false });
|
const jsonData = scene1.serialize({ format: 'json', pretty: false });
|
||||||
|
|
||||||
// 二进制应该更小
|
// 二进制应该更小
|
||||||
const binarySize = (binaryData as Buffer).length;
|
const binarySize = (binaryData as Uint8Array).length;
|
||||||
const jsonSize = (jsonData as string).length;
|
const jsonSize = (jsonData as string).length;
|
||||||
console.log(`Binary size: ${binarySize} bytes, JSON size: ${jsonSize} bytes`);
|
console.log(`Binary size: ${binarySize} bytes, JSON size: ${jsonSize} bytes`);
|
||||||
expect(binarySize).toBeLessThan(jsonSize);
|
expect(binarySize).toBeLessThan(jsonSize);
|
||||||
|
|||||||
Reference in New Issue
Block a user