Skip to content

Conversation

@chaokunyang
Copy link
Collaborator

@chaokunyang chaokunyang commented Dec 9, 2025

Why?

C++ natively supports unsigned integer types (uint8_t, uint16_t, uint32_t, uint64_t) which are widely used in systems programming. This PR adds serialization support for these types in native mode (xlang=false), following the same pattern as the Rust implementation.

What does this PR do?

  1. Adds unsigned TypeIds to cpp/fory/type/type.h:

    • U8 = 64, U16 = 65, U32 = 66, U64 = 67 for basic unsigned types
    • U16_ARRAY = 73, U32_ARRAY = 74, U64_ARRAY = 75 for unsigned arrays
  2. Implements unsigned type serializers in cpp/fory/serialization/unsigned_serializer.h:

    • Basic types: uint8_t, uint16_t, uint32_t, uint64_t
    • Fixed-size arrays: std::array<uintN_t, N>
    • Vectors: std::vector<uintN_t>
  3. Updates struct serializer to recognize unsigned types as primitive types, enabling efficient serialization of structs with unsigned fields.

  4. Adds comprehensive tests covering:

    • Primitive unsigned type roundtrips
    • Unsigned vector and array roundtrips
    • Structs with unsigned fields
    • Boundary value tests
    • TypeId verification

Note: Unsigned types are only supported in native mode (xlang=false). This follows the xlang specification which does not include unsigned types for cross-language compatibility.

Related issues

#2906

Does this PR introduce any user-facing change?

Yes - users can now serialize/deserialize unsigned integer types in C++ when using native mode.

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

Benchmark

N/A - This is a new feature addition, not a performance optimization.

@chaokunyang chaokunyang merged commit da5da4b into apache:main Dec 9, 2025
50 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.

2 participants