mirror of
https://github.com/cocos/cocos-engine.git
synced 2026-09-07 16:20:16 +08:00
* 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
49 lines
992 B
TypeScript
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,
|
|
);
|
|
}); |