Skip to content

Conversation

@theharsh999
Copy link

@theharsh999 theharsh999 commented Dec 30, 2025

Why?

JavaScript xlang schema-based struct serialization currently treats all fields as nullable and always writes a per-field null flag.
This introduces unnecessary overhead when a field is known to be non-nullable by schema design.

What does this PR do?

  • Adds schema-based per-field nullable support for JS xlang struct serialization.
  • Preserves backward compatibility by treating fields as nullable by default.
  • When nullable: false is explicitly specified:
    • Skips writing the per-field null flag.
    • Throws a clear runtime error if the field value is null or undefined (includes field name).
  • Extends StructTypeInfo field schema typing to allow nullable?: boolean.
  • Adds a minimal unit test verifying:
    • Non-nullable fields throw on null.
    • Fields without nullable keep existing behavior.

Related issues

Does this PR introduce any user-facing change?

Yes.
This PR introduces an opt-in schema-level configuration (nullable: false) for JS xlang serialization.
Existing schemas are unaffected unless nullable: false is explicitly set.

  • Does this PR introduce any public API change?
  • Does this PR introduce any binary protocol compatibility change?

Benchmark

This change is opt-in and only affects schema-based fields explicitly marked as nullable: false.
No performance regression is expected for existing schemas.

@theharsh999 theharsh999 changed the title JS xlang: add schema-based per-field nullable support (backward compatible) Dec 30, 2025
@theharsh999
Copy link
Author

Hi @chaokunyang
All CI checks are green now.
Whenever you have time, I’d appreciate a quick review. Thanks!

@chaokunyang
Copy link
Collaborator

chaokunyang commented Jan 1, 2026

@theharsh999 Could you add some tests for this? you can take #3104 as reference

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

Labels

None yet

2 participants