jannschu / datamatrix-rs

Data Matrix (ECC 200) encoding and decoding library in Rust
Apache License 2.0
16 stars 2 forks source link

GS1 FNC1 Function 1 Symbol Character #3

Open andoryu-kun opened 3 weeks ago

andoryu-kun commented 3 weeks ago

Is it possible to add support for GS1 FNC1?

jannschu commented 3 weeks ago

What would be relatively easy to implement is the encoding of FNC1 at the start. For FNC1 characters in later positions we would need to change or extend the input type which is currently &[u8] and this can not encode FNC1. Using ASCII GS in later positions is covered of course currently though.

The decoder already has basic support for codes starting with FNC1 but this is not exposed in the public API. It also does not check any further restrictions required by GS1, which is also not in scope for this library in my opinion. FNC1 characters in later positions are mapped as ASCII GS in ASCII mode and result in an error DataDecodingError::NotImplemented if FNC1 is used in C40/Text mode. The feature behind the checkbox labeled "Detailed decoder output" in the README is intended to provide this, among other information, to the user.

Would the encoding of FNC1 at the start work for you?

andoryu-kun commented 3 weeks ago

Yes, the encoding of FNC1 at the start is all I need.

skull-squadron commented 1 week ago

2.1 Function 1 Symbol Character (FNC1)

By definition in ISO/IEC 16022 GS1 DataMatrix uses a special start sequence to differentiate GS1 DataMatrix from other ISO/IEC Data Matrix symbols. This is achieved by using the Function 1 Symbol Character (FNC1) in the first position of the data encoded. It enables scanners to process the information according to the GS1 System Rules. The FNC1 (codeword 232) has two separate uses in GS1 DataMatrix: ■ Start character. ■ Separator character to separate element strings that are not in the predefined list (see Table 2-3).

Important: In accordance with ISO/IEC 15424 - Data Carrier Identifiers (including

Symbology Identifiers), the Symbology Identifier is the first three characters transmitted by the scanner indicating symbology type. For a GS1 DataMatrix the symbology identifier is ]d2.

References:

  1. https://www.gs1.org/docs/barcodes/GS1_DataMatrix_Guideline.pdf

FYI: My primary use-case at this time involves base256 and precludes additional pre-parsing of binary contents that would reduce the effective base256 capacity.

jannschu commented 1 week ago

I created a merge request for this, feedback is welcome since I personally do not use GS1 Data Matrix.

The API is

let result = DataMatrix::encode_gs1(b"01034531200000111719112510ABCD1234\x1D2110");

Notice that there is limited decoding support only. ]d2 is not added by the decoder, a possible pitfall I also added to the documentation, same MR. I will keep it like that until more detailed scanner output is required because I do not consider the decoder to be a "scanner" in terms of the standard.

I still consider changing the input format though because this is a bit hacky and I would like the user to be more flexible in specifying where FNC1 should be encoded, this could then also allow more fine controlled ECI.