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

Add support for structured append segments #228

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

misenhower
Copy link

This change adds support for structured append segments (#178). Here's a usage example:

QRCode.toFile('test.png', [
  { mode: 'structuredappend', data: { position: 0x0, total: 0x3, parity: 0x0A } },
  { mode: 'byte', data: [0x01, 0x02, 0x03] }
])

This generates the following QR code:

test

I confirmed functionality by testing the QR code with this reader and it found the following bytes:

30 30 a4 03 01 02 03 00   ec 11 ec 11 ec 11 ec 11

3 - the mode indicator for structured append mode (0011)
0 - the current symbol position (indicating this is the 1st QR code)
3 - the total number of symbols (there are a total of 4 QR codes)
0A - the parity byte (as specified)

The parity byte is a little tricky because it's based on the total XOR sum of all the content bytes for the entire payload, spanning across multiple QR codes. There's no way to calculate it based on a single QR code's content, so the assumption here is that you would calculate the parity byte yourself before generating the QR codes, and just pass in whatever you found for the result.

Effectively, the parity byte doesn't really matter much because I think a lot of QR code readers don't actually verify it. I've seen implementations that just generate a random byte value rather than actually calculating what the value should be and they seem to work without issue.

Anyway, let me know if you notice any issues! 😃

@soldair
Copy link
Owner

soldair commented Oct 28, 2020

sorry for leaving this so long.
this is a good pr. we just have to resolve the conflicts and land this feature

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

Successfully merging this pull request may close these issues.

2 participants