1

I have some data extracted from a GS1 barcode (be it GS1 DataMatrix, GS1 QR Code, GS1 DataBar or GS1-128) that is notionally in GS1 Application Identifier, however the FNC1 separator characters (that are expected to be transmitted as GS characters) are omitted.

Here is the incorrectly extracted data (missing GS characters that represent the barcode message's FNC1 separators) that I wish to parse into AI values:

01012345678912311700112210123421555666777

The intended extraction is as follows (masked for privacy)

(01) 01234567891231
(17) 001122
(10) 1234
(21) 555666777

However according to this notice (page 2) and elsewhere Application Identifiers are defined to either have "predefined fixed length", "fixed length" or "variable length" values.

For example:

  • (00) has a predefined fixed length of 18 characters, and does not require FNC1 termination.
  • (01) has a predefined fixed length of 14 characters, and does not require FNC1 termination.
  • (21) has a variable length up to 20 characters, and therefore does require FNC1 termination.
  • (7001) has a fixed length of 13 characters, but is not in the "predefined fixed-length set of AIs" and therefore does require FNC1 termination.

How can I possibly implement a parser for GS1 data that is missing the variable-length field separators?

Terry Burton
  • 2,801
  • 1
  • 29
  • 41
Tommy Leong
  • 2,509
  • 6
  • 30
  • 54

1 Answers1

1

There can exist no algorithm to reliably decode GS1 Application Identifier formatted data that is missing the FNC1 separators that are strictly required to terminate fields that do not have a predefined length, such as AI (10).

Your example data, as given, has the following correct but unintended decoding:

(01) 01234567891231
(17) 001122
(10) 123421555666777

To be compatible with the GS1 system, a barcode scanner must:

  1. Emit a AIM symbology identifier modifier indicating that FNC1 is in first position ("GS1 mode"), or provide an equivalent flag for the same.
  2. Transmit any FNC1 characters, other than the one in first or second character position, as GS characters (ASCII value 29).

This transmission protocol for FNC1 goes as far back as the first symbology to support GS1 Application Identifier data, Code 128:

"When FNC1 is used in the first or second position it shall not be represented in the transmitted message [rather it amends the symbology identifier's modifier character to indicate GS1 mode] ... FNC1 in the third or subsequent character position is transmitted as the control character GS (value 29)." ⁠— ISO/IEC 15417:2007 appendix B.4 (normative).

Equivalent mandatory clauses are part of all barcode symbology specifications that support GS1 Application Identifier data.

Any reader that does not transmit FNC1 in accordance with the above protocol is defective — it does not read barcodes in the way that is required by the symbology standards. It is not simply that such a scanner does not support one particular GS1 application standard. FNC1 is also used in different capacities in several industry standard syntaxes. There is no suitable workaround to support scanning of GS1 Application Identifier syntax when using a defective scanner that does not follow the required decode protocol and therefore loses information that is contained within the symbol.

The correct algorithm for decoding well-formatted GS1 data is presented in this answer.

GS1 provides the Barcode Syntax Resource which includes a C library (that has pure JavaScript and WebAssembly builds) that implements the parser algorithm and can also perform deep validation of the data.

Terry Burton
  • 2,801
  • 1
  • 29
  • 41
  • Thanks @Terry. I've read thru [your ans here](https://stackoverflow.com/a/31760872/4311268), this is currently not possible as I don't have the exact length for each AI value, otherwise extraction would be possible. I've also tried the Barcode Syntax Resource before (`gs1encoders-wasm-app`), unfortunately the AI must be wrapped with parenthesis before it can parse successfully. In my case the data is plain, my challenge here is unable to find AI that do not have predefined length. – Tommy Leong Mar 11 '23 at 05:00
  • Just to facilitate the discussion better, I've also created a [chatroom](https://chat.stackoverflow.com/rooms/252451/gs1-data-extraction-without-fnc1) for an easier communication. Feel free to join here and comment more, thanks! – Tommy Leong Mar 11 '23 at 05:03
  • or would it be possible to know the length of each AI using the GTIN information? Assuming the GTIN is always the first information from the barcode, and we know the value of GTIN is always in length of 14. – Tommy Leong Mar 11 '23 at 09:51
  • The BSR can parse unbracketed AI syntax and present the result as a bracketed element string or as a non-HRI text array.If your data is generic GS1 data then it will use AI that are defined to be variable length that requires FNC1 separators. There's nothing you can do about that. Fix the scanning workflow so that it provides the barcode message data in a format that isn't deranged. – Terry Burton Mar 11 '23 at 10:37
  • Neither the GTIN nor any master data to which the GTIN is associated will allow you to know want otherbAIs will be supplied in the barcode message, nor fix the length of any variable-length AIs that are supplied. The data is bad. It needs to be fixed. No other solution. – Terry Burton Mar 11 '23 at 10:54
  • 1
    thank you for your patient sharing and details answering. We're not going anywhere with the data like I mentioned in ques, FNC1 is strictly required (should not be plain). – Tommy Leong Mar 18 '23 at 11:45