TagDataTranslation 2.0.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package TagDataTranslation --version 2.0.0
                    
NuGet\Install-Package TagDataTranslation -Version 2.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TagDataTranslation" Version="2.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TagDataTranslation" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="TagDataTranslation" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TagDataTranslation --version 2.0.0
                    
#r "nuget: TagDataTranslation, 2.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TagDataTranslation@2.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TagDataTranslation&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=TagDataTranslation&version=2.0.0
                    
Install as a Cake Tool

TagDataTranslation

Tag Data Translation implemented according to the GS1 EPC Tag Data Translation 2.2 specification for RAIN RFID.

Online demo: https://www.mimasu.nl/tdt

Features

  • Full TDT 2.2 support with JSON-based scheme definitions
  • Digital Link URI generation and parsing
  • GS1 Company Prefix lookup
  • Filter Value tables

Supported Schemes

Scheme Formats
SGTIN SGTIN-96, SGTIN-198, SGTIN+ (Digital Link)
SSCC SSCC-96, SSCC+
SGLN SGLN-96, SGLN-195, SGLN+
GRAI GRAI-96, GRAI-170, GRAI+
GIAI GIAI-96, GIAI-202, GIAI+
GSRN GSRN-96, GSRN+
GSRNP GSRNP-96, GSRNP+
GDTI GDTI-96, GDTI-113, GDTI-174, GDTI+
SGCN SGCN-96, SGCN+
ITIP ITIP-110, ITIP-212, ITIP+
GID GID-96
CPI CPI-96, CPI-var, CPI+
ADI ADI-var
USDOD USDOD-96
DSGTIN DSGTIN+ (Digital Link only)

Installation

NuGet

dotnet add package TagDataTranslation

Or via Package Manager:

Install-Package TagDataTranslation

From Source

git clone https://github.com/dannyhaak/TagDataTranslation.git
cd TagDataTranslation/TagDataTranslation-C#/TagDataTranslation
dotnet build

Requirements

  • .NET 10.0 or later

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 parameterList = "tagLength=96";
string legacy = engine.Translate(binary, parameterList, "LEGACY");
// legacy = "gtin=00037000302414;serial=10419703"

Get All Representations

var engine = new TDTEngine();
var result = engine.TranslateDetails("30340242201d8840009efdf7", "tagLength=96", "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"]}");
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
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

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 (e.g., filter=3;gs1companyprefixlength=7;tagLength=96)
outputFormat Target format: BINARY, LEGACY, LEGACY_AI, TAG_ENCODING, PURE_IDENTITY

Returns: The converted EPC as a string.

TranslateDetails
public TranslateResult TranslateDetails(string epcIdentifier, string parameterList, string outputFormat)

Same as Translate, but returns a TranslateResult object containing all extracted fields.

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", ...}).

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

Building

cd TagDataTranslation-C#/TagDataTranslation
dotnet build
dotnet test ../TagDataTranslationUnitTest

Creating a NuGet Package

cd TagDataTranslation-C#/TagDataTranslation
dotnet pack -c Release

The package will be created in bin/Release/.

To publish to NuGet.org:

dotnet nuget push bin/Release/TagDataTranslation.*.nupkg --api-key YOUR_API_KEY --source https://api.nuget.org/v3/index.json

Version History

Version Changes
2.0.0 TDT 2.2 with JSON schemes, Digital Link support, new schemes (DSGTIN+, GDTI-113, etc.)
1.1.5 Updated GCP prefix file, ITIP encoding fixes
1.0.0 Initial release with TDT 1.6/1.11 support

License

This library is dual-licensed:

  • GNU Affero General Public License version 3 (AGPL-3.0)
  • Commercial license - contact tdt@dannyhaak.nl for details

The included JSON and XSD artifacts are (c) GS1 (https://www.gs1.org/standards/epc-rfid/tdt).

Resources

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.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
2.3.1 98 2/3/2026
2.3.0 92 2/2/2026
2.1.0 85 2/1/2026
2.0.1 89 2/1/2026
2.0.0 88 2/1/2026
1.1.5 80,654 12/9/2019
1.1.4 1,270 12/9/2019
1.1.3 1,288 12/9/2019
1.1.3-beta 1,147 10/22/2019
1.1.2 1,526 10/22/2019
1.1.2-beta 1,050 10/21/2019
1.1.1-beta 1,222 5/22/2019
1.1.0 1,803 2/3/2019
1.1.0-beta1 1,428 10/16/2018
1.0.2 3,480 10/8/2018
1.0.1 2,254 6/7/2018
1.0.0 2,129 3/9/2018
0.3.1 1,946 7/23/2017
0.3.1-beta 1,637 4/23/2017
0.2.1 2,220 10/19/2016
0.2.0 1,891 8/4/2016
0.1.0 6,455 5/30/2016

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