Type definitions in HSV format
| Mode | Header Contains | Behavior | Status |
|---|---|---|---|
| Open | No type definitions | Application defines meaning freely | ✓ v1.5 standard |
| Typed | Type definitions | Types MUST be enforced | beta |
Open mode is the default HSV behavior defined in the core spec. This page defines the beta Typed extension: if a header contains type definitions, conforming applications must validate data against them.
Type safety: Validation at parse time. Code generation for typed languages. Type coercion ("30" → integer 30).
Rich types: rational for exact fractions (1/2, 22/7)—no floating point errors. binary for raw bytes. Standard formats: email, uri, date, datetime, uuid.
Constraints: required, min, max, minlen, maxlen, pattern, enum, items.
Self-describing data: Schema travels with the data in the header. External schema references via URL. No separate schema file needed.
Structured content: HTML/XML-like content via namespace prefixes. No escaping for quotes, angles, ampersands.
Header defines structure, body contains data.
HSV uses HSV to describe HSV. Keys are field names, values are types:
[SOH] hsv [US] 1.5 [RS] hsv.typed [US] true [RS] name [US] string [RS] age [US] int [RS] email [US] string [STX] name [US] Alice [RS] age [US] 30 [RS] email [US] a@b.com [ETX]
| Header Key | Header Value | Data Key | Data Value |
|---|---|---|---|
name | string | name | Alice |
age | int | age | 30 |
email | string | email | a@b.com |
For richer type definitions, use nested values:
[SOH] hsv [US] 1.5 [RS] hsv.typed [US] true [RS] name [US] [SSA] type [US] string [RS] required [US] true [ESA] [RS] age [US] [SSA] type [US] int [RS] min [US] 0 [ESA] [RS] email [US] [SSA] type [US] string [RS] format [US] email [ESA] [STX] name [US] Alice [RS] age [US] 30 [RS] email [US] a@b.com [ETX]
Simple types use plain values (string, int). Constrained types use nested structures.
Typed mode is activated by an explicit declaration in the header—never by sniffing values for type-like names. Two ways to activate:
hsv.typed [US] true — inline schema: non-hsv.-prefixed header keys are field type definitionshsv.schema [US] <url> — external schema reference (implies typed mode)When typed mode is not declared, no header value is ever interpreted as a type—metadata like encoding [US] binary is never misread as a field-type declaration.
The hsv. key prefix is reserved for control and metadata. All keys starting with hsv. are protocol-level; all other keys in a typed header are field type definitions.
Reference an external schema with the reserved hsv.schema key:
[SOH] hsv [US] 1.5 [RS] hsv.schema [US] https://example.com/user.hsv [STX] name [US] Alice [RS] age [US] 30 [ETX]
The URL returns an HSV document whose header defines the schema.
Trade-off. External schema reference is the single construct where an HSV document is no longer self-contained—validation depends on a network fetch and inherits an availability and trust surface. Implementations should cache referenced schemas and consider pinning with an integrity hash (e.g., hsv.schema.hash [US] sha256:abc...). This is the one exception to the "debug with grep" guarantee.
| Type | Description | Example Values |
|---|---|---|
string | UTF-8 text (default) | Alice, hello world |
int | Integer | 42, -7 |
float | Floating point (IEEE 754) | 3.14, -0.5, 1.5e-10 |
rational | Exact fraction | 1/2, -3/4, 22/7 |
bool | Boolean | true, false |
array | GS-separated list | a [GS] b [GS] c |
object | Nested structure | SSA...ESA |
binary | DLE-transparent bytes | [DLE] [SPA] ... [DLE] [EPA] |
Fields can be absent or empty by default. Use required [US] true to mandate presence.
Encoding canonicality. In typed mode, each type maps to one normative construct: array ≡ GS-separated values, object ≡ SSA/ESA nesting. In open mode, the same structures are permissive—the consumer assigns meaning.
| Constraint | Applies To | Meaning |
|---|---|---|
required [US] true | Any | Key must be present (value may be empty) |
min [US] N | int, float, rational | Minimum value |
max [US] N | int, float, rational | Maximum value |
minlen [US] N | string, array | Minimum length |
maxlen [US] N | string, array | Maximum length |
pattern [US] regex | string | Must match regex |
format [US] name | string | Semantic format (see below) |
enum [US] a [GS] b [GS] c | Any | Value must be one of listed |
items [US] type | array | Type of array elements |
default [US] value | Any | Default if absent |
| Format | Description | Example |
|---|---|---|
email | Email address | user@example.com |
uri | URI/URL | https://example.com |
date | ISO 8601 date | 2026-01-27 |
time | ISO 8601 time | 14:30:00 |
datetime | ISO 8601 datetime | 2026-01-27T14:30:00Z |
uuid | UUID | 550e8400-e29b-41d4-a716-446655440000 |
base64 | Base64 encoded | SGVsbG8= |
An object field's type definition can carry a nested schema using SSA/ESA, recursively:
profile [US] [SSA] type [US] object [RS] fields [US] [SSA]
bio [US] string [RS]
location [US] [SSA] type [US] object [RS] fields [US] [SSA]
city [US] string [RS]
country [US] string
[ESA] [ESA]
[ESA] [ESA]
The fields constraint on an object type contains a nested set of field definitions using the same syntax as the top-level schema. This closes typed mode under nesting—the schema is fully self-hosting.
If fields is omitted from an object type, the nested content is accepted without validation (open sub-structure).
binary: Only required constraint applies. Content validation is application-defined.
A user record with typed schema in the header:
[SOH] hsv [US] 1.5 [RS] hsv.typed [US] true [RS]
id [US] [SSA] type [US] int [RS] required [US] true [RS] min [US] 1 [ESA] [RS]
name [US] [SSA] type [US] string [RS] required [US] true [RS] maxlen [US] 100 [ESA] [RS]
email [US] [SSA] type [US] string [RS] format [US] email [ESA] [RS]
role [US] [SSA] type [US] string [RS] enum [US] admin [GS] user [GS] guest [RS] default [US] user [ESA] [RS]
tags [US] [SSA] type [US] array [RS] items [US] string [ESA] [RS]
profile [US] object
[STX] id [US] 1 [RS] name [US] Alice [RS] email [US] alice@example.com [RS] role [US] admin [RS] tags [US] staff [GS] engineering [RS] profile [US] [SSA] bio [US] Engineer [RS] location [US] NYC [ESA] [ETX]
The header maps field names to their types. Simple fields use plain type names (object), constrained fields use nested definitions.
When a header contains type definitions, conforming applications must:
Data without typed headers is schema-free HSV—no validation required.
Standalone schema files (referenced via hsv.schema) contain only a header:
[SOH] hsv [US] 1.5 [RS] hsv.typed [US] true [RS]
id [US] [SSA] type [US] int [RS] required [US] true [ESA] [RS]
name [US] [SSA] type [US] string [RS] required [US] true [ESA] [RS]
email [US] [SSA] type [US] string [RS] format [US] email [ESA]
[STX] [ETX]
Empty body, schema in header. The file extension .hsv is sufficient.
Two modes, one format:
Schema syntax:
name [US] stringage [US] [SSA] type [US] int [RS] min [US] 0 [ESA]hsv.schema [US] https://...HSV Schema uses HSV format. Same parser, same benefits.