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

Support binary data in asset pack, support typed array in compiled serialization #15904

Merged
merged 7 commits into from
Sep 8, 2023

Conversation

shrinktofit
Copy link
Contributor

@shrinktofit shrinktofit commented Aug 9, 2023

Re: #

Changelog

  • Support serializing typed array in compiled serialization.

    1. The input(output) of compiled deserialization(serialization) might have a binary storage attached.

    2. With 1, compiled serialization can now process typed array properties:

      • If there is no binary storage, the typed array is serialized in place, as plain JSON number array with type info.

      • Otherwise, the typed array is serialized into the binary storage.

  • Support packing binary data in asset pack.

    The pack content format has been updated reference binary data:

    • A pack might reference to one binary storage attachment. If it does, each "pack section" may contain a reference to a span of the
      binary storage. Each section, together with its reference binary storage, can then be sent to deserialize.
---
title: Before
---
stateDiagram-v2
  standalone: Standalone\n <b>JSON </b>
  section1: <b>JSON </b>
  section2: <b>JSON </b>
  deserialize: Deserialize

  state Pack {
    [*] --> section1: Unpack section 1
    [*] --> section2: Unpack section 2
  }

  standalone --> deserialize
  section1 --> deserialize
  section2 --> deserialize
Loading
---
title: After
---
stateDiagram-v2
  standalone_json: Standalone\n<b>JSON </b>
  standalone_ccon: Standalone CCON
  section1: <b>JSON </b>
  section2: <b>JSON </b> ➕ 🔢
  deserialize: Deserialize

  state standalone_ccon {
    json_plus_bin: <b>JSON </b> ➕ 🔢
    [*] --> json_plus_bin
    json_plus_bin --> [*]
  }

  state Pack {
    [*] --> section1: Unpack section 1
    [*] --> section2: Unpack section 2
  }

  standalone_json --> deserialize
  standalone_ccon --> deserialize
  section1 --> deserialize
  section2 --> deserialize
Loading

Continuous Integration

This pull request:

  • needs automatic test cases check.

    Manual trigger with @cocos-robot run test cases afterward.

  • does not change any runtime related code or build configuration

    If any reviewer thinks the CI checks are needed, please uncheck this option, then close and reopen the issue.


Compatibility Check

This pull request:

  • changes public API, and have ensured backward compatibility with deprecated features.
  • affects platform compatibility, e.g. system version, browser version, platform sdk version, platform toolchain, language version, hardware compatibility etc.
  • affects file structure of the build package or build configuration which requires user project upgrade.
  • introduces breaking changes, please list all changes, affected features and the scope of violation.

cocos/serialization/deserialize.ts Outdated Show resolved Hide resolved
cocos/serialization/deserialize.ts Outdated Show resolved Hide resolved
cocos/serialization/deserialize.ts Outdated Show resolved Hide resolved
cocos/serialization/deserialize.ts Outdated Show resolved Hide resolved
cocos/serialization/deserialize.ts Show resolved Hide resolved
cocos/serialization/deserialize.ts Outdated Show resolved Hide resolved
cocos/serialization/deserialize.ts Show resolved Hide resolved
cocos/serialization/deserialize.ts Outdated Show resolved Hide resolved
cocos/serialization/compiled/typed-array.ts Show resolved Hide resolved
cocos/serialization/compiled/typed-array.ts Outdated Show resolved Hide resolved
@shrinktofit shrinktofit changed the title Support binary data in asset pack, support typed array in compiled serialization (DON'T MERGE)Support binary data in asset pack, support typed array in compiled serialization Aug 10, 2023

const [byteOffset, byteLength] = binaryStorageSpan;

// Note: we do copy here.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@holycanvas @jareguo Notable change.

Copy link
Contributor

Choose a reason for hiding this comment

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

up to you guys

@shrinktofit shrinktofit changed the base branch from v3.8.1 to develop August 18, 2023 03:04
@github-actions
Copy link

github-actions bot commented Aug 31, 2023

Interface Check Report

! WARNING this pull request has changed these public interfaces:

@@ -28139,9 +28139,9 @@
      * @param details - Additional loading result.
      * @param options Deserialization Options.
      * @return The original object.
      */
-    export function deserialize(data: __private._cocos_serialization_deserialize__IDeserializeInput | string | any, details?: Details, options?: __private._cocos_serialization_deserialize__IOptions & __private._cocos_serialization_deserialize_dynamic__DeserializeDynamicOptions): unknown;
+    export function deserialize(data: __private._cocos_serialization_deserialize__IDeserializeInput | string | CCON | any, details?: Details, options?: __private._cocos_serialization_deserialize__IOptions & __private._cocos_serialization_deserialize_dynamic__DeserializeDynamicOptions): unknown;
     export namespace deserialize {
         export namespace Internal {
             export type SharedString_ = __private._cocos_serialization_deserialize__SharedString;
             export type Empty_ = __private._cocos_serialization_deserialize__Empty;
@@ -28156,14 +28156,15 @@
                 Class = 4,
                 ValueTypeCreated = 5,
                 AssetRefByInnerObj = 6,
                 TRS = 7,
-                ValueType = 8,
-                Array_Class = 9,
-                CustomizedClass = 10,
-                Dict = 11,
-                Array = 12,
-                ARRAY_LENGTH = 13
+                TypedArray = 8,
+                ValueType = 9,
+                Array_Class = 10,
+                CustomizedClass = 11,
+                Dict = 12,
+                Array = 13,
+                ARRAY_LENGTH = 14
             }
             export type DataTypes_ = __private._cocos_serialization_deserialize__DataTypes;
             export type AnyData_ = __private._cocos_serialization_deserialize__AnyData;
             export type OtherObjectData_ = __private._cocos_serialization_deserialize__OtherObjectData;
@@ -28176,8 +28177,9 @@
             export type ICustomObjectData_ = __private._cocos_serialization_deserialize__ICustomObjectData;
             export type ITRSData_ = __private._cocos_serialization_deserialize__ITRSData;
             export type IDictData_ = __private._cocos_serialization_deserialize__IDictData;
             export type IArrayData_ = __private._cocos_serialization_deserialize__IArrayData;
+            export type ITypedArrayData_ = TypedArrayData;
             export const enum Refs_ {
                 EACH_RECORD_LENGTH = 3,
                 OWNER_OFFSET = 0,
                 KEY_OFFSET = 1,
@@ -28196,9 +28198,11 @@
                 Refs = 7,
                 DependObjs = 8,
                 DependKeys = 9,
                 DependUuidIndices = 10,
-                ARRAY_LENGTH = 11
+                ARRAY_LENGTH = 11,
+                RUNTIME_BEGIN = 11,
+                BinaryStorage_runtime = 11
             }
             export type IFileData_ = __private._cocos_serialization_deserialize__IFileData;
             export type IPackedFileData_ = __private._cocos_serialization_deserialize__IPackedFileData;
         }
@@ -63710,8 +63714,9 @@
             [deserialize.Internal.DataTypeID_.Class]: _cocos_serialization_deserialize__IClassObjectData;
             [deserialize.Internal.DataTypeID_.ValueTypeCreated]: _cocos_serialization_deserialize__IValueTypeData;
             [deserialize.Internal.DataTypeID_.AssetRefByInnerObj]: number;
             [deserialize.Internal.DataTypeID_.TRS]: _cocos_serialization_deserialize__ITRSData;
+            [deserialize.Internal.DataTypeID_.TypedArray]: TypedArrayData;
             [deserialize.Internal.DataTypeID_.ValueType]: _cocos_serialization_deserialize__IValueTypeData;
             [deserialize.Internal.DataTypeID_.Array_Class]: _cocos_serialization_deserialize__DataTypes[deserialize.Internal.DataTypeID_.Class][];
             [deserialize.Internal.DataTypeID_.CustomizedClass]: _cocos_serialization_deserialize__ICustomObjectData;
             [deserialize.Internal.DataTypeID_.Dict]: _cocos_serialization_deserialize__IDictData;
@@ -63782,18 +63787,24 @@
             customEnv: any;
         }
         export interface _cocos_serialization_deserialize__DeserializeContext extends _cocos_serialization_deserialize__ICustomHandler {
             _version?: number;
+            _attachedBinary?: Uint8Array;
+            _attachedBinaryDataViewCache?: DataView;
         }
         export type _cocos_serialization_deserialize__IRuntimeFileDataMap = Omit<_cocos_serialization_deserialize__IFileDataMap, deserialize.Internal.File_.Version> & {
             [deserialize.Internal.File_.Context]: _cocos_serialization_deserialize__FileInfo & _cocos_serialization_deserialize__DeserializeContext;
+            /**
+             * The binary storage attached to this document.
+             */
+            [deserialize.Internal.File_.BinaryStorage_runtime]: Uint8Array | undefined;
         };
         /**
          * At runtime, we intruded the original file data and injected some helpers.
          */
         export type _cocos_serialization_deserialize__IRuntimeFileData = _cocos_serialization_deserialize_type_utilities__MapEnum<{
             [x in keyof _cocos_serialization_deserialize__IRuntimeFileDataMap as `${x}`]: _cocos_serialization_deserialize__IRuntimeFileDataMap[x];
-        }, 11>;
+        }, 12>;
         export type _cocos_serialization_deserialize__IDeserializeInput = _cocos_serialization_deserialize__IFileData | _cocos_serialization_deserialize__IRuntimeFileData;
         export type _cocos_serialization_deserialize__ClassFinder = deserialize.ClassFinder;
         export interface _cocos_serialization_deserialize__IOptions extends Partial<_cocos_serialization_deserialize__ICustomHandler> {
             classFinder?: _cocos_serialization_deserialize__ClassFinder;
@@ -63826,9 +63837,13 @@
         export type _cocos_serialization_deserialize_type_utilities__SkipFirst<T extends readonly any[], N extends number> = _cocos_serialization_deserialize_type_utilities__TupleSplit<T, N>[1];
         export type _cocos_serialization_deserialize_type_utilities__TupleSlice<T extends readonly any[], S extends number, E extends number = T["length"]> = _cocos_serialization_deserialize_type_utilities__SkipFirst<_cocos_serialization_deserialize_type_utilities__TakeFirst<T, E>, S>;
         export type _cocos_serialization_deserialize__ISharedData = _cocos_serialization_deserialize_type_utilities__TupleSlice<_cocos_serialization_deserialize__IFileData, 1, 5>;
         export type _cocos_serialization_deserialize__IPackedFileSection = [
-            ...document: _cocos_serialization_deserialize_type_utilities__TupleSlice<_cocos_serialization_deserialize__IFileData, 5>
+            ...document: _cocos_serialization_deserialize_type_utilities__TupleSlice<_cocos_serialization_deserialize__IFileData, 5>,
+            binaryStorage: [
+                byteOffset: number,
+                byteLength: number
+            ] | undefined
         ];
         export type _cocos_serialization_deserialize__IPackedFileData = [
             version: number,
             ...shared: _cocos_serialization_deserialize__ISharedData,
@@ -64748,9 +64763,9 @@
              *      packManager.unpackJson(['a', 'b'], file, null, (err, data) => log(err));
              * });
              *
              */
