1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//! **A QR symbol, drawn by this crate** (ISO/IEC 18004): bytes in, a grid of
//! dark and light modules out.
//!
//! # Why it is here rather than in the lockfile
//!
//! The seat has to put a block of bytes on a screen where a phone camera can
//! read it. That is a QR symbol, and a QR symbol is a **fully specified
//! algorithm** — a field, a table, a zigzag and four scoring rules — rather
//! than a research problem or a moving target. The manifest's dependency set is
//! an approved list that a ball has to argue its way onto, and the argument for
//! adding one here would be that the standard is hard. It is not; it is long,
//! which is a different thing and one the 300-line cap already answers by
//! splitting it.
//!
//! # The seam, and what it deliberately does not know
//!
//! [`Symbol::encode`] takes `&[u8]`. It has no opinion about what the bytes
//! mean, what produced them or where the picture goes — which is what lets the
//! payload's own definition live somewhere else and change without touching any
//! of this.
//!
//! Out the other side is a square of booleans and its side length. Two things
//! render it: [`Symbol::block`] for a terminal, and the window, which paints
//! the modules as rectangles. Neither is the symbol, and the assertion in both
//! directions is over the **matrix** — a QR symbol has no glyphs, so the paint
//! probe (the crate's one walk over painted text) has nothing to say about one,
//! and pixels are the wrong altitude to be right at.
//!
//! # What it emits, stated once
//!
//! **Byte mode, correction level M, the smallest version that fits.** Byte mode
//! because the payload is bytes and the other modes buy density for content
//! this seat will never encode. The level is argued in [`version`]. The version
//! is a function of length, so the symbol is as small as the payload allows and
//! nothing chooses it by hand.
//!
//! The ceiling is version 40, which holds **2331 bytes** at this level, and
//! [`TooLong`] is what a payload over it gets — a value, named, never a panic.
use Plan;
/// The payload as a bit stream: header, padding, blocks and interleave.
/// The terminal rendering.
/// GF(2⁸) and the Reed-Solomon check bytes.
/// The eight masks and the four rules that choose between them.
/// The grid: furniture, the zigzag, and the eight candidates.
/// Size, block structure, and the two error-corrected headers.
/// **One QR symbol.** A square of modules, dark where the boolean is true, with
/// no quiet zone — the quiet zone is a property of where the symbol is *drawn*,
/// and a renderer that could not add four modules of margin could not draw the
/// symbol either.
/// The payload does not fit the largest symbol this encoder emits.
///
/// Written out rather than derived: this crate links no error-derive crate, and
/// one refusal with one sentence is not the argument for acquiring one.
/// The most bytes a symbol can carry here: version 40, correction level M.
const LIMIT: usize = 2331;