Browse Source

added bytes array to scan result

pull/42/head
Khoren Markosyan 2 years ago
parent
commit
94d13710f5
  1. 3
      ios/Classes/src/native_zxing.cpp
  2. 10
      ios/Classes/src/native_zxing.h
  3. 7
      lib/generated_bindings.dart
  4. 5
      lib/src/utils/extentions.dart
  5. 6
      pubspec.yaml

3
ios/Classes/src/native_zxing.cpp

@ -122,6 +122,9 @@ extern "C"
code->format = Format(static_cast<int>(result.format())); code->format = Format(static_cast<int>(result.format()));
code->bytes = result.bytes().data();
code->length = result.bytes().size();
wstring_convert<codecvt_utf8<wchar_t>> converter; wstring_convert<codecvt_utf8<wchar_t>> converter;
string text = converter.to_bytes(result.text()); string text = converter.to_bytes(result.text());
code->text = new char[text.length() + 1]; code->text = new char[text.length() + 1];

10
ios/Classes/src/native_zxing.h

@ -53,10 +53,12 @@ extern "C"
*/ */
struct CodeResult struct CodeResult
{ {
int isValid; ///< Whether the barcode was successfully decoded int isValid; ///< Whether the barcode was successfully decoded
char *text; ///< The decoded text char *text; ///< The decoded text
enum Format format; ///< The format of the barcode const unsigned char *bytes; ///< The bytes is the raw / standard content without any modifications like character set conversions
struct Pos *pos; ///< The position of the barcode within the image 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
}; };
/** /**

7
lib/generated_bindings.dart

@ -263,6 +263,13 @@ class CodeResult extends ffi.Struct {
/// < The decoded text /// < The decoded text
external ffi.Pointer<ffi.Char> text; external ffi.Pointer<ffi.Char> text;
/// < The bytes is the raw / standard content without any modifications like character set conversions
external ffi.Pointer<ffi.UnsignedChar> bytes;
/// < The length of the bytes
@ffi.Int()
external int length;
/// < The format of the barcode /// < The format of the barcode
@ffi.Int32() @ffi.Int32()
external int format; external int format;

5
lib/src/utils/extentions.dart

@ -19,6 +19,8 @@ extension CodeExt on CodeResult {
bool get isValidBool => isValid == 1; bool get isValidBool => isValid == 1;
String? get textString => String? get textString =>
text == nullptr ? null : text.cast<Utf8>().toDartString(); text == nullptr ? null : text.cast<Utf8>().toDartString();
Uint8List get rawBytes =>
Uint8List.fromList(bytes.cast<Int8>().asTypedList(length));
String get formatString => barcodeFormatName(format); String get formatString => barcodeFormatName(format);
Pos get position => pos.ref; Pos get position => pos.ref;
} }
@ -28,7 +30,8 @@ extension EncodeExt on EncodeResult {
String? get textString => String? get textString =>
text == nullptr ? null : text.cast<Utf8>().toDartString(); text == nullptr ? null : text.cast<Utf8>().toDartString();
String get formatString => barcodeFormatName(format); String get formatString => barcodeFormatName(format);
Uint32List get bytes => Uint32List.fromList(data.cast<Int8>().asTypedList(length)); Uint32List get bytes =>
Uint32List.fromList(data.cast<Int8>().asTypedList(length));
String get errorMessage => error.cast<Utf8>().toDartString(); String get errorMessage => error.cast<Utf8>().toDartString();
} }

6
pubspec.yaml

@ -12,11 +12,11 @@ dependencies:
ffi: ^2.0.0 ffi: ^2.0.0
flutter: flutter:
sdk: flutter sdk: flutter
image: ^3.2.0 image: ^3.0.0
dev_dependencies: dev_dependencies:
ffigen: ^6.0.0 # dart run ffigen ffigen: ^7.0.0 # dart run ffigen
flutter_lints: ^2.0.1 flutter_lints: ^2.0.0
flutter_test: flutter_test:
sdk: flutter sdk: flutter

Loading…
Cancel
Save