-            unpackJson(pack: string[], json: any, options: Record<string, any>, onComplete: ((err: Error | null, data?: Record<string, any> | null) => void)): void;
+            unpackJson(pack: readonly string[], json: any, options: Record<string, any>, onComplete: ((err: Error | null, data?: Record<string, any> | null) => void)): void;
             init(): void;
             /**
              * @en
              * Register custom handler if you want to change default behavior or extend packManager to unpack other format pack
@@ -70023,9 +70038,9 @@
     }
     import { exoticAnimationTag, ExoticAnimation, additiveSettingsTag, AnimationClipAdditiveSettings } from "cc/editor/exotic-animation";
     import { EmbeddedPlayer, embeddedPlayerCountTag, getEmbeddedPlayersTag, addEmbeddedPlayerTag, removeEmbeddedPlayerTag, clearEmbeddedPlayersTag } from "cc/editor/embedded-player";
     import { AnimationMask, __private as ___private } from "cc/editor/new-gen-anim";
-    import { CCON } from "cc/editor/serialization";
+    import { CCON, TypedArrayData } from "cc/editor/serialization";
     export { Canvas as CanvasComponent, UIRenderer as RenderComponent, UIRenderer as UIRenderable, UIRenderer as Renderable2D, UITransform as UITransformComponent, Mask as MaskComponent, RichText as RichTextComponent, Sprite as SpriteComponent, UIMeshRenderer as UIModelComponent, LabelOutline as LabelOutlineComponent, Graphics as GraphicsComponent, UIStaticBatch as UIStaticBatchComponent, UIOpacity as UIOpacityComponent, Label as LabelComponent, MeshRenderer as ModelComponent, DirectionalLight as DirectionalLightComponent, Light as LightComponent, SphereLight as SphereLightComponent, SpotLight as SpotLightComponent, SkinnedMeshRenderer as SkinningModelComponent, SkinnedMeshBatchRenderer as BatchedSkinningModelComponent, SkinnedMeshUnit as SkinningModelUnit, Animation as AnimationComponent, AudioSource as AudioSourceComponent, Node as BaseNode, Camera as CameraComponent, ModelRenderer as RenderableComponent, Billboard as BillboardComponent, Line as LineComponent, ParticleSystem as ParticleSystemComponent, SkeletalAnimation as SkeletalAnimationComponent, Button as ButtonComponent, EditBox as EditBoxComponent, Layout as LayoutComponent, ProgressBar as ProgressBarComponent, ScrollBar as ScrollBarComponent, ScrollView as ScrollViewComponent, Slider as SliderComponent, Toggle as ToggleComponent, ToggleContainer as ToggleContainerComponent, Widget as WidgetComponent, PageView as PageViewComponent, PageViewIndicator as PageViewIndicatorComponent, SafeArea as SafeAreaComponent, UICoordinateTracker as UICoordinateTrackerComponent, BlockInputEvents as BlockInputEventsComponent } from "cc";
     import { Details as _Details } from "cc";
     export {};
 }

@shrinktofit shrinktofit force-pushed the CCONPack branch 3 times, most recently from 3fe77f9 to b251331 Compare September 7, 2023 09:43
@shrinktofit shrinktofit changed the title (DON'T MERGE)Support binary data in asset pack, support typed array in compiled serialization Support binary data in asset pack, support typed array in compiled serialization Sep 7, 2023
@VisualSJ VisualSJ merged commit 4381c62 into cocos:develop Sep 8, 2023
8 of 9 checks passed
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.

4 participants