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?
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:
To be compatible with the GS1 system, a barcode scanner must:
This transmission protocol for FNC1 goes as far back as the first symbology to support GS1 Application Identifier data, Code 128:
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.