Files
cocos-engine/tests/core/serialization/shared/cases/custom-serialize-classical.test.ts
Leslie Leigh (李的序) 705c977fc9 Binary serialization (#8946)
* Binary serialization

* Update snapshots

* Update

* rename option ccon -> useCCON

* Missing script

* encodeCCONJson: chunks -> chunkURLs

* Update

* (de)serializeSymbol -> (de)serializeTag;

* CustomizedSerializable -> CustomSerializable

* _deserializePrimitiveObject -> _fillPlainObject

* Unify CCClass CCClassConstructor

* encodeCCONJson -> parseCCONJson

* Custom serializable

* Move (de)serializeSuper(This) from context into global

* property -> read(write)Property; (de)serializeThis(Super) -> (read)writeThis(Super)

* CI and lint

* Mock cc env
2021-07-15 10:21:25 +08:00

49 lines
992 B
TypeScript

import { PORTS_BOTH_DYNAMIC_COMPILED, testEachPort } from "../port";
import { ccclassAutoNamed, runTest } from "../utils";
@ccclassAutoNamed(__filename)
class Foo {
constructor (public a: number, public b: number) {
}
_deserialize (serialized: ReturnType<Foo['_serialize']>) {
const { 1: a, 2: b } = /(\d+)\+(\d+)/.exec(serialized.str);
this.a = parseInt(a);
this.b = parseInt(b);
}
_serialize() {
return {
str: `${this.a}+${this.b}`,
};
}
}
@ccclassAutoNamed(__filename)
class Bar {
constructor (public a: number) {
}
_deserialize (serialized: ReturnType<Bar['_serialize']>) {
this.a = serialized - 1;
}
_serialize() {
return this.a + 1;
}
}
const value = {
returnObject: new Foo(6, 8),
returnNonObject: new Bar(6),
};
testEachPort(PORTS_BOTH_DYNAMIC_COMPILED, async (port) => {
await runTest(
__filename,
port,
value,
);
});