ayush00git opened a new pull request, #3181:
URL: https://github.com/apache/fory/pull/3181
## Why?
While unsigned integer type annotations (`@Uint8Type`, `@Uint16Type`,
`@Uint32Type`, `@Uint64Type`) were added in PR #3144, they were not integrated
into the code generation system. This meant:
* The annotation definitions existed but were not recognized by the code
generator
* No support for annotation-based type specification like `@Uint8Type() int
age` in struct fields
* Users couldn't use the protobuf/flatbuffer-style ergonomic API that was
intended
* No way to specify encoding variants (fixed vs varint) for uint32/uint64
via annotations during code generation
## What does this PR do?
### 1. Created Uint Annotation Analyzer
Added `uint_annotation_analyzer.dart` to detect and parse uint type
annotations during code generation:
```dart
class UintAnnotationAnalyzer {
UintAnnotationResult analyze(
List<ElementAnnotation> metadata,
LocationMark locationMark,
) {
// Detects @Uint8Type, @Uint16Type, @Uint32Type, @Uint64Type
// Extracts encoding options (fixed, varint, tagged)
// Returns appropriate ObjType
}
}
```
**Supported annotations:**
* `@Uint8Type()` → `ObjType.UINT8`
* `@Uint16Type()` → `ObjType.UINT16`
* `@Uint32Type()` → `ObjType.UINT32`
* `@Uint32Type(encoding: UintEncoding.varint)` → `ObjType.VAR_UINT32`
* `@Uint64Type()` → `ObjType.UINT64`
* `@Uint64Type(encoding: UintEncoding.varint)` → `ObjType.VAR_UINT64`
* `@Uint64Type(encoding: UintEncoding.tagged)` → `ObjType.TAGGED_UINT64`
### 2. Extended Type Identifier System
Updated `analysis_type_identifier.dart` to recognize uint annotation types:
```dart
static final List<Type3StringKey> _keys = [
// ... existing annotations
Type3StringKey('Uint8Type', 'package',
'fory/src/annotation/uint_types.dart'),
Type3StringKey('Uint16Type', 'package',
'fory/src/annotation/uint_types.dart'),
Type3StringKey('Uint32Type', 'package',
'fory/src/annotation/uint_types.dart'),
Type3StringKey('Uint64Type', 'package',
'fory/src/annotation/uint_types.dart'),
];
```
### 3. Integrated Annotation-Based Type Override
Modified `type_analyzer_impl.dart` to support annotation-based type override:
```dart
TypeSpecGen getTypeImmutableAndTagWithOverride(
TypeDecision typeDecision,
LocationMark locationMark,
ObjType objTypeOverride,
) {
// Uses annotation-specified ObjType instead of default type resolution
}
```
### 4. Updated Field Analyzer
Modified `field_analyzer_impl.dart` to check for uint annotations:
```dart
// Check for uint annotations
final uintAnnotationResult = Analyzer.uintAnnotationAnalyzer.analyze(
element.metadata,
locationMark,
);
if (uintAnnotationResult.hasAnnotation) {
// Use annotation-based type override
fieldType = Analyzer.typeAnalyzer.getTypeImmutableAndTagWithOverride(
typeDecision, locationMark, uintAnnotationResult.objType!,
);
}
```
## Related issues
Completes the unsigned integer annotation types support initiated in PR
#3144 by integrating the annotations into the code generation system.
## Does this PR introduce any user-facing change?
* [x] Does this PR introduce any public API change?
* **Dart**: Users can now use `@Uint8Type()`, `@Uint16Type()`,
`@Uint32Type()`, `@Uint64Type()` annotations on native `int` fields in
`@ForyClass` structs
* Enables encoding variant specification via `encoding` parameter for
uint32/uint64
* Provides more ergonomic API: `@Uint8Type() int age` instead of `UInt8
age`
* [ ] Does this PR introduce any binary protocol compatibility change?
* No changes to binary encoding format
* Uses existing ObjType mappings and serializers
* Type IDs remain the same: UINT8 (40), UINT16 (41), UINT32 (42),
VAR_UINT32 (43), UINT64 (44), VAR_UINT64 (45), TAGGED_UINT64 (46)
## Benchmark
N/A - This PR only adds annotation processing during code generation
(build-time). 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]