gs1-ai-syntaxgs1-datamatrixgs1-128gs1-qr-codegs1-databar

Is it possible to decode GS1 Application Identifier formatted data that lacks GS characters to represent FNC1?


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:

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


Solution

  • 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.