epc

package
v0.783.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package epc decodes GS1 Electronic Product Code (EPC) binary identifiers — the data on UHF RAIN RFID (EPC Gen2 / ISO 18000-63) tags used pervasively in retail item-level tagging and supply-chain logistics. It turns the 96-bit EPC read from a tag into the GS1 identifiers it encodes: the company prefix, item reference, serial number, the canonical EPC URIs, and the reconstructed GTIN-14.

This is a whole RFID band the toolkit did not decode: PromptZero covers HF (ISO 14443 / 15693 / NDEF) and LF (EM4100 / HID / FDX-B / T5577), but not the UHF EPC layer. Reading a UHF tag needs a RAIN reader (out of scope — hardware), but the EPC binary an operator captures decodes entirely offline and deterministically here.

Wrap-vs-native: native. The EPC binary is a fixed bit-field layout with a per-partition split table and a GS1 mod-10 check digit; no third-party dependency is warranted. The SGTIN-96 layout, the partition table, and the SGTIN→GTIN reconstruction are taken from the GS1 EPC Tag Data Standard and verified byte-for-byte against its canonical worked example — 3074257BF7194E4000001A85 → urn:epc:tag:sgtin-96:3.0614141.812345.6789 (company prefix 0614141, item reference 812345, serial 6789) — not recalled.

Covered: the complete set of 96-bit schemes — SGTIN-96 (0x30, retail item), SSCC-96 (0x31, logistics unit), SGLN-96 (0x32, location), GRAI-96 (0x33, returnable asset), GIAI-96 (0x34, individual asset), and GID-96 (0x35, the General Identifier with no GS1 key). Each is fully field-decoded and verified against a worked vector (SGTIN/SSCC additionally reconstruct the GTIN-14 / SSCC-18 with a recomputed mod-10 check digit; the partition-based schemes are anchored against the epc-encoding-utils library used as an oracle). Plus SGTIN-198 (header 0x36): the 198-bit SGTIN whose serial is an alphanumeric 7-bit-ASCII string rather than a numeric value (internal/ sgtin198.go). Unsupported (reported, not guessed): the other 198-bit variants (GRAI-170 / GIAI-202 / SGLN-195) and any header outside 0x30-0x36.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GIAI added in v0.471.0

type GIAI struct {
	Filter          int    `json:"filter"`
	Partition       int    `json:"partition"`
	CompanyPrefix   string `json:"company_prefix"`
	AssetReference  uint64 `json:"asset_reference"`
	TagURI          string `json:"tag_uri"`
	PureIdentityURI string `json:"pure_identity_uri"`
}

GIAI is a decoded GIAI-96 EPC.

type GID added in v0.470.0

type GID struct {
	GeneralManagerNumber uint64 `json:"general_manager_number"`
	ObjectClass          uint64 `json:"object_class"`
	SerialNumber         uint64 `json:"serial_number"`
	TagURI               string `json:"tag_uri"`
	PureIdentityURI      string `json:"pure_identity_uri"`
}

GID is a decoded GID-96 EPC (General Identifier).

type GRAI added in v0.471.0

type GRAI struct {
	Filter          int    `json:"filter"`
	Partition       int    `json:"partition"`
	CompanyPrefix   string `json:"company_prefix"`
	AssetType       string `json:"asset_type"`
	SerialNumber    uint64 `json:"serial_number"`
	TagURI          string `json:"tag_uri"`
	PureIdentityURI string `json:"pure_identity_uri"`
}

GRAI is a decoded GRAI-96 EPC.

type Result

type Result struct {
	Scheme       string   `json:"scheme"`
	SchemeHeader string   `json:"scheme_header"`
	SGTIN        *SGTIN   `json:"sgtin,omitempty"`
	SSCC         *SSCC    `json:"sscc,omitempty"`
	SGLN         *SGLN    `json:"sgln,omitempty"`
	GRAI         *GRAI    `json:"grai,omitempty"`
	GIAI         *GIAI    `json:"giai,omitempty"`
	GID          *GID     `json:"gid,omitempty"`
	Notes        []string `json:"notes,omitempty"`
}

Result is the decoded EPC.

func Decode

func Decode(b []byte) (*Result, error)

Decode decodes an EPC binary: a 96-bit (12-byte) EPC, or a 198-bit EPC (the word-aligned 25/26-byte form a RAIN reader emits) for SGTIN-198.

func DecodeHex

func DecodeHex(s string) (*Result, error)

DecodeHex decodes a hex-encoded EPC: a 96-bit EPC (24 hex digits) or a 198-bit SGTIN-198 (the word-aligned 50/52 hex-digit form). ':' / '-' / '_' / whitespace separators and an optional 0x prefix are tolerated.

type SGLN added in v0.471.0

type SGLN struct {
	Filter            int    `json:"filter"`
	Partition         int    `json:"partition"`
	CompanyPrefix     string `json:"company_prefix"`
	LocationReference string `json:"location_reference"`
	Extension         uint64 `json:"extension"`
	TagURI            string `json:"tag_uri"`
	PureIdentityURI   string `json:"pure_identity_uri"`
}

SGLN is a decoded SGLN-96 EPC.

type SGTIN

type SGTIN struct {
	TagSize       int    `json:"tag_size"` // 96 or 198
	Filter        int    `json:"filter"`
	Partition     int    `json:"partition"`
	CompanyPrefix string `json:"company_prefix"`
	ItemReference string `json:"item_reference"`
	// SerialNumber is the numeric serial of an SGTIN-96. SerialString is the
	// 7-bit-ASCII serial of an SGTIN-198; exactly one is meaningful per the
	// tag size.
	SerialNumber    uint64 `json:"serial_number,omitempty"`
	SerialString    string `json:"serial_string,omitempty"`
	GTIN14          string `json:"gtin14"`
	TagURI          string `json:"tag_uri"`
	PureIdentityURI string `json:"pure_identity_uri"`
}

SGTIN is a decoded SGTIN EPC (Serialised Global Trade Item Number), either the 96-bit form (numeric serial) or the 198-bit form (alphanumeric serial).

type SSCC added in v0.469.0

type SSCC struct {
	Filter          int    `json:"filter"`
	Partition       int    `json:"partition"`
	CompanyPrefix   string `json:"company_prefix"`
	SerialReference string `json:"serial_reference"`
	SSCC18          string `json:"sscc18"`
	TagURI          string `json:"tag_uri"`
	PureIdentityURI string `json:"pure_identity_uri"`
}

SSCC is a decoded SSCC-96 EPC (Serial Shipping Container Code).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL