cocos-engine icon indicating copy to clipboard operation
cocos-engine copied to clipboard

How do we recongnize CCONB files

Open shrinktofit opened this issue 1 year ago • 2 comments

Currently we deserialize certain sorts of asset into CCON binary format then store them as .cconb files. Some users claim that their target platform/CDN doesn't allow such extension of file to be loaded or gzip-ed. We have several ways to solve this problem.

The widely-used binary format has extension .bin. But if we deploy CCON binary in .bin, we need to distinguish CCON binary from plain binary from user domain. In the following I posted some distinguishing method.

Treat all .bin as CCON binary

We could treat all .bin as CCON binary file. For user's plain binaries, we import them as BufferAsset which then would be serialized into CCON binary file.

Pros

  • Easy to implement.

  • Could distinguish accurately.

Cons

  • Users have to use asset loading methods to load their binaries.

    ❓ I don't think this causes actual problems indeed.

Constuct a CCON table

We could contruct a CCON table to indicates what .bin are CCON or plain binary.

Pros

  • Easy to implement.

  • Could distinguish accurately.

Cons

  • Extra memory/storage required.

Guess file format from file content

CCON binary data has leading bytes(the ASCII of CCON chars). We could guess the format according to this.

Pros

  • Easy to implement.

Cons

  • Could not distinguish accurately. There're potential problems.

Let CCON file format be well-known

Platform limits base on they don't know such application-specific file format and extension. We could drive platforms to recongnize this format. Specifically, we should:

  • Register CCON media type in https://www.iana.org/assignments/media-types/media-types.xhtml

  • Contact our target platform vendors and request a by-pass policy on CCON files.

  • If the application is targetting C/S and the server side is configurable by users. Teach users to configure the media type.

Pros

  • We need change nothing.

  • Extend Cocos Creator ecosystem.

Cons

  • A slow remedy cannot meet an urgency.

Related:

  • https://forum.cocos.org/t/topic/97736/41

shrinktofit avatar Jul 28 '22 06:07 shrinktofit

麻烦把工作量评一下级,在 2 进制序列化方案订下来之前,我倾向于选择工作量最小的方案,改得越多,之后给后面的负担越大

holycanvas avatar Jul 28 '22 06:07 holycanvas

@holycanvas Please use English

pandamicro avatar Jul 30 '22 14:07 pandamicro

@dumganhar is refactoring the whole serialization system, and this problem will be solved after that

holycanvas avatar Nov 10 '22 07:11 holycanvas

Another solution: Compress the .cconb file in building stage, decompress it in runtime. Maybe LZ4 is a choice.

Pros

  • Don't need to rename .cconb to .bin
  • Don't need to ask the target platform or CDN to recognize .cconb extension

Cons

  • Impact runtime performance, especially LZ4 decompress in JS may be slow. Need to do some performance tests.

dumganhar avatar Feb 03 '23 05:02 dumganhar