Skip to content

Commit

Permalink
Fix Decimal128 and RealmValue
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsenko committed Jun 28, 2024
1 parent 05742ac commit ec29569
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion packages/realm_dart/lib/src/handles/native/init.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import 'dart:ffi';
import 'dart:io';

import 'package:ejson/ejson.dart';
import 'package:package_config/package_config.dart';
import 'package:path/path.dart' as p;

Expand All @@ -15,6 +16,8 @@ import '../../realm_class.dart';
import '../../../realm.dart' show isFlutterPlatform;
export '../../../realm.dart' show isFlutterPlatform;

import 'decimal128.dart' as impl;

const realmBinaryName = 'realm_dart';
final targetOsType = Platform.operatingSystem.asTargetOsType ?? _platformNotSupported();
final nativeLibraryName = _getLibName(realmBinaryName);
Expand Down Expand Up @@ -52,7 +55,6 @@ String _getLibPathDart(Package realmDartPackage) {
_platformNotSupported();
}


String _getLibName(String stem) => switch (targetOsType) {
TargetOsType.android => 'lib$stem.so',
TargetOsType.ios => stem, // xcframeworks are a directory
Expand Down Expand Up @@ -135,13 +137,28 @@ DynamicLibrary _openRealmLib() {
throwError(candidatePaths);
}

EJsonValue encodeDecimal128(Decimal128 value) => {'\$numberDecimal': value.toString()};

impl.Decimal128 decodeDecimal128(EJsonValue ejson) => switch (ejson) {
{'\$numberDecimal': String x} => impl.Decimal128.parse(x),
_ => raiseInvalidEJson(ejson),
};

EJsonValue encodeRealmValue(RealmValue value) => toEJson(value.value);

RealmValue decodeRealmValue(EJsonValue ejson) => RealmValue.from(fromEJson(ejson));

/// @nodoc
// Initializes Realm library
DynamicLibrary initRealm() {
if (_library != null) {
return _library!;
}

register<impl.Decimal128>(encodeDecimal128, decodeDecimal128, superTypes: [Decimal128]);
register<Decimal128>(encodeDecimal128, decodeDecimal128);
register(encodeRealmValue, decodeRealmValue);

if (!isFlutterPlatform) {
assert(() {
try {
Expand Down

0 comments on commit ec29569

Please sign in to comment.