BarcodeResult type mismatch between Android and iOS
boutier opened this issue · 1 comments
boutier commented
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
andText
instead ofqr_code
andtext
in this case) - on iOS:
bounds
is simpler (origin
andsize
are inlined — which I personally prefer BTW)rawBytes
being base64 encoded (I guess) instead of being an array ofany
format
being an array
Side questions about BarcodeResult
:
- why having
bounds
withorigin
andsize
in theBarcodeResult
model rather than just inlining them as in the current iOS implementation? - why having an
Origin
type while we already have aPoint
? - why typing
rawBytes
asany[]
instead ofnumber[]
(orstring
if base64 is deemed better)
triniwiz commented
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.
- Qr* This would be a serializer issue
- Bound* my fault here the bounds output on android is what iOS outputs but I joined them so I'll merge it.
- rawBytes* seems iOS and Android encoders behave a bit different, both values are rawBytes on their respective platforms
byte[]
andData
. If needed we can use a custom JSON parse to ensure rawBytes is returned as an Array/ArrayBuffer