ayush00git opened a new pull request, #3192:
URL: https://github.com/apache/fory/pull/3192
## Why?
While the uint annotation types were integrated into the code generation
system in the PR #3181 , there were two remaining issues:
1. **No annotated struct support and test coverage for annotated structs**:
The annotation system was integrated but not tested with actual struct fields
using the annotations
2. **Null check error in key_annotation_analyzer**: When fields didn't have
`@ForyKey` annotations, the code generator crashed with a null check error at
`key_annotation_analyzer.dart`
## What does this PR do?
### 1. Created Test Entity with Annotated Uint Fields
Added `uint_annotated_struct.dart` demonstrating all uint annotation
variants:
```dart
@ForyClass(promiseAcyclic: true)
class UIntAnnotatedStruct with _$UIntAnnotatedStructFory {
@Uint8Type()
final int age;
@Uint16Type()
final int port;
@Uint32Type()
final int count;
@Uint32Type(encoding: UintEncoding.varint)
final int varCount;
@Uint64Type()
final int id;
@Uint64Type(encoding: UintEncoding.varint)
final int varId;
@Uint64Type(encoding: UintEncoding.tagged)
final int taggedId;
}
```
### 2. Added Comprehensive Test Suite
Created `uint_annotated_struct_test.dart` with test coverage for:
* Basic serialization/deserialization with annotated fields
* Max value handling for uint8 (255), uint16 (65535), uint32 (4294967295)
* Min value handling (0 for all types)
* Varint encoding efficiency verification
**Run tests:**
```bash
cd dart/packages/fory-test
dart run build_runner build --delete-conflicting-outputs
dart test test/struct_test/uint_annotated_struct_test.dart
```
### 3. Fixed Null Check Error in Key Annotation Analyzer
**Problem:** The `key_annotation_analyzer.dart` was attempting to access
annotation fields even when no `@ForyKey` annotation was present, causing a
null check operator error.
**Solution:** Added additional check to ensure we only access annotation
fields when a `@ForyKey` annotation is actually found:
Before
```dart
if (anno != null){
```
After
```dart
if (getMeta && anno != null){
```
This ensures that:
- We only try to read annotation fields when `getMeta` is true (meaning we
found a `@ForyKey` annotation)
- Fields without `@ForyKey` annotations correctly default to
`includeFromFory: true` and `includeToFory: true`
- Code generation no longer crashes on structs with unannotated fields
## Related issues
Completes the uint annotation testing and fixes a critical bug that
prevented code generation from working with fields lacking `@ForyKey`
annotations.
## Does this PR introduce any user-facing change?
* [ ] Does this PR introduce any public API change?
* No new APIs - only adds test coverage and fixes a bug
* [ ] Does this PR introduce any binary protocol compatibility change?
* No changes to binary encoding format
* Bug fix only affects code generation, not runtime serialization
## Benchmark
N/A - This PR adds test coverage and fixes a code generation bug. No runtime
performance impact.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]