From 94d13710f5c1a228e98c6aed4a722dcf712a0b5f Mon Sep 17 00:00:00 2001 From: Khoren Markosyan Date: Fri, 21 Oct 2022 13:01:59 +0400 Subject: [PATCH] added bytes array to scan result --- ios/Classes/src/native_zxing.cpp | 3 +++ ios/Classes/src/native_zxing.h | 10 ++++++---- lib/generated_bindings.dart | 7 +++++++ lib/src/utils/extentions.dart | 5 ++++- pubspec.yaml | 6 +++--- 5 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ios/Classes/src/native_zxing.cpp b/ios/Classes/src/native_zxing.cpp index c6cbaa7..cd276fe 100644 --- a/ios/Classes/src/native_zxing.cpp +++ b/ios/Classes/src/native_zxing.cpp @@ -122,6 +122,9 @@ extern "C" code->format = Format(static_cast(result.format())); + code->bytes = result.bytes().data(); + code->length = result.bytes().size(); + wstring_convert> converter; string text = converter.to_bytes(result.text()); code->text = new char[text.length() + 1]; diff --git a/ios/Classes/src/native_zxing.h b/ios/Classes/src/native_zxing.h index 84b26f1..ec7996c 100644 --- a/ios/Classes/src/native_zxing.h +++ b/ios/Classes/src/native_zxing.h @@ -53,10 +53,12 @@ extern "C" */ struct CodeResult { - int isValid; ///< Whether the barcode was successfully decoded - char *text; ///< The decoded text - enum Format format; ///< The format of the barcode - struct Pos *pos; ///< The position of the barcode within the image + int isValid; ///< Whether the barcode was successfully decoded + char *text; ///< The decoded text + const unsigned char *bytes; ///< The bytes is the raw / standard content without any modifications like character set conversions + int length; ///< The length of the bytes + enum Format format; ///< The format of the barcode + struct Pos *pos; ///< The position of the barcode within the image }; /** diff --git a/lib/generated_bindings.dart b/lib/generated_bindings.dart index 0854b30..9362d82 100644 --- a/lib/generated_bindings.dart +++ b/lib/generated_bindings.dart @@ -263,6 +263,13 @@ class CodeResult extends ffi.Struct { /// < The decoded text external ffi.Pointer text; + /// < The bytes is the raw / standard content without any modifications like character set conversions + external ffi.Pointer bytes; + + /// < The length of the bytes + @ffi.Int() + external int length; + /// < The format of the barcode @ffi.Int32() external int format; diff --git a/lib/src/utils/extentions.dart b/lib/src/utils/extentions.dart index 70b1596..dd937a3 100644 --- a/lib/src/utils/extentions.dart +++ b/lib/src/utils/extentions.dart @@ -19,6 +19,8 @@ extension CodeExt on CodeResult { bool get isValidBool => isValid == 1; String? get textString => text == nullptr ? null : text.cast().toDartString(); + Uint8List get rawBytes => + Uint8List.fromList(bytes.cast().asTypedList(length)); String get formatString => barcodeFormatName(format); Pos get position => pos.ref; } @@ -28,7 +30,8 @@ extension EncodeExt on EncodeResult { String? get textString => text == nullptr ? null : text.cast().toDartString(); String get formatString => barcodeFormatName(format); - Uint32List get bytes => Uint32List.fromList(data.cast().asTypedList(length)); + Uint32List get bytes => + Uint32List.fromList(data.cast().asTypedList(length)); String get errorMessage => error.cast().toDartString(); } diff --git a/pubspec.yaml b/pubspec.yaml index 5be99a6..45a28aa 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,11 +12,11 @@ dependencies: ffi: ^2.0.0 flutter: sdk: flutter - image: ^3.2.0 + image: ^3.0.0 dev_dependencies: - ffigen: ^6.0.0 # dart run ffigen - flutter_lints: ^2.0.1 + ffigen: ^7.0.0 # dart run ffigen + flutter_lints: ^2.0.0 flutter_test: sdk: flutter