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

Reading Binary Data #44

Closed
MggMuggins opened this issue Oct 2, 2018 · 2 comments
Closed

Reading Binary Data #44

MggMuggins opened this issue Oct 2, 2018 · 2 comments

Comments

@MggMuggins
Copy link

MggMuggins commented Oct 2, 2018

So I'm working on a Point of Sale app doing barcode scanning. I'm using datamatrix to store an md5 sum of an item name, and my app stores all the item names and their prices in a json file. When I scan a barcode, I'll compare the data I get out of the barcode with the md5 sum of all the item names to figure out which price+name combination is the right one. There's probably a better way to do that, but I want all the barcodes to be the same size, hence the hashing function.

The problem is reading binary data. I've got a program that will run a name through md5 and spit that out on stdout, and I'm using dmtxwrite and dmtxread to encode/decode barcodes. I can generate a barcode in this manner which I can verify is the correct data using dmtxread. Barcode:
out

The problem is reading this barcode data using this library: The library gives me a string instead of aList<int> (dart's type system is unsuitable for this kind of low-level memory work anyway, but I'll skip most of that spiel), and both codeUnits and runes do not give me identical data to the stuff I get out of the barcode using dmtxread (they are the same).

EDIT: Realized that if anybody wanted to test with that barcode they'd need the correct hash: run pineapple_pie through md5 and you should get the same binary data that is stored in that code.

@rmtmckenzie
Copy link
Owner

Hmm. That's not an easy problem as the Mobile Vision library only returns a string. See this: googlesamples/android-vision#156. Not only that, it seems to return the string "Unknown encoding" rather than throwing an error about it which is why you're seeing different bytes coming out of whatever you're doing. Not ideal... I'll make an issue to put something in that throws an error if it finds that string.

At some point I may update to use the firebase ml vision library instead of this one, but it seems to also use a string so that won't help.

You may be able to find a different library to do this, or implement something yourself (I believe the ZXing library supports binary data but not 100% sure).

What I'd recommend though is base64-encoding (or some other base-encoding) your data before making it into the datamatrix. That will increase your barcode code size by a factor of 4/3 (for base64) but should work with no problems - you'll just have to base64-decode it on the other side.

@MggMuggins
Copy link
Author

MggMuggins commented Oct 8, 2018

That seems like a really nasty case of assuming a use-case for something where that really shouldn't happen. Sorta dumb on the part of the authors.

Anyway, I'm going to use hex as alphanumeric for now, I appreciate the note. I'm going to restructure to make that unnecessary.

Another little thing I noticed: Throwing an exception in the QrCodeCallback just ends the call without any indication at all. (Specifically I'm generating an NPE, and nothing is being done to indicate that I'm getting an exception)

Great library! Exactly what I need. Sorry for not replying sooner, RL caught up with me :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants