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

NULL-byte #4

Closed
themars opened this issue Feb 24, 2016 · 9 comments
Closed

NULL-byte #4

themars opened this issue Feb 24, 2016 · 9 comments

Comments

@themars
Copy link
Contributor

themars commented Feb 24, 2016

Trying to create barcode with data:

data = ['08', 'FF', '00', '01', 'E2', '25', '01', '00', '00', '00', '00', '00', '00', 'CF', '21', '09', '2C', '16', 'E1', 'A0', '12', 'CE', '18', '00', '00']
barcode = PDF417.new([data.join].pack("H*"))

barcode stops with length of 4

if I delete '00' it will go thru

barcode = PDF417.new([data.delete_if { |x| x == '00' }.join].pack("H*"))

Is there any way to pass the data?

@jamesprior
Copy link
Collaborator

Well, it is trying to turn that string into a set of PDF417 codewords for barcode generation. I'm not sure what you want the end result to be, but with that initialization I wouldn't expect a scan to return data.join].pack("H*").

Maybe you want to try using the raw_codewords method? That would look like this:

barcode = PDF417.new
barcode.raw_codewords = data

Or maybe

barcode = PDF417.new(:raw_codewords => data)

If that doesn't do it then it means digging into C code to fix it but I think the assumption you ran into is that it is passed a text string to be encoded, and that's a string with some very special characters.

@themars
Copy link
Contributor Author

themars commented Feb 24, 2016

Can you please explain how to convert hex data I'm trying to pass into element of raw_codewords array?

Thanks!

@jamesprior
Copy link
Collaborator

Not any better than I have above - to set raw_codewords pass it an array of the raw codewords.

What happens when this barcode is scanned, a bunch of binary data comes back?

@themars
Copy link
Contributor Author

themars commented Feb 24, 2016

I mean, How data in raw_codewords is encoded?

For example
barcode = PDF417.new("test")
p barcode.codewords # [4, 829, 138, 599]

first element - length of array, what about other elements?

Yes, after scan binary data comes back.

@jamesprior
Copy link
Collaborator

Okay, looking at https://github.com/asee/pdf417/blob/master/ext/pdf417/pdf417.c#L189 and https://en.wikipedia.org/wiki/PDF417#Codewords it looks like the codewords should be integers and represent the binary data that has been encoded in the PDF417 format.

This gem is a wrapper around a C library and looking at the method it uses to convert text to codewords it looks like it will occasionally try to use compact binary codeword substitutes, but that it expects text data - https://github.com/asee/pdf417/blob/master/ext/pdf417/pdf417lib.c#L520

@themars
Copy link
Contributor Author

themars commented Feb 26, 2016

You need to fix your code. Problem: you setting ruby string to char array using StringValuePtr(text), but You don't set the right string size, RSTRING_LEN(text) - will return the exact ruby string length. So, if you set p.lenText = (int)RSTRING_LEN(text); there will be no problem :)

I've created a pull request to fix this, take a look.

@jamesprior
Copy link
Collaborator

That is great, thank you very much! It makes a log of sense now that you point it out too...

@themars themars closed this as completed Feb 26, 2016
@jamesprior
Copy link
Collaborator

FYI, I bumped this up to 1.0.0, fixed some other errors that came up and released a new version of the gem

@themars
Copy link
Contributor Author

themars commented Feb 26, 2016

👍

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