Framing, flow control, and device switching
HSV Streaming defines how to send HSV over connections: WebSocket, TCP, serial. Framing with STX/ETX, flow control with XON/XOFF, chunked transfers with ETB/EM, device switching with DC2/DC4. Conforms to RFC 20.
Three forms:
[SOH] [header] [STX] [content] [ETX] Header + content
[STX] [content] [ETX] Content only
[SOH] [header] [STX] [ETX] Header only (empty content)
SOH starts a header. STX terminates the header and starts content. ETX ends the block.
This matches the original ASCII design: SOH begins routing/control info, STX marks where content begins, ETX marks the end.
STX/ETX frames content. Any payload format works:
# Plain text
[STX] Hello World [ETX]
# JSON
[STX] {"user": "alice", "action": "login"} [ETX]
# HSV records
[STX] name [US] Alice [RS] age [US] 30 [ETX]
# XML
[STX] <message>Hello</message> [ETX]
# Raw binary (DLE transparency)
[STX] [DLE] [STX] <raw PNG bytes> [DLE] [ETX] [ETX]
# Multi-line content (newlines are literal)
[STX] Line one
Line two
Line three [ETX]
# Code with special characters (no escaping needed)
[STX] if (x < 10 && y > 5) { return "yes"; } [ETX]
# Unicode, emoji, RTL, CJK (all valid)
[STX] Hello 世界! Привет мир! مرحبا 🎉🚀✨ [ETX]
# Math and symbols
[STX] ∀x ∈ ℝ: x² ≥ 0 ∧ √(x²) = |x| [ETX]
# Mixed scripts
[STX] English · Ελληνικά · עברית · 日本語 · 한국어 [ETX]
Any data format inside. Seven control characters pass through as literal data:
| Byte | Hex | Name | Use |
|---|---|---|---|
| BEL | 0x07 | Bell | Audible/visual alert |
| BS | 0x08 | Backspace | Cursor back, enables overwrite |
| TAB | 0x09 | Tab | Horizontal tab |
| LF | 0x0A | Line Feed | New line |
| VT | 0x0B | Vertical Tab | Vertical movement |
| FF | 0x0C | Form Feed | Page break |
| CR | 0x0D | Carriage Return | Return to line start |
These can be used for terminal animation or any application needing whitespace/formatting.
SOH starts a header, STX ends it:
[SOH] hsv [US] 1.0 [RS] type [US] request [STX] [content] [ETX] Header + content
[SOH] route [US] chat [RS] user [US] alice [STX] [content] [ETX] Routing + content
[SOH] ack [US] msg-123 [STX] [ETX] Header only (control message)
Headers use HSV structure ([US] for key-value, [RS] for properties). Applications define their own header schemas.
Server sends header on connect:
[SOH] hsv [US] 1.0 [RS] protocol [US] stream [STX] [ETX]
End session:
␄
␓ (0x13) XOFF - pause output
␑ (0x11) XON - resume output
␖ (0x16) Sync/keepalive
␆ Acknowledged
␕ Error/resend
␘ Cancel operation
␗ (0x17) End of block, more coming
␙ (0x19) End of medium, data exhausted
␗ for streaming large data. ␙ signals "no more data" (distinct from ␄ which ends the session).
Device Control characters for distributed architecture:
␒ (0x12) Connect to backend
␔ (0x14) Disconnect (return to lobby)
Example:
␒ chat [ETX] Connect to chat service
␔ Return to lobby
Enables edge + backend architecture where a lobby handles auth/routing and backends are private HSV servers.
| Category | Bytes | Count |
|---|---|---|
| Reserved (protocol) | 0x01-0x06 0x0E-0x19 0x1C-0x1F | 22 |
| Allowed (data) | BEL BS TAB LF VT FF CR | 7 |
| Forbidden | NUL (0x00), SUB (0x1A), ESC (0x1B) | 3 |
NUL (0x00) — C string terminator. Functions like strlen(), strcpy(), and most string APIs stop at NUL. Data gets silently truncated. Database fields, log entries, filenames — anything touching C code risks corruption. Even "safe" languages often use C libraries underneath.
SUB (0x1A) — Ctrl+Z, the DOS/Windows end-of-file marker. Open a file in text mode on Windows, and reading stops at 0x1A. Streams get truncated mid-transfer. Copy a file with SUB in it, get half a file. This isn't legacy — it's still the default behavior in 2026.
ESC (0x1B) — The escape character that starts terminal control sequences. An attacker who can inject ESC into your stream can: change terminal colors, move the cursor, clear the screen, redefine keys, and in some terminals execute arbitrary commands. Decades of CVEs. HSV forbids ESC entirely — if you need terminal control, use HSV's structured operations instead.
If your data contains these bytes, use binary mode (DLE transparency).
{"msg":"line 1\nline 2"}
{"code":"if (x < 3 \u0026\u0026 y > 5)"}
{"html":"\u003cdiv\u003eHello\u003c/div\u003e"}
[STX] {"msg":"line 1
line 2"} [ETX]
[STX] {"code":"if (x < 3 && y > 5)"} [ETX]
[STX] {"html":"Hello"} [ETX]
NDJSON requires escaping newlines, and JSON requires escaping <, >, & in strings. HSV frames the JSON—content passes through unchanged.
0x00 0x00 0x00 0x0C Hello World!
Must buffer entire message to know length.
Can't stream partial content.
Binary header not human-readable.
[STX] Hello World! [ETX]
Stream bytes as they arrive.
Send ␗ for partial chunks.
Inspect with any text tool.
Message framing only.
No routing metadata standard.
No acknowledgment protocol.
No backpressure signaling.
No chunked transfer.
[SOH] route [US] chat [STX] Hello! [ETX]
Routing in header, content in body.
␆ acknowledge, ␕ request resend.
␓ pause, ␑ resume.
␗ partial, ␙ complete.
WebSocket provides reliable transport. HSV adds application-level semantics: routing, acknowledgment, flow control, chunking.
[SOH] type [US] json [STX] {"x":1} [ETX]
[SOH] type [US] xml [STX] <x>1</x> [ETX]
[SOH] type [US] text [STX] Hello 🌍 [ETX]
[SOH] type [US] hsv [STX] x [US] 1 [ETX]
Framing is consistent
Payload format varies
Routing via headers
No escaping anywhere
HSV Streaming adds framing to any payload format. Content can contain newlines, quotes, emoji, any bytes except the 22 reserved.
| Transport | Example | Notes |
|---|---|---|
| WebSocket | wss://host/hsv | Browsers, compression via permessage-deflate |
| Raw TCP | host:8080 | Native clients, no HTTP overhead |
| Serial | Direct | Original intent of STX/ETX framing |
# Connect (header only)
[SOH] hsv [US] 1.0 [RS] protocol [US] chat [RS] user [US] alice [STX] [ETX]
# Send message (content only)
[STX] Hello everyone! [ETX]
# Receive message (header + content)
[SOH] from [US] bob [STX] Hi Alice! [ETX]
# Acknowledge
␆
# Disconnect
␄
Simple request/response, pub/sub, or bidirectional — HSV Streaming provides the framing and flow control.