-
Notifications
You must be signed in to change notification settings - Fork 1
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
Binary deserialization, CCON + TypedArray #25
Conversation
@@ -437,21 +434,11 @@ class _Deserializer { | |||
this._onDereferenced = null!; | |||
} | |||
|
|||
public deserialize (serializedData: SerializedData | CCON) { | |||
let jsonObj: SerializedData; | |||
if (serializedData instanceof CCON) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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!; |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
暴露给编辑器用
The engine part.