TagDataTranslation 4.0.0
dotnet add package TagDataTranslation --version 4.0.0
NuGet\Install-Package TagDataTranslation -Version 4.0.0
<PackageReference Include="TagDataTranslation" Version="4.0.0" />
<PackageVersion Include="TagDataTranslation" Version="4.0.0" />
<PackageReference Include="TagDataTranslation" />
paket add TagDataTranslation --version 4.0.0
#r "nuget: TagDataTranslation, 4.0.0"
#:package TagDataTranslation@4.0.0
#addin nuget:?package=TagDataTranslation&version=4.0.0
#tool nuget:?package=TagDataTranslation&version=4.0.0
TagDataTranslation
Encode and decode GS1 EPC identifiers for RAIN (UHF) RFID tags. Convert between GTIN, SSCC, SGLN, and 50+ other formats — from barcode to EPC hex and back.
Implements the GS1 EPC Tag Data Standard (TDS) 2.3 and Tag Data Translation (TDT) 2.2 specifications. Used in production for RFID tag programming, inventory systems, and supply chain applications.
Try it online: https://www.mimasu.nl/tag-data-translation/try-online
Why This Library
- Spec-complete: All 50 EPC schemes including TDS 2.3 '+' and '++' variants with Digital Link URIs
- Deterministic: Every encode/decode is provably correct against the GS1 specification — no approximations, no guessing
- Fast: SGTIN-96 encode in 7.8 us, decode in 7.7 us (benchmarked on Apple M1 Pro)
- Cross-platform: .NET, JavaScript/TypeScript (WASM), Python, Swift, Kotlin, Flutter
- Production-ready: Exception-free
TryTranslateAPI for high-throughput tag programming and reading
Features
- GTIN to EPC encoding (SGTIN-96, SGTIN-198) and decoding
- SSCC, SGLN, GRAI, GIAI, GSRN, GDTI, SGCN, ITIP, GID, CPI, ADI, USDOD encoding
- GS1 Digital Link URI generation and parsing
- '++' schemes with custom hostname encoding for branded Digital Link URIs
- GS1 Company Prefix lookup
- Filter Value tables
- Hex to binary and binary to hex conversion
Platform Support
| Platform | Package | Status |
|---|---|---|
| .NET 8/9/10 | NuGet | Available |
| .NET MAUI (Android) | NuGet | Available (3.0.0+) |
| .NET MAUI (iOS) | NuGet | Available (3.0.0+) |
| .NET MAUI (macCatalyst) | NuGet | Available (3.0.0+) |
| JavaScript/TypeScript | npm | Available (3.0.0+) |
| Python | PyPI | Available (3.0.0+) |
| iOS (Swift) | Swift Package Manager | Available (3.0.0+) |
| Android (Kotlin/Java) | GitHub Packages | Available (3.0.0+) |
| Flutter (Dart) | pub.dev | Available (3.0.0+) |
Supported Schemes
| Scheme | Formats |
|---|---|
| SGTIN | SGTIN-96, SGTIN-198, SGTIN+, SGTIN++ |
| SSCC | SSCC-96, SSCC+, SSCC++ |
| SGLN | SGLN-96, SGLN-195, SGLN+, SGLN++ |
| GRAI | GRAI-96, GRAI-170, GRAI+, GRAI++ |
| GIAI | GIAI-96, GIAI-202, GIAI+, GIAI++ |
| GSRN | GSRN-96, GSRN+, GSRN++ |
| GSRNP | GSRNP-96, GSRNP+, GSRNP++ |
| GDTI | GDTI-96, GDTI-113, GDTI-174, GDTI+, GDTI++ |
| SGCN | SGCN-96, SGCN+, SGCN++ |
| ITIP | ITIP-110, ITIP-212, ITIP+, ITIP++ |
| GID | GID-96 |
| CPI | CPI-96, CPI-var, CPI+, CPI++ |
| ADI | ADI-var |
| USDOD | USDOD-96 |
| DSGTIN | DSGTIN+, DSGTIN++ |
'++' schemes (TDS 2.3) support lossless encoding of custom hostnames in EPC binary, enabling round-trip translation with branded Digital Link URIs like https://coca-cola.com/01/... instead of https://id.gs1.org/01/....
Installation
# .NET
dotnet add package TagDataTranslation
# JavaScript / TypeScript
npm install @mimasu/tdt
# Python
pip install tag-data-translation
# Swift (Package.swift)
.package(url: "https://github.com/dannyhaak/TagDataTranslation.git", from: "3.0.0")
# Flutter
flutter pub add tag_data_translation
The .NET package includes targets for .NET 8.0/9.0/10.0, Android, iOS, and macCatalyst. The npm package uses WebAssembly and works in Node.js and browsers.
Quick Start
Encode GTIN to Hex
using TagDataTranslation;
var engine = new TDTEngine();
string epcIdentifier = "gtin=00037000302414;serial=10419703";
string parameterList = "filter=3;gs1companyprefixlength=7;tagLength=96";
string binary = engine.Translate(epcIdentifier, parameterList, "BINARY");
string hex = engine.BinaryToHex(binary);
// hex = "30340242201d8840009efdf7"
Decode Hex to GTIN
var engine = new TDTEngine();
string binary = engine.HexToBinary("30340242201d8840009efdf7");
string bareId = engine.Translate(binary, "", "BARE_IDENTIFIER");
// bareId = "gtin=00037000302414;serial=10419703"
Get All Representations
var engine = new TDTEngine();
var result = engine.TranslateDetails("30340242201d8840009efdf7", "", "TAG_ENCODING");
Console.WriteLine($"Pure Identity: {result.Fields["pureIdentityURI"]}");
Console.WriteLine($"Tag URI: {result.Fields["tagURI"]}");
Console.WriteLine($"GTIN: {result.Fields["gtin"]}");
Console.WriteLine($"Serial: {result.Fields["serial"]}");
Digital Link Generation
using TagDataTranslation.DigitalLink;
var components = new DigitalLinkComponents
{
Domain = "id.gs1.org",
PrimaryKey = ("01", "00037000302414"), // AI 01 = GTIN
KeyQualifiers = new List<(string, string)>
{
("21", "10419703") // AI 21 = Serial
}
};
string digitalLink = DigitalLinkGenerator.Generate(components);
// https://id.gs1.org/01/00037000302414/21/10419703
Digital Link Parsing
if (DigitalLinkParser.TryParse("https://id.gs1.org/01/00037000302414/21/10419703", out var components))
{
Console.WriteLine($"GTIN: {components.PrimaryKey.Value}");
// GTIN: 00037000302414
}
GS1 Company Prefix Lookup
var engine = new TDTEngine();
var result = engine.GetPrefixLength("0037000302414");
Console.WriteLine($"Prefix: {result.Prefix}, Length: {result.Length}");
// Prefix: 0037000, Length: 7
Debugging Scheme Loading
var engine = new TDTEngine();
if (engine.LoadErrors.Count > 0)
{
foreach (var error in engine.LoadErrors)
{
Console.WriteLine(error);
}
}
API Reference
TDTEngine
Translate
public string Translate(string epcIdentifier, string parameterList, string outputFormat)
Translates an EPC identifier from one representation to another.
| Parameter | Description |
|---|---|
epcIdentifier |
The EPC to convert (binary string, hex, URI, or legacy format) |
parameterList |
Semicolon-delimited key=value pairs (see Parameter Keys below) |
outputFormat |
Target format (see Output Formats below) |
Returns: The converted EPC as a string.
Parameter Keys
Pass as semicolon-delimited key=value pairs, e.g. "filter=3;gs1companyprefixlength=7;tagLength=96".
| Key | Required | Description |
|---|---|---|
filter |
Encode only | Filter value. Determines packaging level (POS item, case, pallet, etc.). Range is scheme-dependent: 0-7 (3-bit, most schemes), 0-15 (4-bit, USDOD), or 0-63 (6-bit, ADI) |
gs1companyprefixlength |
Encode only | Length of the GS1 Company Prefix (6-12). Determines the partition table entry |
tagLength |
Encode only | Target tag length in bits (e.g., 96, 198). Selects the scheme variant |
dataToggle |
'+' / '++' encode only | AIDC data indicator (0 or 1). When 1, additional AI data follows the EPC in tag memory |
uriStem |
Optional | Custom URI stem for GS1_DIGITAL_LINK output (default: https://id.gs1.org). Example: uriStem=https://example.com |
When decoding (hex/binary input), no parameters are needed — the engine determines everything from the binary data.
Output Formats
| Format | Description | Example |
|---|---|---|
BINARY |
Binary bit string | 001100000011010000... |
TAG_ENCODING |
Tag URI with filter value | urn:epc:tag:sgtin-96:3.0037000.030241.10419703 |
PURE_IDENTITY |
Pure Identity URI (no filter) | urn:epc:id:sgtin:0037000.030241.10419703 |
BARE_IDENTIFIER |
Key=value pairs | gtin=00037000302414;serial=10419703 |
GS1_DIGITAL_LINK |
GS1 Digital Link URI | https://id.gs1.org/01/00037000302414/21/10419703 |
GS1_AI_JSON |
JSON object with AI keys | {"01":"00037000302414","21":"10419703"} |
TEI |
Text Element Identifier (ADI only) | ADI CAG 359F2/PNO PQ7VZ4/SEQ M37GXB92 |
Legacy alias (backward-compatible):
| Alias | Maps to |
|---|---|
LEGACY |
BARE_IDENTIFIER |
TranslateDetails
public TranslateResult TranslateDetails(string epcIdentifier, string parameterList, string outputFormat)
Same as Translate, but returns a TranslateResult object containing all extracted fields.
TryTranslate (Exception-Free)
public bool TryTranslate(string epcIdentifier, string parameterList, string outputFormat, out string? result, out string? errorCode)
Translates an EPC identifier without throwing exceptions. Ideal for high-throughput scenarios.
if (engine.TryTranslate(epcIdentifier, parameterList, "BINARY", out var result, out var errorCode))
{
Console.WriteLine($"Success: {result}");
}
else
{
Console.WriteLine($"Failed: {errorCode}");
}
TryTranslateDetails (Exception-Free)
public bool TryTranslateDetails(string epcIdentifier, string parameterList, string outputFormat, out TranslateResult? result, out string? errorCode)
Same as TryTranslate, but returns a TranslateResult object on success.
GetPrefixLength
public PrefixLengthResult GetPrefixLength(string input)
Looks up the GS1 Company Prefix length for a given identifier.
GetFilterValueTable
public Dictionary<int, string> GetFilterValueTable(string scheme)
Returns the filter value descriptions for a scheme (e.g., "SGTIN" returns {0: "All Others", 1: "POS Item", ...}).
LoadErrors
public IReadOnlyList<string> LoadErrors { get; }
Contains any errors encountered while loading scheme files. Inspect this after construction to debug missing or malformed schemes.
Helper Methods
public string HexToBinary(string hex) // Convert hex to binary string
public string BinaryToHex(string binary) // Convert binary string to hex
Exceptions
TDTTranslationException is thrown with one of these codes:
| Code | Description |
|---|---|
TDTFileNotFound |
Scheme definition file not found |
TDTFieldBelowMinimum |
Numeric field below minimum value |
TDTFieldAboveMaximum |
Numeric field above maximum value |
TDTFieldOutsideCharacterSet |
Field contains invalid characters |
TDTUndefinedField |
Required field is missing |
TDTSchemeNotFound |
No matching scheme found |
TDTLevelNotFound |
No matching level found |
TDTOptionNotFound |
No matching option found |
TDTLookupFailed |
External table lookup failed |
TDTNumericOverflow |
Numeric overflow occurred |
Performance
Benchmarked on Apple M1 Pro, .NET 8.0 (BenchmarkDotNet):
| Operation | Mean | Allocated |
|---|---|---|
| SGTIN-96 encode (GTIN → binary) | 7.8 us | 9.9 KB |
| SGTIN-96 decode (binary → GTIN) | 7.7 us | 9.2 KB |
| SGTIN++ encode (with hostname) | 24.3 us | 75.3 KB |
| SGTIN++ decode (with hostname) | 5.0 us | 7.8 KB |
| HexToBinary (96-bit) | 99 ns | 480 B |
| BinaryToHex (96-bit) | 54 ns | 192 B |
The engine uses compiled regex caching, pre-sorted scheme data, and lookup tables for hex/binary conversion. The TDTEngine constructor loads all schemes once; subsequent Translate() calls benefit from cached patterns and pre-computed data structures.
Run benchmarks yourself:
dotnet run -c Release --project test/TagDataTranslation.Benchmarks
Examples
See the examples/ directory for platform-specific sample projects:
examples/ConsoleApp/-- .NET console applicationexamples/MauiApp/-- .NET MAUI cross-platform app (Android, iOS, macCatalyst)examples/NodeApp/-- Node.js application (via WebAssembly)
License
This library is licensed under the Business Source License 1.1 (BSL 1.1).
- Non-production use (development, testing, evaluation) is free
- Production use requires a commercial license -- contact tdt@mimasu.nl
- Each version converts to Apache 2.0 four years after release
See LICENSING.md for full details.
The included JSON and XSD artifacts are (c) GS1 (https://www.gs1.org/standards/epc-rfid/tdt).
Use Cases
- Tag programming: Encode GTINs and SSCCs to EPC hex for writing to RAIN RFID tags
- Tag reading: Decode EPC hex from RFID readers back to human-readable identifiers
- Inventory systems: Translate between barcode and RFID representations
- Supply chain: Convert between GS1 Digital Link URIs and EPC binary
- Label printing: Generate EPC hex for RFID-enabled label printers (Zebra, SATO, etc.)
- Mobile RFID apps: Encode/decode on iOS and Android via native SDKs
Resources
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-android36.0 is compatible. net10.0-browser was computed. net10.0-ios was computed. net10.0-ios26.0 is compatible. net10.0-maccatalyst was computed. net10.0-maccatalyst26.0 is compatible. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
-
net10.0-android36.0
- No dependencies.
-
net10.0-ios26.0
- No dependencies.
-
net10.0-maccatalyst26.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.0 | 63 | 10/1/2026 |
| 3.0.7 | 10,978 | 3/3/2026 |
| 3.0.6 | 144 | 3/3/2026 |
| 3.0.5 | 162 | 2/26/2026 |
| 3.0.4 | 136 | 2/26/2026 |
| 3.0.3 | 159 | 2/25/2026 |
| 3.0.2 | 148 | 2/25/2026 |
| 3.0.1 | 153 | 2/25/2026 |
| 2.3.1 | 1,811 | 2/3/2026 |
| 2.3.0 | 398 | 2/2/2026 |
| 2.1.0 | 202 | 2/1/2026 |
| 2.0.1 | 210 | 2/1/2026 |
| 2.0.0 | 203 | 2/1/2026 |
| 1.1.5 | 98,362 | 12/9/2019 |
| 1.1.4 | 1,424 | 12/9/2019 |
| 1.1.3 | 1,463 | 12/9/2019 |
| 1.1.3-beta | 1,191 | 10/22/2019 |
| 1.1.2 | 1,688 | 10/22/2019 |
| 1.1.2-beta | 1,108 | 10/21/2019 |
| 1.1.1-beta | 1,268 | 5/22/2019 |
Version 3.0.0:
- Cross-platform SDK: added mobile target frameworks (Android, iOS, macCatalyst) for .NET MAUI
- Removed Console.WriteLine output (library-inappropriate for mobile/embedded)
- Added LoadErrors property for programmatic inspection of scheme loading failures
- Business Source License 1.1: free for non-production use, commercial license for production
Version 2.3.1:
- Improved TDTEngine reliability and error handling
- Fixed GRAI-96 scheme definition
- Code refactoring and cleanup
Version 2.3.0:
- Added TDS 2.3 support with 12 new '++' EPC schemes for custom hostname encoding
- New schemes: SGTIN++, DSGTIN++, SSCC++, SGLN++, GRAI++, GIAI++, GSRN++, GSRNP++, GDTI++, SGCN++, ITIP++, CPI++
- Hostname encoder with URN Code 40 and 7-bit ASCII with TLD optimizations
- Lossless encoding of custom domain names in Digital Link URIs
Version 2.1.0:
- Added TryTranslate and TryTranslateDetails methods for exception-free translation
- Ideal for high-throughput scenarios where exception overhead is a concern
Version 2.0.1:
- Added multi-targeting support for .NET 8.0, 9.0, and 10.0
Version 2.0.0:
- Upgraded to TDT 2.2 specification
- Replaced XML schemes with JSON schemes
- Added Digital Link URI generation and parsing
- Added new schemes: DSGTIN+, GDTI-113, and all + variants
- Added TDT Tables (B, E, F, K) support
- Updated GS1 Company Prefix list