Option to generate pointers to fields on struct pointers
- Dominant language
- Dart
- Stars
- 275
- Forks
- 144
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 47
Description
After we address https://github.com/dart-lang/sdk/issues/41237.
We can add an option to generate extension methods for `Pointer`s to fields of `Pointer`:
If we settle on an API like this for getting the offsets:
```dart
class MyStruct extends Struct {
@Int32()
external int foo;
@Int64()
external int bar;
@OffsetOf(#foo)
external const int offsetOfFoo;
@OffsetOf(#bar)
external const int offsetOfBar;
}
```
Then we could generate extension methods such as:
```dart
extension MyStructFields on Pointer {
Pointer foo => Pointer.fromAddress(address + MyStruct.offsetOfFoo);
Pointer bar => Pointer.fromAddress(address + MyStruct.offsetOfBar);
}
```
Which would be handy for cases like https://github.com/dart-lang/ffi/issues/117.
Contributor guide
Assessment
This issue has not been assessed yet.