-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenhancement-nesting.html
More file actions
1253 lines (1190 loc) · 63.9 KB
/
Copy pathenhancement-nesting.html
File metadata and controls
1253 lines (1190 loc) · 63.9 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Nesting & Overhead — BitPads Documentation</title>
<link rel="stylesheet" href="bp-style.css">
<style>
/* ── Page-specific ── */
/* Nesting scenario grid */
.scenario-grid {
display: flex; flex-direction: column; gap: 2px;
margin: 20px 0;
}
.scenario-row {
display: grid;
grid-template-columns: 28px 200px 72px 72px 1fr;
align-items: stretch;
border: 1px solid var(--rule-soft);
background: var(--bg-panel);
}
.scenario-row.header-row {
background: var(--bg-soft);
border-bottom: 2px solid var(--nasa-blue);
}
.sc-cell {
padding: 11px 14px;
border-right: 1px solid var(--rule-soft);
font-size: 13px; color: var(--ink-soft);
display: flex; align-items: center;
}
.sc-cell:last-child { border-right: none; }
.sc-cell.header {
font-family: var(--mono); font-size: 9px;
text-transform: uppercase; letter-spacing: 0.1em;
color: var(--ink-soft); font-weight: normal;
}
.sc-num {
font-family: var(--mono); font-size: 12px;
font-weight: 700; color: white;
background: var(--nasa-blue);
display: flex; align-items: center; justify-content: center;
flex-shrink: 0;
}
.scenario-row.no-push .sc-num { background: var(--ink-faint); }
.sc-name {
font-family: var(--display); font-weight: 600;
font-size: 14px; text-transform: uppercase;
letter-spacing: 0.04em; color: var(--ink);
}
.sc-badge {
font-family: var(--mono); font-size: 10px;
text-align: center; display: flex; align-items: center; justify-content: center;
}
.sc-badge.yes { color: var(--nasa-blue); font-weight: 700; }
.sc-badge.no { color: var(--ink-faint); }
.sc-badge.partial { color: var(--nasa-gold); }
/* Depth pyramid */
.depth-meter {
display: flex; flex-direction: column; gap: 3px;
margin: 20px 0; align-items: flex-start;
}
.dm-row {
display: flex; align-items: center; gap: 12px;
}
.dm-bar {
height: 28px; background: var(--nasa-blue);
border-right: 2px solid var(--nasa-gold);
display: flex; align-items: center;
padding: 0 14px;
font-family: var(--mono); font-size: 10px;
font-weight: 700; color: white;
flex-shrink: 0;
min-width: 40px; justify-content: center;
}
.dm-bar.level-1 { width: 90px; }
.dm-bar.level-2 { width: 160px; }
.dm-bar.level-4 { width: 230px; }
.dm-bar.level-ext { width: 300px; background: var(--bit-enhance); }
.dm-label {
font-size: 13px; color: var(--ink-soft);
}
.dm-code {
font-family: var(--mono); font-size: 10px;
color: var(--ink-faint);
}
/* Stack frame diagram */
.stack-visual {
display: flex; flex-direction: column; gap: 0;
margin: 20px 0; border: 1px solid var(--rule);
max-width: 520px;
}
.sv-frame {
background: var(--bg-panel);
border-bottom: 1px solid var(--rule-soft);
padding: 14px 18px;
border-left: 4px solid var(--nasa-blue);
}
.sv-frame.inner { border-left-color: var(--nasa-red); background: #FFF9F8; }
.sv-frame.empty {
background: var(--bg-soft);
border-left-color: var(--rule);
color: var(--ink-faint); font-family: var(--mono); font-size: 11px;
text-align: center; padding: 10px;
}
.sv-frame:last-child { border-bottom: none; }
.sv-frame-label {
font-family: var(--mono); font-size: 9px;
text-transform: uppercase; letter-spacing: 0.12em;
color: var(--nasa-red); margin-bottom: 6px;
}
.sv-frame .sv-frame-label { color: var(--nasa-blue); }
.sv-frame.inner .sv-frame-label { color: var(--nasa-red); }
.sv-fields {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 4px 16px;
font-family: var(--mono); font-size: 11px;
color: var(--ink-soft);
}
.sv-fields span { color: var(--nasa-blue); }
/* Overhead meter */
.overhead-meter {
margin: 24px 0;
display: flex; flex-direction: column; gap: 3px;
}
.om-row {
display: flex; align-items: center; gap: 12px;
}
.om-label {
font-family: var(--mono); font-size: 11px;
min-width: 200px; color: var(--ink-soft); flex-shrink: 0;
}
.om-bar-wrap {
flex: 1; height: 18px; background: var(--bg-soft);
border: 1px solid var(--rule-soft);
position: relative; overflow: hidden;
}
.om-bar {
height: 100%; background: var(--nasa-blue);
transition: width .5s;
}
.om-bar.secondary { background: var(--bit-enhance); }
.om-bar.minimal { background: var(--ink-faint); }
.om-bytes {
font-family: var(--mono); font-size: 11px;
color: var(--ink-faint); min-width: 80px;
text-align: right;
}
/* Break-even table highlight */
.be-win { background: #F0FAF2; }
.be-neutral { background: var(--bg-panel); }
.be-cost { background: #FDF5F0; }
/* Deployment card grid */
.deploy-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
gap: 1px; background: var(--rule);
border: 1px solid var(--rule); margin: 24px 0;
}
.deploy-card {
background: var(--bg-panel); padding: 22px;
}
.dc-level {
font-family: var(--mono); font-size: 9px;
text-transform: uppercase; letter-spacing: 0.12em;
color: var(--nasa-red); margin-bottom: 8px;
}
.dc-usecase {
font-family: var(--display); font-weight: 700;
font-size: 16px; text-transform: uppercase;
letter-spacing: 0.04em; margin: 0 0 8px;
color: var(--ink);
}
.dc-strength {
font-family: var(--mono); font-size: 11px;
color: var(--nasa-blue); margin-bottom: 8px;
}
.dc-reason {
font-size: 12.5px; color: var(--ink-soft);
line-height: 1.5; margin: 0;
}
/* Context preservation table compact */
.ctx-table {
width: 100%; border-collapse: collapse;
margin: 16px 0; font-size: 12.5px;
}
.ctx-table th {
font-family: var(--mono); font-size: 8.5px;
text-transform: uppercase; letter-spacing: 0.1em;
color: var(--ink-soft); padding: 8px 12px;
background: var(--bg-soft);
border-bottom: 2px solid var(--nasa-blue);
text-align: left; white-space: nowrap;
}
.ctx-table td {
padding: 9px 12px;
border-bottom: 1px solid var(--rule-soft);
vertical-align: top; line-height: 1.4;
color: var(--ink-soft);
}
.ctx-table td:first-child {
font-family: var(--mono); font-size: 11px;
color: var(--ink);
}
.ctx-table tr.carries td:last-child { color: var(--nasa-blue); }
.ctx-table tr.resets td:last-child { color: var(--nasa-red); }
</style>
</head>
<body>
<header class="topbar">
<div class="topbar-inner">
<a class="brand" href="index.html">
<span class="brand-mark">BP</span>
<span class="brand-name">BitPads Protocol</span>
</a>
<nav class="topnav">
<a href="overview.html">Overview</a>
<a href="bitpads-v2.html">BitPads v2</a>
<a href="bitledger.html" class="active">BitLedger</a>
<a href="universal-domain.html">Universal Domain</a>
<div class="nav-group">
<a href="enhancement-grammar.html">Enhancement</a>
<div class="nav-dropdown">
<a href="enhancement-grammar.html">Grammar & Signal Slots</a>
<a href="enhancement-commands.html">Commands & Context</a>
<a href="enhancement-telegraph-1.html">Telegraph Emulation I</a>
<a href="enhancement-telegraph-2.html">Telegraph Emulation II</a>
<a href="enhancement-nesting.html">Nesting & Overhead</a>
</div>
</div>
<a href="compound-mode.html">Compound Mode</a>
<a href="engineering.html">Engineering</a>
<a href="guide.html">Guide</a>
<a href="cli.html">CLI</a>
<a href="reference.html">Reference</a>
</nav>
</div>
</header>
<div class="page">
<aside class="sidebar">
<p class="toc-label">On This Page</p>
<ul class="toc">
<li><a href="#overview" class="active">Overview</a></li>
<li><a href="#nesting-levels">Nesting Level Codes</a></li>
<li><a href="#parser-stack">Parser Stack</a></li>
<li><a href="#declaration">Nesting Declaration</a></li>
<li><a href="#scope-levels">Scope Levels</a></li>
<li><a href="#industrial-strength">Industrial Strength</a></li>
<li><a href="#overhead">Overhead Tables</a></li>
<li><a href="#break-even">Break-Even Analysis</a></li>
<li><a href="#deployment-guidance">Deployment Guidance</a></li>
</ul>
</aside>
<main>
<!-- ── OVERVIEW ── -->
<section id="overview">
<p class="eyebrow">Enhancement Sub-Protocol v2.0 · Section 8 & 15</p>
<h1>Nesting<br>& Overhead</h1>
<p class="pullquote">Enhancement sequences may contain transmission structures within themselves. A formally specified parser stack tracks every nesting boundary and restores outer context on exit.</p>
<p class="lead">Nesting allows one BitPads structure — a stream, a record, a session — to contain another complete structure, suspending the outer context while the inner structure executes, then restoring the outer exactly.</p>
<p>The sub-protocol defines six nesting scenarios, two of which require parser stack operations. A <code>ParserStateFrame</code> captures the complete decoder context at the moment nesting is entered. The stack is last-in-first-out. On inner structure close, the frame is popped and the outer context is restored bit-for-bit. Maximum nesting depth is negotiated at session open from three independent limits: hardware capacity, operator policy, and the negotiated minimum of both endpoints.</p>
<p>Overhead is a first-class design concern throughout the sub-protocol. The enhancement grammar is a microservice: it adds zero overhead to transmissions that do not use it. For transmissions that do, overhead is exactly proportional to what is expressed — one byte per signal slot declaration, one bit per session-level activation.</p>
<div class="notice">
<p><strong>Six nesting scenarios:</strong> Record in Stream (stack push), Sub-Session in Session (stack push), Compound in Escalated Record (partial), Signal Sequence (no push — repetition at one position), Fragmented + Signal (partial), Context Update in Stream (no push — updates in place). This page covers the full stack specification and overhead accounting for all scenarios.</p>
</div>
</section>
<!-- ── NESTING LEVELS ── -->
<section id="nesting-levels">
<p class="eyebrow">Section 8.5</p>
<h2>Nesting Level Codes</h2>
<p>The device declares its nesting capability in Layer 1. Two non-contiguous bits in the Layer 1 session defaults — bits 9 and 12 — form a 2-bit nesting level code. This code communicates the maximum nesting depth the sender supports and triggers the Nesting Declaration Extension byte when depth beyond four levels is required.</p>
<div class="depth-meter">
<div class="dm-row">
<div class="dm-bar level-1">00</div>
<div>
<div class="dm-label">Depth 1 — Flat only, no nesting permitted</div>
<div class="dm-code">Layer 1 bits 9+12 = 00 · Constrained hardware · No stack allocated</div>
</div>
</div>
<div class="dm-row">
<div class="dm-bar level-2">01</div>
<div>
<div class="dm-label">Depth 2 — One level of nesting</div>
<div class="dm-code">Layer 1 bits 9+12 = 01 · Typical embedded device · Record-in-stream supported</div>
</div>
</div>
<div class="dm-row">
<div class="dm-bar level-4">10</div>
<div>
<div class="dm-label">Depth 4 — Up to four levels</div>
<div class="dm-code">Layer 1 bits 9+12 = 10 · Industrial controller · Sub-session + escalation chains</div>
</div>
</div>
<div class="dm-row">
<div class="dm-bar level-ext">11</div>
<div>
<div class="dm-label">Extended — Nesting Declaration Extension byte follows Layer 1</div>
<div class="dm-code">Layer 1 bits 9+12 = 11 · Mission-critical or deep telemetry · Up to 15 levels declared</div>
</div>
</div>
</div>
<h3>The Six Nesting Scenarios</h3>
<p>The sub-protocol formally defines six scenarios in which one transmission structure contains or overlaps another. Scenarios 1 and 2 are structural nesting requiring stack push and pop. Scenarios 3–6 are partial or non-structural.</p>
<div class="scenario-grid">
<div class="scenario-row header-row">
<div class="sc-cell header">#</div>
<div class="sc-cell header">Scenario</div>
<div class="sc-cell header">Stack Push</div>
<div class="sc-cell header">Outer Pauses</div>
<div class="sc-cell header">Trigger</div>
</div>
<div class="scenario-row">
<div class="sc-num">1</div>
<div class="sc-cell"><div class="sc-name">Record in Stream</div></div>
<div class="sc-cell sc-badge yes">YES</div>
<div class="sc-cell sc-badge yes">YES</div>
<div class="sc-cell">Enhancement field <code>101</code> (component escalation) in any stream signal slot. Full BitPads Record delivered within active stream. Stack restores stream on close.</div>
</div>
<div class="scenario-row">
<div class="sc-num">2</div>
<div class="sc-cell"><div class="sc-name">Sub-Session in Session</div></div>
<div class="sc-cell sc-badge yes">YES</div>
<div class="sc-cell sc-badge yes">YES</div>
<div class="sc-cell">SOH + Continuation flag in P1 signal slot. Nested session with its own Layer 1, identity, domain, and permissions. Outer session suspended until EOT.</div>
</div>
<div class="scenario-row">
<div class="sc-num">3</div>
<div class="sc-cell"><div class="sc-name">Compound in Escalated Record</div></div>
<div class="sc-cell sc-badge partial">Partial</div>
<div class="sc-cell sc-badge partial">Partial</div>
<div class="sc-cell">1111 continuation marker in a BitLedger record delivered via component escalation. Compound close (bit 39=0) closes inner compound before the inner record closes.</div>
</div>
<div class="scenario-row no-push">
<div class="sc-num">4</div>
<div class="sc-cell"><div class="sc-name">Signal Sequence</div></div>
<div class="sc-cell sc-badge no">NO</div>
<div class="sc-cell sc-badge no">No</div>
<div class="sc-cell">Continuation flag C=1 in any signal slot. Multiple enhanced C0 bytes at the same position. Repetition — not structural nesting. Receiver reads until C=0.</div>
</div>
<div class="scenario-row no-push">
<div class="sc-num">5</div>
<div class="sc-cell"><div class="sc-name">Fragmented + Signal</div></div>
<div class="sc-cell sc-badge partial">Partial</div>
<div class="sc-cell sc-badge no">No</div>
<div class="sc-cell">Meta bit 3=1 (BitPad fragment) simultaneously with C=1 in a signal slot. Both close independently. Meta bit 3=0 closes BitPad fragment; C=0 closes signal sequence.</div>
</div>
<div class="scenario-row no-push">
<div class="sc-num">6</div>
<div class="sc-cell"><div class="sc-name">Context Update in Stream</div></div>
<div class="sc-cell sc-badge no">NO</div>
<div class="sc-cell sc-badge partial">Brief</div>
<div class="sc-cell">Enhancement field <code>111</code> + opcode byte in any active stream. DLE escape into context operation. Stream pauses two bytes; context updated in place; stream resumes.</div>
</div>
</div>
</section>
<!-- ── PARSER STACK ── -->
<section id="parser-stack">
<p class="eyebrow">Section 8.2 — 8.3</p>
<h2>Parser Stack</h2>
<p>Scenarios 1 and 2 require a parser stack — a last-in-first-out structure of <code>ParserStateFrame</code> objects. Each frame is a complete snapshot of the decoder context at the moment nesting was entered: the outer mode, category, slot position, component flags remaining, all stream state, all session/batch context, and the enhancement grammar state. When the inner structure closes, the frame is popped and the outer context is restored exactly.</p>
<p>The effective stack depth is the minimum of three independent limits: the hardware capacity derived from available stack memory, the operator-configured policy maximum, and the agreed depth negotiated at session open via DC2 parameter exchange in the P1 slot.</p>
<div class="formula">
<span class="f-name">effective_depth</span> = min(<span class="f-var">hardware_max</span>, <span class="f-var">policy_max</span>, <span class="f-var">negotiated_max</span>)<br>
<span class="f-name">hardware_max</span> = floor(<span class="f-var">stack_memory_bytes</span> / <span class="f-note">frame_size_bytes</span>)<br>
<span class="f-note"> 64 bytes stack → hardware_max = 3 frames</span><br>
<span class="f-note"> 256 bytes stack → hardware_max = 12 frames</span><br>
<span class="f-note"> 1 KB stack → hardware_max = 51 frames</span><br>
<span class="f-name">policy_max</span> = declared in NestingPolicy dataclass<br>
<span class="f-name">negotiated_max</span> = min(<span class="f-var">sender_declared</span>, <span class="f-var">receiver_declared</span>)<br>
<span class="f-note"> negotiated via DC2 parameter in P1 slot</span>
</div>
<h3>ParserStateFrame Structure</h3>
<p>Each frame is approximately 20 bytes on a 32-bit embedded device. The stack memory formula follows directly from this: allocate stack bytes, divide by 20, floor to integer for hardware_max.</p>
<div class="printout">
<div class="ph">── ParserStateFrame ────────────────────────────────────────</div>
<div><span class="pl">outer_mode </span><span class="pv">int </span><span class="pc"># WAVE/RECORD/STREAM/COMMAND/CONTEXT</span></div>
<div><span class="pl">outer_category </span><span class="pv">int </span><span class="pc"># category code 0–15</span></div>
<div><span class="pl">outer_slot_position </span><span class="pv">int </span><span class="pc"># slot P1–P13 at time of interrupt</span></div>
<div><span class="pl">outer_component_flags </span><span class="pv">int </span><span class="pc"># which components remain unread</span></div>
<div class="ph">── Signal sequence state ────────────────────────────────────</div>
<div><span class="pl">signal_sequence_open </span><span class="pv">bool </span><span class="pc"># was a C=1 sequence in progress?</span></div>
<div><span class="pl">signal_c0_code </span><span class="pv">int </span><span class="pc"># which C0 code was sequencing</span></div>
<div><span class="pl">signal_count </span><span class="pv">int </span><span class="pc"># how many signals received so far</span></div>
<div class="ph">── Stream state (if outer was a stream) ────────────────────</div>
<div><span class="pl">stream_bytes_remaining </span><span class="pv">int </span><span class="pc"># length countdown; 0 if not stream</span></div>
<div><span class="pl">stream_codebook </span><span class="pv">int </span><span class="pc"># active codebook index</span></div>
<div><span class="pl">stream_archetype </span><span class="pv">int </span><span class="pc"># active archetype code</span></div>
<div><span class="pl">stream_cipher_active </span><span class="pv">bool </span><span class="pc"># cipher shift flag</span></div>
<div class="ph">── Session / batch context ──────────────────────────────────</div>
<div><span class="pl">scaling_factor_index </span><span class="pv">int </span><span class="pc"># current SF</span></div>
<div><span class="pl">decimal_position </span><span class="pv">int </span><span class="pc"># current D</span></div>
<div><span class="pl">optimal_split </span><span class="pv">int </span><span class="pc"># current S</span></div>
<div><span class="pl">currency_code </span><span class="pv">int </span><span class="pc"># current currency/qty type</span></div>
<div class="ph">── Enhancement and continuation ─────────────────────────────</div>
<div><span class="pl">enhancement_active </span><span class="pv">bool </span><span class="pc"># was grammar active?</span></div>
<div><span class="pl">meta_continuation </span><span class="pv">bool </span><span class="pc"># was Meta byte bit 3 = 1?</span></div>
<div><span class="pl">resume_byte_offset </span><span class="pv">int </span><span class="pc"># stream position to resume from</span></div>
<div class="ph">── Frame size: ~20 bytes on 32-bit embedded device ──────────</div>
</div>
<h3>Stack Push — Component Escalation</h3>
<p>When enhancement field <code>101</code> is encountered in a stream signal slot, the current parser context is captured into a frame and pushed onto the stack. The inner record then reads its own Meta bytes, Layer 1, and components independently.</p>
<div class="printout">
<div class="ph">── PUSH — Component Escalation (Record in Stream) ──────────</div>
<div><span class="pc"># Trigger: enhancement field 101 in stream signal slot</span></div>
<div><span class="pl">frame </span><span class="pv">= ParserStateFrame(</span></div>
<div><span class="pv"> outer_mode = session.current_mode,</span></div>
<div><span class="pv"> outer_category = session.current_category,</span></div>
<div><span class="pv"> outer_slot_position = session.current_slot,</span></div>
<div><span class="pv"> outer_component_flags = session.remaining_components,</span></div>
<div><span class="pv"> stream_bytes_remaining = session.stream_counter,</span></div>
<div><span class="pv"> stream_codebook = session.active_codebook,</span></div>
<div><span class="pv"> stream_archetype = session.active_archetype,</span></div>
<div><span class="pv"> stream_cipher_active = session.cipher_active,</span></div>
<div><span class="pv"> resume_byte_offset = session.stream_position,</span></div>
<div><span class="pv"> ... </span><span class="pc"># all remaining fields</span></div>
<div><span class="pv">)</span></div>
<div><span class="pg">stack.push(frame) # returns False if at limit</span></div>
<div><span class="pl">session.current_mode </span><span class="pv">= ParserMode.RECORD</span></div>
<div><span class="pl">session.inner_record_active </span><span class="pv">= True</span></div>
<div class="ph">────────────────────────────────────────────────────────────</div>
<div class="ph">── POP — Inner Record Close ─────────────────────────────────</div>
<div><span class="pc"># Trigger: ETX/EOT in P8 slot or final component read</span></div>
<div><span class="pg">outer = stack.pop() # ProtocolError if empty (underflow)</span></div>
<div><span class="pl">session.current_mode </span><span class="pv">= outer.outer_mode</span></div>
<div><span class="pl">session.stream_counter </span><span class="pv">= outer.stream_bytes_remaining</span></div>
<div><span class="pl">session.active_codebook </span><span class="pv">= outer.stream_codebook</span></div>
<div><span class="pl">session.stream_position </span><span class="pv">= outer.resume_byte_offset</span></div>
<div><span class="pl">session.inner_record_active </span><span class="pv">= False</span></div>
<div><span class="pc"># ... all fields restored from frame</span></div>
<div class="ph">── Return STATE 3F. Stream resumes. ─────────────────────────</div>
</div>
<h3>Stack Push — Sub-Session</h3>
<div class="printout">
<div class="ph">── PUSH — Sub-Session Open ──────────────────────────────────</div>
<div><span class="pc"># Trigger: SOH + Continuation flag in P1 slot</span></div>
<div><span class="pg">frame = build_full_session_frame(session)</span></div>
<div><span class="pg">stack.push(frame) # full session snapshot</span></div>
<div><span class="pl">session.current_mode </span><span class="pv">= ParserMode.IDLE</span></div>
<div><span class="pl">session.sub_session_depth </span><span class="pv">+= 1</span></div>
<div><span class="pc"># Sub-session reads own Layer 1, has independent identity</span></div>
<div class="ph">── POP — Sub-Session Close (EOT) ────────────────────────────</div>
<div><span class="pg">outer = stack.pop()</span></div>
<div><span class="pg">restore_session_from_frame(session, outer)</span></div>
<div><span class="pl">session.sub_session_depth </span><span class="pv">-= 1</span></div>
<div class="ph">── Outer session resumes exactly where it was. ──────────────</div>
</div>
<h3>Overflow Policy</h3>
<p>When a push is attempted at the stack limit, the overflow policy from the operator's <code>NestingPolicy</code> dataclass determines the response.</p>
<div class="printout">
<div class="ph">── Overflow Handling ────────────────────────────────────────</div>
<div><span class="pl">if overflow_policy == </span><span class="pg">'reject'</span><span class="pl">:</span></div>
<div><span class="pe"> raise ProtocolError('Nesting limit exceeded')</span></div>
<div><span class="pl">elif overflow_policy == </span><span class="pg">'flatten'</span><span class="pl">:</span></div>
<div><span class="pv"> emit_enhanced_c0(C0Code.NAK, flags=ParserFlags(continuation=True))</span></div>
<div><span class="pc"> # treat inner structure as same level — no stack push</span></div>
<div class="ph">── Warning emitted at warn_at_depth (EM signal + Priority) ─</div>
</div>
<h3>Context Preservation on Push and Pop</h3>
<p>Not all fields behave the same way at nesting boundaries. Some carry over into the inner structure; others reset. All are fully restored on pop.</p>
<table class="ctx-table">
<thead>
<tr>
<th>Field</th>
<th>On Push — Inner Gets</th>
<th>On Pop — Outer Restored</th>
<th>Note</th>
</tr>
</thead>
<tbody>
<tr class="carries">
<td>sender_id</td>
<td>Carries over</td>
<td>Restored from frame</td>
<td>Identity always preserved</td>
</tr>
<tr class="carries">
<td>domain</td>
<td>Carries over</td>
<td>Restored</td>
<td>Inner re-declares if needed</td>
</tr>
<tr class="carries">
<td>permissions</td>
<td>Carries over</td>
<td>Restored</td>
<td>Inner cannot exceed outer</td>
</tr>
<tr class="carries">
<td>scaling_factor</td>
<td>Carries over</td>
<td>Restored from frame</td>
<td>Inner may re-declare</td>
</tr>
<tr class="carries">
<td>currency_code</td>
<td>Carries over</td>
<td>Restored from frame</td>
<td>Same as SF</td>
</tr>
<tr class="carries">
<td>enhancement_active</td>
<td>Carries over</td>
<td>Restored</td>
<td>Grammar state preserved</td>
</tr>
<tr class="resets">
<td>stream_counter</td>
<td>Resets to 0</td>
<td>Restored from frame</td>
<td>Inner has own length context</td>
</tr>
<tr class="resets">
<td>active_codebook</td>
<td>Resets to 0</td>
<td>Restored from frame</td>
<td>Inner starts with primary codebook</td>
</tr>
<tr class="resets">
<td>active_archetype</td>
<td>Resets to 0</td>
<td>Restored from frame</td>
<td>Inner starts with default archetype</td>
</tr>
<tr class="resets">
<td>cipher_active</td>
<td>Resets to false</td>
<td>Restored from frame</td>
<td>Cipher must be re-declared in inner</td>
</tr>
<tr class="resets">
<td>compound_open</td>
<td>Resets to false</td>
<td>Restored from frame</td>
<td>Inner compounds are independent</td>
</tr>
<tr class="resets">
<td>records_received</td>
<td>Resets to 0</td>
<td>Not restored (outer kept)</td>
<td>Inner record count is independent</td>
</tr>
<tr class="carries">
<td>signal_sequence_open</td>
<td>Saved in frame</td>
<td>Restored from frame</td>
<td>Outer sequence resumes on close</td>
</tr>
</tbody>
</table>
</section>
<!-- ── DECLARATION BYTE ── -->
<section id="declaration">
<p class="eyebrow">Section 8.5</p>
<h2>Nesting Declaration Extension</h2>
<p>When the Layer 1 nesting code is <code>11</code> (bits 9 and 12 both set), a Nesting Declaration Extension byte follows Layer 1 immediately. This byte allows the sender to declare a precise depth up to 15 levels, select an overflow policy, and configure timeout behaviour — all in a single byte before the session begins handling records.</p>
<div class="bit-display">
<div class="bit-display-label">Nesting Declaration Extension Byte — appears when Layer 1 nesting code = 11</div>
<div class="bit-cells">
<div class="bit-cell enhance w4" data-layer="l2"
data-tooltip="Bits 1–4: Maximum nesting depth for this session. 0000=0 levels (flat), 0001=1 level … 1111=15 levels.">
<span class="bit-pos">1–4</span>
<span class="bit-val on">D</span>
<span class="bit-name">Max<br>Depth<br>0–15</span>
</div>
<div class="bit-cell mode" data-layer="l2"
data-tooltip="Bit 5: Stack overflow policy. 0 = reject (ProtocolError). 1 = flatten (NAK + treat as same level).">
<span class="bit-pos">5</span>
<span class="bit-val off">0</span>
<span class="bit-name">Overflow<br>Policy</span>
</div>
<div class="bit-cell mode" data-layer="l2"
data-tooltip="Bit 6: Timeout active. 0 = no timeout on nested structures. 1 = timeout enabled per timeout scale.">
<span class="bit-pos">6</span>
<span class="bit-val off">0</span>
<span class="bit-name">Timeout<br>Active</span>
</div>
<div class="bit-cell data w2" data-layer="l2"
data-tooltip="Bits 7–8: Timeout scale. 00 = none. 01 = seconds. 10 = units. 11 = control bytes.">
<span class="bit-pos">7–8</span>
<span class="bit-val off">T</span>
<span class="bit-name">Timeout<br>Scale</span>
</div>
</div>
<div class="bit-legend">
<span class="legend-item"><span class="legend-swatch enhance"></span> Nesting depth (4 bits, 0–15 levels)</span>
<span class="legend-item"><span class="legend-swatch mode"></span> Policy / control flags</span>
<span class="legend-item"><span class="legend-swatch data"></span> Timeout scale selector</span>
</div>
</div>
<table class="data-table" style="margin-top:8px;">
<thead>
<tr>
<th>Bits</th>
<th>Field</th>
<th>Values</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>1–4</code></td>
<td>Maximum Nesting Depth</td>
<td>0000–1111</td>
<td>Declares the maximum stack depth for this session. 0000 = flat only (no nesting). 1111 = 15 levels.</td>
</tr>
<tr>
<td><code>5</code></td>
<td>Overflow Policy</td>
<td>0 / 1</td>
<td>0 = reject — raise ProtocolError when limit reached. 1 = flatten — emit NAK and treat inner structure as same level without pushing stack.</td>
</tr>
<tr>
<td><code>6</code></td>
<td>Timeout Active</td>
<td>0 / 1</td>
<td>0 = no timeout; nested structures may remain open indefinitely. 1 = timeout enabled; scale defined in bits 7–8.</td>
</tr>
<tr>
<td><code>7–8</code></td>
<td>Timeout Scale</td>
<td>00–11</td>
<td>00 = none. 01 = seconds. 10 = transmission units. 11 = control bytes (protocol-controlled count).</td>
</tr>
</tbody>
</table>
<h3>Depth Negotiation at Session Open</h3>
<p>When sender and receiver declare different nesting limits, they negotiate at session open using the P1 signal slot. The agreed depth is the minimum of both declared values. Both sides must compute the same minimum — the protocol produces a single agreed depth with no ambiguity.</p>
<div class="printout">
<div class="ph">── Depth Negotiation — P1 Signal Slot ──────────────────────</div>
<div><span class="pc"># Step 1: Sender transmits Layer 1 with nesting code in bits 9+12</span></div>
<div><span class="pc"># Step 2: Receiver reads Layer 1, extracts sender_max</span></div>
<div><span class="pc"># Step 3: Receiver transmits DC2 + ACK in P1 slot</span></div>
<div><span class="pv"># parameter byte = receiver_max</span></div>
<div><span class="pc"># Step 4: Both sides compute:</span></div>
<div><span class="pl">agreed_depth </span><span class="pv">= min(sender_max, receiver_max)</span></div>
<div class="ph">────────────────────────────────────────────────────────────</div>
<div><span class="pc"># If agreed_depth == 0:</span></div>
<div><span class="pe"> emit_enhanced_c0(C0Code.EM, flags=ParserFlags(priority=True))</span></div>
<div><span class="pe"> # "Nesting not permitted. Flat sessions only."</span></div>
<div><span class="pl"> session.nesting_permitted </span><span class="pv">= False</span></div>
</div>
</section>
<!-- ── SCOPE LEVELS ── -->
<section id="scope-levels">
<p class="eyebrow">Section 10.2</p>
<h2>Activation Scope Levels</h2>
<p>The C0 Enhancement Module attaches at five scope levels. Each scope determines the activation mechanism, the overhead cost, and the lifetime of the enhancement context. Nesting depth interacts with scope: a session-scope activation permits nesting across all records in the session; a record-scope activation permits nesting only within the single record where the Signal Slot Presence byte is set.</p>
<table class="data-table">
<thead>
<tr>
<th>Scope</th>
<th>Attachment Point</th>
<th>Activation Mechanism</th>
<th>Overhead</th>
<th>Nesting Context</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Session</strong></td>
<td>Layer 1</td>
<td>1 bit in Layer 1 session defaults</td>
<td>1 bit once; zero thereafter</td>
<td>Enhancement active for all records and streams in the session. Full nesting depth available throughout.</td>
</tr>
<tr>
<td><strong>Batch</strong></td>
<td>Layer 2 Set B</td>
<td>1 bit in Layer 2 reserved space</td>
<td>1 bit per batch header</td>
<td>Enhancement applies to all records in the batch. Nesting resets at each batch boundary — depth counter clears when batch closes.</td>
</tr>
<tr>
<td><strong>Category</strong></td>
<td>Category code</td>
<td>Categories 1100, 1101, 1110 activate automatically</td>
<td>Zero beyond category declaration</td>
<td>Enhancement applies for the duration of the category structure. Category 1110 (Telegraph Emulation) opens a stream scope; nesting applies within that stream only.</td>
</tr>
<tr>
<td><strong>Record</strong></td>
<td>Meta byte 2 bit 8</td>
<td>Signal Slot Presence byte follows Meta byte 2</td>
<td>1 byte when any slot active</td>
<td>Enhancement applies within the single record. Signal slots P4–P8 may trigger nesting (e.g., component escalation at P6/P7) — but only while the record is being read.</td>
</tr>
<tr>
<td><strong>Inline Wave</strong></td>
<td>Meta byte 1</td>
<td>Category 1110 Wave with enhanced C0 bytes</td>
<td>1 Meta byte + N signal bytes</td>
<td>Applies to the next enhanced C0 token only. No nesting — inline scope is a single-use enhancement burst (heartbeat, alert, flow control).</td>
</tr>
</tbody>
</table>
<p>Scope levels nest inside each other in strict containment order. A record-scope activation sits inside a batch-scope session. A batch-scope activation sits inside a session-scope session. The parser stack honours containment: a stack push from a record-level escalation is unwound before the record's batch context is closed.</p>
<div class="notice">
<p><strong>Scope and depth interaction:</strong> For sessions with more than eight records where any record requires enhancement signals, session-scope activation (Level 4) is always cheaper than record-scope (Level 2) — the 1-bit session flag pays for itself at eight records and costs nothing per-record thereafter. For sparse enhancement needs, record-scope keeps overhead proportional to actual use.</p>
</div>
</section>
<!-- ── INDUSTRIAL STRENGTH ── -->
<section id="industrial-strength">
<p class="eyebrow">Section 10.3</p>
<h2>Industrial Strength Spectrum</h2>
<p>The sub-protocol defines six levels of enhancement activation forming a progressive capability spectrum. Level 0 is standard BitPads with no C0 grammar active. Level 5 is full Telegraph Emulation with session-wide enhancement, deep nesting, and the complete Murray-Baudot lineage. Each level is a strict superset of the level below it.</p>
<table class="data-table">
<thead>
<tr>
<th>Level</th>
<th>Name</th>
<th>Features Active</th>
<th>Overhead / Record</th>
<th>Typical Use Case</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>0</strong></td>
<td>No Enhancement</td>
<td>Standard BitPads. No C0 grammar. No signal slots.</td>
<td>0 bytes</td>
<td>Single-sensor IoT, heartbeat-only devices, constrained microcontrollers</td>
</tr>
<tr>
<td><strong>1</strong></td>
<td>Inline Signals</td>
<td>Category 1110 Wave for pure control. Priority, ACK, Continuation flags on C0 signals.</td>
<td>1 Meta + N signal bytes per Wave</td>
<td>Lightweight alerts, presence pulses, ACK-confirmed heartbeats</td>
</tr>
<tr>
<td><strong>2</strong></td>
<td>Record Signals</td>
<td>All Level 1 features + Signal Slot Presence byte. Component boundary signalling per record. Slots P4–P8 available.</td>
<td>1 byte (presence) + 1 byte/slot active</td>
<td>Multi-sensor reporting, confirmed delivery, record-level event annotation</td>
</tr>
<tr>
<td><strong>3</strong></td>
<td>Batch Enhancement</td>
<td>All Level 2 features + Layer 2 batch flag. All records in batch can use signal slots. Zero per-record overhead.</td>
<td>0 bytes (1 bit paid at batch open)</td>
<td>Industrial controller batches, mixed enhancement across a record group</td>
</tr>
<tr>
<td><strong>4</strong></td>
<td>Session Enhancement</td>
<td>All Level 3 features + Layer 1 session flag. All 13 signal slots (P1–P13) available. Basic nesting depth declared in Layer 1 code.</td>
<td>0 bytes (1 bit paid at session open)</td>
<td>Mission-critical telemetry, safety-critical links, high-BER environments</td>
</tr>
<tr>
<td><strong>5</strong></td>
<td>Full Telegraph Emulation</td>
<td>All Level 4 features + Category 1110 stream + extended nesting (Nesting Declaration Extension byte). All 29+4 agreed C0 codes. Rolling codebook. Binary pictography. Deep nesting.</td>
<td>0 bytes per record (session flag + 1 stream ctrl paid once)</td>
<td>Rich binary telemetry, deep-space communication, legacy C0 system bridging</td>
</tr>
</tbody>
</table>
<div class="stat-grid" style="margin-top:24px;">
<div class="stat-cell">
<div class="stat-val">0</div>
<div class="stat-unit">bytes — Level 0</div>
<p class="stat-desc">No enhancement. Standard protocol validation only. Nothing spent.</p>
</div>
<div class="stat-cell">
<div class="stat-val">1</div>
<div class="stat-unit">bit — Level 3 & 4</div>
<p class="stat-desc">Session or batch flag paid once. Zero overhead per record or batch thereafter.</p>
</div>
<div class="stat-cell">
<div class="stat-val">1</div>
<div class="stat-unit">byte — Level 2</div>
<p class="stat-desc">Signal Slot Presence byte. Declares up to 5 slot positions in 8 bits. Paid once per record with any active slot.</p>
</div>
<div class="stat-cell">
<div class="stat-val">20</div>
<div class="stat-unit">bytes — frame size</div>
<p class="stat-desc">Approximate size of one ParserStateFrame on a 32-bit embedded device. Stack memory determines hardware_max.</p>
</div>
</div>
</section>
<!-- ── OVERHEAD ── -->
<section id="overhead">
<p class="eyebrow">Section 15.1 — 15.2</p>
<h2>Overhead Reference</h2>
<p>The overhead model is strictly pay-for-what-you-use. Every byte of overhead directly earns its cost by providing a signal, a confirmation, or a nesting boundary that the transmission explicitly needs. Transmissions that do not use a feature pay nothing for it.</p>
<h3>Per-Element Costs</h3>
<table class="data-table">
<thead>
<tr>
<th>Element</th>
<th>Bits</th>
<th>Bytes</th>
<th>Frequency</th>
</tr>
</thead>
<tbody>
<tr>
<td>Session enhancement flag (Layer 1)</td>
<td>1</td>
<td><1</td>
<td>Once per session</td>
</tr>
<tr>
<td>Nesting Declaration Extension byte</td>
<td>8</td>
<td>1</td>
<td>Once per session (when depth > 4 declared, Layer 1 code = <code>11</code>)</td>
</tr>
<tr>
<td>Signal Slot Presence byte (Meta2 bit8=1)</td>
<td>8</td>
<td>1</td>
<td>Once per record with any slot active</td>
</tr>
<tr>
<td>Individual signal slot — plain C0 (<code>000</code> flag)</td>
<td>8</td>
<td>1</td>
<td>Per slot declared present</td>
</tr>
<tr>
<td>Individual signal slot — enhanced (<code>001–111</code> flag)</td>
<td>8</td>
<td>1</td>
<td>Per slot declared present</td>
</tr>
<tr>
<td>Signal sequence continuation byte</td>
<td>8</td>
<td>1</td>
<td>Per additional signal in a C=1 sequence</td>
</tr>
<tr>
<td>Stream-Open Control byte (categories 1001/1110)</td>
<td>8</td>
<td>1</td>
<td>Once per stream</td>
</tr>
<tr>
<td>Context Declaration Block</td>
<td>8–32</td>
<td>1–4</td>
<td>Per context change (category 1101)</td>
</tr>
<tr>
<td>In-stream context opcode (field <code>111</code> + opcode)</td>
<td>16</td>
<td>2</td>
<td>Per in-stream context operation (DLE + opcode byte)</td>
</tr>
</tbody>
</table>
<h3>Overhead at Each Microservice Level</h3>
<div class="overhead-meter">
<div class="om-row">
<div class="om-label">Level 0 — None</div>
<div class="om-bar-wrap"><div class="om-bar minimal" style="width:0%;"></div></div>
<div class="om-bytes">0 / 0 / 0 bytes</div>
</div>
<div class="om-row">
<div class="om-label">Level 1 — Inline</div>
<div class="om-bar-wrap"><div class="om-bar minimal" style="width:8%;"></div></div>
<div class="om-bytes">1 Meta + N signal</div>
</div>
<div class="om-row">
<div class="om-label">Level 2 — Record Signals</div>
<div class="om-bar-wrap"><div class="om-bar" style="width:22%;"></div></div>
<div class="om-bytes">1B presence/record</div>
</div>
<div class="om-row">
<div class="om-label">Level 3 — Batch</div>
<div class="om-bar-wrap"><div class="om-bar secondary" style="width:3%;"></div></div>
<div class="om-bytes">1 bit/batch</div>
</div>
<div class="om-row">
<div class="om-label">Level 4 — Session</div>
<div class="om-bar-wrap"><div class="om-bar secondary" style="width:2%;"></div></div>
<div class="om-bytes">1 bit/session</div>
</div>
<div class="om-row">
<div class="om-label">Level 5 — Full Emulation</div>
<div class="om-bar-wrap"><div class="om-bar secondary" style="width:5%;"></div></div>
<div class="om-bytes">1 bit + 1 stream ctrl</div>
</div>
</div>
<table class="data-table">
<thead>
<tr>
<th>Level</th>
<th>Per Session</th>
<th>Per Batch</th>
<th>Per Record</th>
<th>Per Signal</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>0 — None</strong></td>
<td>0</td>
<td>0</td>
<td>0</td>
<td>N/A</td>
</tr>
<tr>
<td><strong>1 — Inline</strong></td>
<td>1 Meta byte</td>
<td>0</td>
<td>0</td>
<td>1 byte</td>
</tr>
<tr>
<td><strong>2 — Record</strong></td>
<td>0</td>
<td>0</td>
<td>1 byte (presence)</td>
<td>1 byte per slot</td>
</tr>
<tr>
<td><strong>3 — Batch</strong></td>
<td>1 bit (Layer 2)</td>
<td>0</td>
<td>0</td>
<td>1 byte per slot</td>
</tr>
<tr>
<td><strong>4 — Session</strong></td>
<td>1 bit (Layer 1)</td>
<td>0</td>
<td>0</td>
<td>1 byte per slot</td>
</tr>
<tr>
<td><strong>5 — Full Emulation</strong></td>
<td>1 bit + 1 stream ctrl</td>
<td>0</td>
<td>0</td>
<td>1 byte per signal</td>
</tr>
</tbody>
</table>
<div class="notice">
<p><strong>Nesting overhead:</strong> The Nesting Declaration Extension byte adds exactly 1 byte per session when depth beyond 4 is declared (Layer 1 code = <code>11</code>). Stack push/pop operations have no wire overhead — they are decoder-side memory operations. The only wire cost of nesting is the signal that triggers it (1 byte for the component escalation enhancement field).</p>
</div>
</section>
<!-- ── BREAK-EVEN ── -->
<section id="break-even">
<p class="eyebrow">Section 15.3</p>
<h2>Break-Even Analysis</h2>
<p class="lead">At what transmission volume does enhancement grammar overhead pay for itself compared to application-layer alternatives?</p>