The GitHub Actions job "Fory CI" on fory.git/main has succeeded.
Run started by GitHub user chaokunyang (triggered by chaokunyang).

Head commit for run:
4b53e0ac15970315a21692d730509e5a92ef1d1a / Ayush Kumar 
<[email protected]>
feat(dart): add struct serializer support for unsigned integer types (#3155)

## Why?

While unsigned integer types (UInt8, UInt16, UInt32) were added to Fory
in PR #3144 with their primitive serializers and wrapper classes, they
were not integrated into the framework's type system for struct
serialization. This meant users could serialize individual UInt values
but could not use them as fields in structs annotated with `@ForyClass`.

For example:

* A struct with `UInt16 port` field would fail during code generation
* Cross-language data structures using unsigned integers couldn't be
represented in Dart structs
* The type system didn't recognize UInt types as valid field types for
serialization

## What does this PR do?

### 1. Registers Unsigned Integer Types in DartTypeEnum

Added UInt8, UInt16, and UInt32 to the type enumeration in
`dart_type.dart`:

```dart
UINT8(UInt8, true, 'UInt8', 'package', 'fory/src/datatype/uint8.dart', 
ObjType.UINT8, true, 'dart:core@UInt8'),
UINT16(UInt16, true, 'UInt16', 'package', 'fory/src/datatype/uint16.dart', 
ObjType.UINT16, true, 'dart:core@UInt16'),
UINT32(UInt32, true, 'UInt32', 'package', 'fory/src/datatype/uint32.dart', 
ObjType.UINT32, true, 'dart:core@UInt32'),
```

This enables the code generator to recognize unsigned types during
static analysis and generate proper serialization metadata.

### 2. Integrates Serializers into SerializerPool

Registered the serializers in the framework initialization:

```dart
type2Ser[UInt8]!.ser = UInt8Serializer.cache.getSerializer(conf);
type2Ser[UInt16]!.ser = UInt16Serializer.cache.getSerializer(conf);
type2Ser[UInt32]!.ser = UInt32Serializer.cache.getSerializer(conf);
```

This ensures serializers are available when the framework starts and can
be used for struct field serialization.

### 3. Adds Comprehensive Test Suite for Struct Serialization

Created test entity and test cases:

```dart
@ForyClass(promiseAcyclic: true)
class UIntStruct with _$UIntStructFory {
  final UInt8 age;
  final UInt16 port;
  final UInt32 count;

  const UIntStruct(this.age, this.port, this.count);
}
```

**Test coverage:**
* Normal value serialization/deserialization
* Maximum boundary values (255, 65535, 4294967295)
* Minimum boundary values (0, 0, 0)
* Round-trip serialization integrity

**Run tests:**

```bash
cd packages/fory-test
dart test test/struct_test/uint_struct_test.dart
```

## Related issues

Completes the unsigned integer types support initiated in PR #3144.

## Does this PR introduce any user-facing change?

* [x] Does this PR introduce any public API change?
* **Dart**: UInt8, UInt16, UInt32 can now be used as fields in
`@ForyClass` structs
  * The wrapper classes themselves were already public (added in #3144)
* This PR enables their use in code generation and struct serialization
contexts

* [ ] Does this PR introduce any binary protocol compatibility change?
  * No changes to binary encoding format
* Uses existing serializers from #3144 (UInt8: 1 byte, UInt16: 2 bytes
LE, UInt32: 4 bytes LE)
  * Type IDs remain the same: UINT8 (40), UINT16 (41), UINT32 (42)

## Benchmark

N/A, The serializers themselves were already implemented in #3144. This
PR only adds registration overhead during framework initialization,
which is negligible..

Report URL: https://github.com/apache/fory/actions/runs/21135518382

With regards,
GitHub Actions via GitBox


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to