Main class for processing GS1 barcode data, including validation, format conversion, and generation of outputs such as GS1 Digital Link URIs and Human-Readable Interpretation text.
More...
|
| | GS1Encoder () |
| | Initialises a new instance of the GS1Encoder class.
|
| |
| | GS1Encoder (const InitOpts &opts) |
| | Initialises a new instance of the GS1Encoder class with the given options.
|
| |
| | ~GS1Encoder () |
| | Destructor. Releases the native context.
|
| |
|
| GS1Encoder (const GS1Encoder &)=delete |
| | Copy construction is deleted: the underlying native context cannot be duplicated.
|
| |
|
GS1Encoder & | operator= (const GS1Encoder &)=delete |
| | Copy assignment is deleted: the underlying native context cannot be duplicated.
|
| |
| | GS1Encoder (GS1Encoder &&other) noexcept |
| | Move-construct from another encoder.
|
| |
| GS1Encoder & | operator= (GS1Encoder &&other) noexcept |
| | Move-assign from another encoder.
|
| |
| std::optional< std::string > | init_fallback_warning () const |
| | The warning message produced when initialisation fell back to the embedded AI table because the supplied Syntax Dictionary could not be loaded.
|
| |
| std::string | version () const |
| | Get the version string of the library.
|
| |
| int | max_data_str_length () const |
| | Get the maximum size of the input data buffer for barcode message content.
|
| |
| Symbology | sym () const |
| | Get the current symbology type.
|
| |
| void | set_sym (Symbology s) |
| | Set the current symbology type.
|
| |
| bool | add_check_digit () const |
| | Get the current "add check digit" mode.
|
| |
| void | set_add_check_digit (bool v) |
| | Enable or disable "add check digit" mode for EAN/UPC and GS1 DataBar symbols.
|
| |
| bool | permit_unknown_ais () const |
| | Get the current "permit unknown AIs" mode.
|
| |
| void | set_permit_unknown_ais (bool v) |
| | Enable or disable acceptance of unknown AIs in parsed input.
|
| |
| bool | permit_zero_suppressed_gtin_in_dl_uris () const |
| | Get the current "permit zero-suppressed GTIN in GS1 DL URIs" mode.
|
| |
| void | set_permit_zero_suppressed_gtin_in_dl_uris (bool v) |
| | Enable or disable acceptance of zero-suppressed GTINs in GS1 Digital Link URIs.
|
| |
| bool | include_data_titles_in_hri () const |
| | Get the current "include data titles in HRI" mode.
|
| |
| void | set_include_data_titles_in_hri (bool v) |
| | Enable or disable inclusion of AI Data Titles in HRI output.
|
| |
| bool | validation_enabled (Validation v) const |
| | Get the current enabled status of an AI validation procedure.
|
| |
| void | set_validation_enabled (Validation v, bool enabled) |
| | Enable or disable an AI validation procedure.
|
| |
| std::string | data_str () const |
| | Get the raw data that would be directly encoded within a GS1 barcode message.
|
| |
| void | set_data_str (const std::string &v) |
| | Set the raw barcode message data.
|
| |
| std::string | ai_data_str () const |
| | Get the barcode data input rendered as a bracketed AI element string.
|
| |
| void | set_ai_data_str (const std::string &v) |
| | Set the barcode data input from a bracketed GS1 AI element string.
|
| |
| std::string | get_dl_uri (const std::string &stem) const |
| | Render the current AI-based input data as a GS1 Digital Link URI.
|
| |
| std::string | scan_data () const |
| | Get the scan data string a reader would return for the current data and symbology.
|
| |
| void | set_scan_data (const std::string &v) |
| | Process normalised scan data received from a barcode reader.
|
| |
| std::vector< std::string > | hri () const |
| | Get the Human-Readable Interpretation ("HRI") text for the current input data.
|
| |
| std::vector< std::string > | dl_ignored_query_params () const |
| | Get the non-numeric (ignored) query parameters from a GS1 Digital Link URI.
|
| |
| std::string | err_markup () const |
| | Get the marked-up offending AI from the most recent linting failure.
|
| |
Main class for processing GS1 barcode data, including validation, format conversion, and generation of outputs such as GS1 Digital Link URIs and Human-Readable Interpretation text.
Move-only: the underlying native context cannot be duplicated, but ownership can be transferred. The destructor releases the native resources, so the object can be used at any scope without manual cleanup.
| std::vector< std::string > gs1encoders::GS1Encoder::dl_ignored_query_params |
( |
| ) |
const |
|
inline |
Get the non-numeric (ignored) query parameters from a GS1 Digital Link URI.
When set_data_str() parses a GS1 Digital Link URI, query parameters that are not numeric AI keys are ignored for the purposes of AI extraction. This method returns those ignored parameters so the application can present which sections of the URI were not interpreted as AI data.
For example, given the input data https://a/01/12312312312333/22/ABC?name=Donald%2dDuck&99=ABC&testing&type=cartoon, this method returns:
name=Donald%2dDuck
testing
type=cartoon
The returned strings are not URI-decoded.
- Returns
- one std::string per ignored query parameter; empty vector when no DL URI has been parsed or none were ignored.
- See also
- set_data_str()
| void gs1encoders::GS1Encoder::set_ai_data_str |
( |
const std::string & |
v | ) |
|
|
inline |
Set the barcode data input from a bracketed GS1 AI element string.
The input is provided in human-friendly format without FNC1 characters (which are inserted automatically), for example:
(01)12345678901231(10)ABC123(11)210630
This syntax harmonises the input format across all symbologies — for example (01)00031234000054 is acceptable for EAN-13, UPC-A, UPC-E, any variant of the GS1 DataBar family, GS1 QR Code and GS1 Data Matrix.
The input is validated against the AI data syntax rules at the point of being set; on failure this setter throws gs1encoders::GS1EncoderParameterException, and when the failure is due to invalid AI content err_markup() returns a marked-up rendering of the offending AI.
Any literal "(" characters in AI element values must be escaped as "\(" to avoid being conflated with the start of the next AI.
For symbologies that support a composite component (all except Data Matrix, QR Code and DotCode) the linear and 2D components can be separated with a "|" character, e.g. (01)12345678901231|(10)ABC123(11)210630.
- Parameters
-
| v | the bracketed AI element string to be parsed. |
- Exceptions
-
- See also
- ai_data_str()
-
set_data_str()
-
err_markup()
| void gs1encoders::GS1Encoder::set_data_str |
( |
const std::string & |
v | ) |
|
|
inline |
Set the raw barcode message data.
A leading "^" indicates the data is in GS1 Application Identifier syntax; subsequent "^" characters represent the FNC1 non-data separator that delimits variable-length fields.
Inputs beginning with "^" are validated against the AI data syntax rules; on failure this setter throws gs1encoders::GS1EncoderParameterException, and when the failure is due to invalid AI content err_markup() returns a marked-up rendering of the offending AI.
Inputs beginning with "http://" or "https://" are parsed as GS1 Digital Link URIs; the corresponding AI element string is extracted and validated.
EAN/UPC, GS1 DataBar and GS1-128 support a Composite Component. The Composite Component must be specified in AI syntax. It is separated from the primary linear component with a "|" character and begins with FNC1 in first position, e.g. "^0112345678901231|^10ABC123^11210630" (linear component (01)12345678901231, composite component (10)ABC123(11)210630).
- Note
- For GS1 data it is simpler and less error-prone to specify the input in human-friendly bracketed AI syntax via set_ai_data_str(), which inserts FNC1 characters automatically.
- Parameters
-
| v | the raw barcode data to be set. |
- Exceptions
-
- See also
- data_str()
-
set_ai_data_str()
-
err_markup()
| void gs1encoders::GS1Encoder::set_permit_zero_suppressed_gtin_in_dl_uris |
( |
bool |
v | ) |
|
|
inline |
Enable or disable acceptance of zero-suppressed GTINs in GS1 Digital Link URIs.
When false (the default), the value of a path component for AI (01) must be a full GTIN-14. When true, the value may be a GTIN-14 with leading zeros suppressed (a GTIN-13, GTIN-12 or GTIN-8).
This option only applies to parsed input data, specifically GS1 Digital Link URIs. Since zero-suppressed GTINs are deprecated by the GS1 Digital Link standard, this option should only be enabled when it is necessary to accept legacy GS1 Digital Link URIs that carry zero-suppressed GTIN-14.
- Parameters
-
| v | true to accept zero-suppressed GTINs; false to require GTIN-14. |
- Exceptions
-
- See also
- permit_zero_suppressed_gtin_in_dl_uris()
| void gs1encoders::GS1Encoder::set_scan_data |
( |
const std::string & |
v | ) |
|
|
inline |
Process normalised scan data received from a barcode reader.
Parses scan data (such as the output of a barcode reader) with AIM Symbology Identifiers enabled, populates the input data buffer with the message received, and selects a symbology that is able to carry the received data. Performs syntax checks for GS1 Digital Link and AI data input.
Example scan data input: ]C1011231231231233310ABC123{GS}99TESTING where {GS} represents ASCII character 29 (the FNC1 / GS separator).
A literal "|" character may be included in the scan data to indicate the separation between the first and second messages that would be transmitted by a reader configured to return the composite component when reading EAN/UPC symbols.
- Note
- In some instances the symbology determined by this library will not match that of the image actually scanned: the AIM Symbology Identifier prefix does not always uniquely identify the source symbology. For example GS1-128 Composite symbols share the same identifier as the GS1 DataBar family, and will therefore be detected as such.
- Parameters
-
| v | the normalised scan data string, including the AIM Symbology Identifier prefix. |
- Exceptions
-
| GS1EncoderScanDataException | if the scan data cannot be processed (for example because the AIM identifier is missing or the embedded data fails validation). |
- See also
- scan_data()
-
sym()