# `Barcode`

What a barcode encodes, by its symbology: a GS1 retail code, Code 128's printable ASCII or a QR code's ISO 8859-1 text. Shown as its data.

[Commerce and logistics](types.md#commerce-and-logistics); not ordered; since Jadpo 0.1.0.

## Make one

Pick one of its variants and give its fields, `Barcode.ean13 { data: ... }`.

## Variants

| Variant | Fields |
|---|---|
| `ean13` | `data`: [`Ean13`](type-ean13.md) |
| `upc_a` | `data`: [`UpcA`](type-upc-a.md) |
| `code128` | `data`: `Text` |
| `qr_code` | `data`: `Text` |

## Text, JSON and storage

It has no single text form, so `text.from` and `text.parse` don't take it. JSON sends an object of its variant's name, as `tag`, and the variant's fields.

| JSON |
|---|
| `{"tag":"ean13","data":"4006381333931"}` |
| `{"tag":"upc_a","data":"036000291452"}` |
| `{"tag":"code128","data":"CTN-0042"}` |
| `{"tag":"qr_code","data":"https://example.com/a1"}` |

It is stored in 2 columns, each named for the field, `_` and its suffix. This is `{"tag":"code128","data":"CTN-0042"}`:

| Column | Type | Holds |
|---|---|---|
| `<field>_kind` | `text` | `'code128'` |
| `<field>_data` | `text` | `'CTN-0042'` |

## Shown to people

`text.format(value, locale:)` shows it to people in their locale.

With `locale: Locale.en_gb`:

| Value | Shown |
|---|---|
| `{"tag":"ean13","data":"4006381333931"}` | `4006381333931` |
| `{"tag":"upc_a","data":"036000291452"}` | `036000291452` |
| `{"tag":"code128","data":"CTN-0042"}` | `CTN-0042` |
| `{"tag":"qr_code","data":"https://example.com/a1"}` | `https://example.com/a1` |

## Operations

It has the contract's own operations: `text.format`, `json.read`, `json.write` and `==`. It isn't ordered, so `<` and sorting don't take it. [Every standard type meets one contract](../topics/every-standard-type-meets-one-contract.md) says how they work.
