Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binary deserialization, CCON + TypedArray #25

Closed

Conversation

jareguo
Copy link

@jareguo jareguo commented Jul 14, 2021

The engine part.

@@ -437,21 +434,11 @@ class _Deserializer {
this._onDereferenced = null!;
}

public deserialize (serializedData: SerializedData | CCON) {
let jsonObj: SerializedData;
if (serializedData instanceof CCON) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这部分统一在 deserializer 入口中处理了

@@ -262,29 +260,33 @@ export declare namespace deserialize.Internal {
}

interface DataTypes {
[DataTypeID.SimpleType]: number | string | boolean | null | object;
[DataTypeID.SimpleType]: number | string | boolean | null | unknown;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

用 unknown 表示 json 对象,不知道正确不

DataTypeID.Dict
DataTypeID.Dict |
DataTypeID.TypedArray |
DataTypeID.TypedArrayRef
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

引擎侧默认支持反序列化复用 TypedArray,编辑器侧感觉不太需要实现

function parseTypedArray (data: IFileData, owner: any, key: string, value: ITypedArrayData) {
const Type = TypedArrays[value[value.length - 1]];
value.length -= 1;
owner[key] = Type.from(value);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

所有魔法发生的地方


function parseTypedArrayRef (data: IFileData, owner: any, key: string, value: ITypedArrayRefData) {
const Type = TypedArrays[value[TYPEDARRAY_REF_TYPE_INDEX]];
const chunk = (data[File.Context] as IContext)._mainBinChunk!;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

获取当前反序列化的上下文,类似 dynamic deserializer 的 this

@@ -1113,12 +1145,13 @@ export function hasNativeDep (data: IFileData): boolean {
}

function getDependUuidList (json: IFileData): string[] {
const sharedUuids = json[File.SharedUuids];
return json[File.DependUuidIndices].map((index) => sharedUuids[index]);
assertIsTrue(hasNativeDep(json));
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

加了个 assert,减轻代码阅读负担,希望不会影响性能

@@ -1158,6 +1191,7 @@ if (EDITOR || TEST) {
};
deserialize._BuiltinValueTypes = BuiltinValueTypes;
deserialize._serializeBuiltinValueTypes = serializeBuiltinValueTypes;
deserialize._TypedArrays = TypedArrays;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

暴露给编辑器用

@jareguo jareguo changed the title Binary deserialization Binary deserialization, CCON + TypedArray Jul 14, 2021
@shrinktofit shrinktofit deleted the branch shrinktofit:BinarySerialization July 15, 2021 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants