Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BarcodeResult type mismatch between Android and iOS #48

Open
boutier opened this issue Apr 12, 2023 · 1 comment
Open

BarcodeResult type mismatch between Android and iOS #48

boutier opened this issue Apr 12, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@boutier
Copy link

boutier commented Apr 12, 2023

Hi !

With mlkit 2.0.0, on Android, when scanning a *code, I have something like:

{
  "bounds": {
    "origin": { "x": 100, "y": 215 },
    "size": { "height": 166, "width": 172 }
  },
  "points": [
    { "x": 110, "y": 215 },
    { "x": 272, "y": 220 },
    { "x": 262, "y": 381 },
    { "x": 100, "y": 376 }
  ],
  "rawBytes": [68, 77, 83, 90, 49, 47, 49, 47, 49, 47, 49],
  "format": "QR_CODE",
  "displayValue": "DMSZ1/1/1/1",
  "rawValue": "DMSZ1/1/1/1",
  "valueType": "Text"
}

While I have on iOS:

{
  "bounds": { "y": 279, "x": 661, "width": 576, "height": 589 },
  "points": [
    { "x": 661, "y": 357 },
    { "x": 1161, "y": 279 },
    { "x": 1237, "y": 781 },
    { "x": 738, "y": 868 }
  ],
  "rawBytes": "RE1TWjEvMS8xLzE=",
  "format": ["qr_code"],
  "displayValue": "DMSZ1/1/1/1",
  "rawValue": "DMSZ1/1/1/1",
  "valueType": "text"
}

(both reordered for better readability)

The BarcodeResult interface is defined in https://github.com/NativeScript/mlkit/blob/0712e3dfe4b4d2eb4d0caa3e22786c603366f19f/packages/mlkit-barcode-scanning/index.ts

Given BarcodeResult is the reference:

  • on Android, enum values are not lowercase (QR_CODE and Text instead of qr_code and text in this case)
  • on iOS:
    • bounds is simpler (origin and size are inlined — which I personally prefer BTW)
    • rawBytes being base64 encoded (I guess) instead of being an array of any
    • format being an array

Side questions about BarcodeResult:

  • why having bounds with origin and size in the BarcodeResult model rather than just inlining them as in the current iOS implementation?
  • why having an Origin type while we already have a Point?
  • why typing rawBytes as any[] instead of number[] (or string if base64 is deemed better)
@triniwiz
Copy link
Member

For starters the android implementation was created before iOS so I failed to match the behaviour so the differences could be me trying to make things easier.

  1. Qr* This would be a serializer issue
  2. Bound* my fault here the bounds output on android is what iOS outputs but I joined them so I'll merge it.
  3. rawBytes* seems iOS and Android encoders behave a bit different, both values are rawBytes on their respective platforms byte[] and Data. If needed we can use a custom JSON parse to ensure rawBytes is returned as an Array/ArrayBuffer

@triniwiz triniwiz added the bug Something isn't working label Apr 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants