NativeScript/mlkit

BarcodeResult type mismatch between Android and iOS

boutier opened this issue · 1 comments

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)

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