Skip to content

Commit

Permalink
Use new dart to generate ffi bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
nirinchev committed Aug 21, 2024
1 parent 2e8b1fd commit 425376a
Show file tree
Hide file tree
Showing 7 changed files with 1,062 additions and 496 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension BoolEx on bool {
}

class LastError {
final int code;
final realm_errno code;
final String? message;
final Object? userError;

Expand Down Expand Up @@ -64,6 +64,6 @@ Never _raiseLastError([String? errorMessage]) {
extension RealmErrorEx on realm_error {
LastError toDart() {
final message = this.message.cast<Utf8>().toRealmDartString();
return LastError(error, message, user_code_error.toUserCodeError());
return LastError(realm_errno.fromValue(error), message, user_code_error.toUserCodeError());
}
}
10 changes: 6 additions & 4 deletions packages/realm_dart/lib/src/handles/native/from_native.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'dart:async';
import 'dart:ffi';
import 'dart:io';
import 'dart:typed_data';
Expand All @@ -20,8 +19,11 @@ const int _nanosecondsPerMicrosecond = 1000;
extension RealmValueEx on realm_value_t {
Object? toPrimitiveValue() => toDartValue(realm: null, getList: null, getMap: null);

realm_value_type get typeEnum => realm_value_type.fromValue(type);
void set typeEnum(realm_value_type value) => type = value.value;

Object? toDartValue({required Realm? realm, required Pointer<realm_list_t> Function()? getList, required Pointer<realm_dictionary_t> Function()? getMap}) {
switch (type) {
switch (typeEnum) {
case realm_value_type.RLM_TYPE_NULL:
return null;
case realm_value_type.RLM_TYPE_INT:
Expand Down Expand Up @@ -149,8 +151,8 @@ extension RealmPropertyInfoEx on realm_property_info {
SchemaProperty toSchemaProperty() {
final linkTarget = link_target == nullptr ? null : link_target.cast<Utf8>().toDartString();
return SchemaProperty(name.cast<Utf8>().toDartString(), RealmPropertyType.values[type],
optional: flags & realm_property_flags.RLM_PROPERTY_NULLABLE == realm_property_flags.RLM_PROPERTY_NULLABLE,
primaryKey: flags & realm_property_flags.RLM_PROPERTY_PRIMARY_KEY == realm_property_flags.RLM_PROPERTY_PRIMARY_KEY,
optional: flags & realm_property_flags.RLM_PROPERTY_NULLABLE.value == realm_property_flags.RLM_PROPERTY_NULLABLE.value,
primaryKey: flags & realm_property_flags.RLM_PROPERTY_PRIMARY_KEY.value == realm_property_flags.RLM_PROPERTY_PRIMARY_KEY.value,
linkTarget: linkTarget == null || linkTarget.isEmpty ? null : linkTarget,
collectionType: RealmCollectionType.values[collection_type]);
}
Expand Down
Loading

0 comments on commit 425376a

Please sign in to comment.