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

EDIFACT encoding: 'Return to ASCII mode'-code #2

Open
adrianschlatter opened this issue May 22, 2021 · 0 comments
Open

EDIFACT encoding: 'Return to ASCII mode'-code #2

adrianschlatter opened this issue May 22, 2021 · 0 comments

Comments

@adrianschlatter
Copy link

Apparently, toEdifact(msg) encodes the last character in msg as "ASCII" even if it is a valid EDIFACT character.

Example

toEdifact('ABCD') => [240, 4, 32, 223, 69]

  • 240: "Start EDIFACT mode" code
  • [4, 32, 223] after unpacking 3 bytes to 4 EDIFACT codes result in [1, 2, 3, 31] which means 'A', 'B', 'C', 'Return to ASCII mode'.
  • 69: "ASCII" encoding of 'D'

While this works, a more efficient encoding would be [240, 4, 32, 196]:

  • 240: "Start EDIFACT mode" code
  • [4, 32, 196] unpacked result in [1, 2, 3, 4] which corresponds to 'A', 'B', 'C', 'D'

Code

The culprit is in datamatrix.js/DataMatrix,toEdifact() (note that the if-else systematically skips the last character to place a 31 (="Return to ASCII mode") in front of it):

if (i < l - 1) {
      /* encode char */
      ch = t.charCodeAt(i);
      if (ch < 32 || ch > 94) return []; /* not in set */
} else ch = 31; /* return to ASCII */
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

1 participant