From 7369eea2bd43b855b00e2a35c6f7047cc57983a4 Mon Sep 17 00:00:00 2001 From: Odyhibit Date: Thu, 21 May 2026 16:06:40 -0500 Subject: [PATCH 1/9] Version 3 --- README.md | 47 ++++--- decoder/index.html | 344 ++++++++++++++++++++++++++++++++++++++++++++- encoder/index.html | 182 ++++++++++++++---------- encoder/qrcode.js | 6 + shared/protocol.ts | 15 +- test/test.js | 63 +++++++++ 6 files changed, 545 insertions(+), 112 deletions(-) diff --git a/README.md b/README.md index 719cba6..32cd8bf 100644 --- a/README.md +++ b/README.md @@ -51,33 +51,34 @@ test/test.js Test suite (43 tests) Encoder and decoder pages bundle all dependencies locally — no CDN, no build step. They work from `file://`, GitHub Pages, or the dev server. -## Chunk protocol (v2) +## Chunk protocol (v3) -Each QR code contains a JSON chunk: +The encoder emits compact binary QR frames. The decoder still accepts the older JSON v1/v2 frames for compatibility. -```json -{ - "v": 2, "i": 0, "n": 17, - "hash": "a1b2c3d4", "name": "file.txt", - "gz": 1, "zip": 0, "rs": 1, "k": 7, "sz": 19721, - "t": "d", "d": "base64data..." -} +Frame layout: + +```text +"Q3" magic +flags byte: gzip, zip, Reed-Solomon, parity +frame index varint +total frame count varint +data frame count varint +binary frame body +``` + +Frame 0's body starts with transfer metadata, then binary payload bytes: + +```text +encoded payload size varint +original file size varint +frame 0 data byte count varint +FNV-1a hash uint32 +filename length varint +filename UTF-8 bytes +payload bytes ``` -| Field | Description | -|-------|-------------| -| `v` | Protocol version (2) | -| `i` | Chunk index (0-based) | -| `n` | Total chunks (data + parity) | -| `hash`| FNV-1a hash of original file | -| `name`| File name | -| `gz` | 1 if gzip-compressed | -| `zip` | 1 if zip archive | -| `rs` | 1 if Reed-Solomon enabled | -| `k` | Data chunk count (for RS) | -| `sz` | Original file size in bytes | -| `t` | `d` = data, `p` = parity | -| `d` | Base64 payload | +Other data frames contain only binary payload bytes. Parity frames contain Reed-Solomon parity bytes. Reed-Solomon protects data frame bodies, including frame 0 metadata, so a missing metadata frame can be recovered from parity. ## Testing diff --git a/decoder/index.html b/decoder/index.html index aba4c30..0782269 100644 --- a/decoder/index.html +++ b/decoder/index.html @@ -8,6 +8,7 @@ +