Skip to content

feat(scene): stable-schema binary scene artifact #716

Description

@JeanPhilippeKernel

Summary

Implement the validated stable-schema binary scene artifact used by the runtime
cook path. It is a portable cooked representation of the authoring document,
not a raw-memory dump and not a zero-parse promise.

Scope

Non-goals

Dependencies

Acceptance criteria

  • Valid cooked data loads on a fresh process with preserved durable identity and
    component semantics.
  • Truncated, oversized, malformed, unsupported-version, and incompatible data
    fails safely without partial publication.
  • Binary assets remain independent of process-local type allocation and native
    ABI/layout differences.

References

ZEngine/docs/future-plan/scene-serialization.md sections 8, 9, and 11.

Implementation API contract

The binary header is a logical wire layout, not a packed C++ structure. The
implementation writes and reads every integer in the declared byte order;
sizeof, alignment, and a memcpy of BinarySceneHeader are never part of
the format contract.

namespace ZEngine::ECS
{
    class SceneComponentSchemaRegistry;
    class SceneCompatibilityService;
    class SceneValue;
    struct SceneDocument;
    struct SceneDiagnostics;
    struct SceneSerializationLimits;

    namespace SceneBinaryFormat
    {
        inline constexpr uint32_t Magic             = ZESCENE_MAGIC;
        inline constexpr uint32_t CurrentVersion    = 1;
        inline constexpr uint32_t LittleEndianMark  = 0x01020304;
    }

    // A component codec receives a reader bounded to its one payload table
    // entry, so it cannot consume the next component's data.
    class SceneBinaryReader;
    class SceneBinaryWriter;

    class BinarySceneCodec
    {
    public:
        void Initialize(const SceneComponentSchemaRegistry* schemas,
                        const SceneCompatibilityService* compatibility);

        Core::VFS::VFSResult<void> Encode(const SceneDocument& document,
                                           Core::Memory::ArenaAllocator* output_arena,
                                           Core::Containers::Array<uint8_t>* out_bytes,
                                           SceneDiagnostics* diagnostics) const;
        Core::VFS::VFSResult<void> Decode(Core::Containers::ArrayView<const uint8_t> bytes,
                                           const SceneSerializationLimits& limits,
                                           Core::Memory::ArenaAllocator* document_arena,
                                           SceneDocument* out_document,
                                           SceneDiagnostics* diagnostics) const;
    };
}

Encode initializes out_bytes from output_arena and emits the current
document version, feature flags, stable schema keys/versions, bounded tables,
and an integrity value. Decode validates the complete header and every count,
offset, length, version, key, and checksum before allocating an unbounded
collection or returning a document. It routes supported version changes through
#830 and reports all content failures through SceneDiagnostics.

The codec owns bounded format conversion only. It neither opens files nor
publishes a live scene; #718 owns artifact I/O/asset validation and #829 owns
runtime construction. Unknown components may be represented in a decoded
document for editor compatibility, but a shipping cook is rejected according to
the policy in #830.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1Critical path — blocks other workenhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions