GS1.DataStructure (gs1_barcode v0.1.2)

View Source

Decoded GS1 Data Structure, encapsulating AIs, type, prefix, and original input.

Summary

Types

GS1 barcode symbology type.

t()

Decoded GS1 Data Structure.

Functions

Retrieves the data value associated with a specific AI. Returns nil if the AI is not present.

Returns the map of AI codes and their data values.

Returns the raw input of barcode.

Returns the FNC1 prefix binary (<<>> if none was found).

Checks if a specific Application Identifier (AI) code is present in the decoded data.

Creates a new DataStructure t/0 struct.

Returns barcode without FNC1 prefix.

Returns type of the barcode.

Types

barcode_type()

@type barcode_type() :: :gs1_datamatrix | :gs1_qrcode | :gs1_ean | :gs1_128 | :unknown

GS1 barcode symbology type.

  • :gs1_datamatrix - GS1 DataMatrix (2D)
  • :gs1_qrcode - GS1 QR Code (2D)
  • :gs1_ean - GS1 EAN/UPC (1D/linear)
  • :gs1_128 - GS1-128 (1D/linear, formerly UCC/EAN-128)
  • :unknown - unrecognized or missing symbology identifier

t()

@type t() :: %GS1.DataStructure{
  ais: %{required(String.t()) => String.t()},
  content: String.t(),
  fnc1_prefix: String.t(),
  type: barcode_type()
}

Decoded GS1 Data Structure.

Fields

  • content: input exactly as received, including prefix if exists.
  • type: barcode type (e.g., :gs1_datamatrix).
  • ais: A map of AI code (string) => data (string).
  • fnc1_prefix: The FNC1 prefix string (e.g., "]d2"), or "" if none was found.

Functions

ai(data_structure, code)

@spec ai(t(), String.t()) :: String.t() | nil

Retrieves the data value associated with a specific AI. Returns nil if the AI is not present.

ais(data_structure)

@spec ais(t()) :: %{required(String.t()) => String.t()}

Returns the map of AI codes and their data values.

content(data_structure)

@spec content(t()) :: String.t()

Returns the raw input of barcode.

fnc1_prefix(data_structure)

@spec fnc1_prefix(t()) :: String.t()

Returns the FNC1 prefix binary (<<>> if none was found).

has_ai?(data_structure, code)

@spec has_ai?(t(), String.t()) :: boolean()

Checks if a specific Application Identifier (AI) code is present in the decoded data.

new(content, type, fnc1_prefix, ais)

@spec new(String.t(), barcode_type(), String.t(), map() | keyword()) :: t()

Creates a new DataStructure t/0 struct.

The ais parameter is normalized to a map if a keyword list is provided.

payload(data_structure)

@spec payload(t()) :: String.t()

Returns barcode without FNC1 prefix.

type(data_structure)

@spec type(t()) :: barcode_type()

Returns type of the barcode.