BP BitPads Protocol

Enhancement Sub-Protocol v2.0 · Section 8 & 15

Nesting
& Overhead

Enhancement sequences may contain transmission structures within themselves. A formally specified parser stack tracks every nesting boundary and restores outer context on exit.

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.

The sub-protocol defines six nesting scenarios, two of which require parser stack operations. A ParserStateFrame 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.

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.

Six nesting scenarios: 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.

Section 8.5

Nesting Level Codes

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.

00
Depth 1 — Flat only, no nesting permitted
Layer 1 bits 9+12 = 00 · Constrained hardware · No stack allocated
01
Depth 2 — One level of nesting
Layer 1 bits 9+12 = 01 · Typical embedded device · Record-in-stream supported
10
Depth 4 — Up to four levels
Layer 1 bits 9+12 = 10 · Industrial controller · Sub-session + escalation chains
11
Extended — Nesting Declaration Extension byte follows Layer 1
Layer 1 bits 9+12 = 11 · Mission-critical or deep telemetry · Up to 15 levels declared

The Six Nesting Scenarios

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.

#
Scenario
Stack Push
Outer Pauses
Trigger
1
Record in Stream
YES
YES
Enhancement field 101 (component escalation) in any stream signal slot. Full BitPads Record delivered within active stream. Stack restores stream on close.
2
Sub-Session in Session
YES
YES
SOH + Continuation flag in P1 signal slot. Nested session with its own Layer 1, identity, domain, and permissions. Outer session suspended until EOT.
3
Compound in Escalated Record
Partial
Partial
1111 continuation marker in a BitLedger record delivered via component escalation. Compound close (bit 39=0) closes inner compound before the inner record closes.
4
Signal Sequence
NO
No
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.
5
Fragmented + Signal
Partial
No
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.
6
Context Update in Stream
NO
Brief
Enhancement field 111 + opcode byte in any active stream. DLE escape into context operation. Stream pauses two bytes; context updated in place; stream resumes.

Section 8.2 — 8.3

Parser Stack

Scenarios 1 and 2 require a parser stack — a last-in-first-out structure of ParserStateFrame 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.

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.

effective_depth = min(hardware_max, policy_max, negotiated_max)
hardware_max = floor(stack_memory_bytes / frame_size_bytes)
  64 bytes stack → hardware_max = 3 frames
256 bytes stack → hardware_max = 12 frames
1 KB stack → hardware_max = 51 frames
policy_max = declared in NestingPolicy dataclass
negotiated_max = min(sender_declared, receiver_declared)
negotiated via DC2 parameter in P1 slot

ParserStateFrame Structure

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.

── ParserStateFrame ────────────────────────────────────────
outer_mode int # WAVE/RECORD/STREAM/COMMAND/CONTEXT
outer_category int # category code 0–15
outer_slot_position int # slot P1–P13 at time of interrupt
outer_component_flags int # which components remain unread
── Signal sequence state ────────────────────────────────────
signal_sequence_open bool # was a C=1 sequence in progress?
signal_c0_code int # which C0 code was sequencing
signal_count int # how many signals received so far
── Stream state (if outer was a stream) ────────────────────
stream_bytes_remaining int # length countdown; 0 if not stream
stream_codebook int # active codebook index
stream_archetype int # active archetype code
stream_cipher_active bool # cipher shift flag
── Session / batch context ──────────────────────────────────
scaling_factor_index int # current SF
decimal_position int # current D
optimal_split int # current S
currency_code int # current currency/qty type
── Enhancement and continuation ─────────────────────────────
enhancement_active bool # was grammar active?
meta_continuation bool # was Meta byte bit 3 = 1?
resume_byte_offset int # stream position to resume from
── Frame size: ~20 bytes on 32-bit embedded device ──────────

Stack Push — Component Escalation

When enhancement field 101 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.

── PUSH — Component Escalation (Record in Stream) ──────────
# Trigger: enhancement field 101 in stream signal slot
frame = ParserStateFrame(
outer_mode = session.current_mode,
outer_category = session.current_category,
outer_slot_position = session.current_slot,
outer_component_flags = session.remaining_components,
stream_bytes_remaining = session.stream_counter,
stream_codebook = session.active_codebook,
stream_archetype = session.active_archetype,
stream_cipher_active = session.cipher_active,
resume_byte_offset = session.stream_position,
... # all remaining fields
)
stack.push(frame) # returns False if at limit
session.current_mode = ParserMode.RECORD
session.inner_record_active = True
────────────────────────────────────────────────────────────
── POP — Inner Record Close ─────────────────────────────────
# Trigger: ETX/EOT in P8 slot or final component read
outer = stack.pop() # ProtocolError if empty (underflow)
session.current_mode = outer.outer_mode
session.stream_counter = outer.stream_bytes_remaining
session.active_codebook = outer.stream_codebook
session.stream_position = outer.resume_byte_offset
session.inner_record_active = False
# ... all fields restored from frame
── Return STATE 3F. Stream resumes. ─────────────────────────

Stack Push — Sub-Session

── PUSH — Sub-Session Open ──────────────────────────────────
# Trigger: SOH + Continuation flag in P1 slot
frame = build_full_session_frame(session)
stack.push(frame) # full session snapshot
session.current_mode = ParserMode.IDLE
session.sub_session_depth += 1
# Sub-session reads own Layer 1, has independent identity
── POP — Sub-Session Close (EOT) ────────────────────────────
outer = stack.pop()
restore_session_from_frame(session, outer)
session.sub_session_depth -= 1
── Outer session resumes exactly where it was. ──────────────

Overflow Policy

When a push is attempted at the stack limit, the overflow policy from the operator's NestingPolicy dataclass determines the response.

── Overflow Handling ────────────────────────────────────────
if overflow_policy == 'reject':
raise ProtocolError('Nesting limit exceeded')
elif overflow_policy == 'flatten':
emit_enhanced_c0(C0Code.NAK, flags=ParserFlags(continuation=True))
# treat inner structure as same level — no stack push
── Warning emitted at warn_at_depth (EM signal + Priority) ─

Context Preservation on Push and Pop

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.

Field On Push — Inner Gets On Pop — Outer Restored Note
sender_id Carries over Restored from frame Identity always preserved
domain Carries over Restored Inner re-declares if needed
permissions Carries over Restored Inner cannot exceed outer
scaling_factor Carries over Restored from frame Inner may re-declare
currency_code Carries over Restored from frame Same as SF
enhancement_active Carries over Restored Grammar state preserved
stream_counter Resets to 0 Restored from frame Inner has own length context
active_codebook Resets to 0 Restored from frame Inner starts with primary codebook
active_archetype Resets to 0 Restored from frame Inner starts with default archetype
cipher_active Resets to false Restored from frame Cipher must be re-declared in inner
compound_open Resets to false Restored from frame Inner compounds are independent
records_received Resets to 0 Not restored (outer kept) Inner record count is independent
signal_sequence_open Saved in frame Restored from frame Outer sequence resumes on close

Section 8.5

Nesting Declaration Extension

When the Layer 1 nesting code is 11 (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.

Nesting Declaration Extension Byte — appears when Layer 1 nesting code = 11
1–4 D Max
Depth
0–15
5 0 Overflow
Policy
6 0 Timeout
Active
7–8 T Timeout
Scale
Nesting depth (4 bits, 0–15 levels) Policy / control flags Timeout scale selector
Bits Field Values Description
1–4 Maximum Nesting Depth 0000–1111 Declares the maximum stack depth for this session. 0000 = flat only (no nesting). 1111 = 15 levels.
5 Overflow Policy 0 / 1 0 = reject — raise ProtocolError when limit reached. 1 = flatten — emit NAK and treat inner structure as same level without pushing stack.
6 Timeout Active 0 / 1 0 = no timeout; nested structures may remain open indefinitely. 1 = timeout enabled; scale defined in bits 7–8.
7–8 Timeout Scale 00–11 00 = none. 01 = seconds. 10 = transmission units. 11 = control bytes (protocol-controlled count).

Depth Negotiation at Session Open

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.

── Depth Negotiation — P1 Signal Slot ──────────────────────
# Step 1: Sender transmits Layer 1 with nesting code in bits 9+12
# Step 2: Receiver reads Layer 1, extracts sender_max
# Step 3: Receiver transmits DC2 + ACK in P1 slot
# parameter byte = receiver_max
# Step 4: Both sides compute:
agreed_depth = min(sender_max, receiver_max)
────────────────────────────────────────────────────────────
# If agreed_depth == 0:
emit_enhanced_c0(C0Code.EM, flags=ParserFlags(priority=True))
# "Nesting not permitted. Flat sessions only."
session.nesting_permitted = False

Section 10.2

Activation Scope Levels

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.

Scope Attachment Point Activation Mechanism Overhead Nesting Context
Session Layer 1 1 bit in Layer 1 session defaults 1 bit once; zero thereafter Enhancement active for all records and streams in the session. Full nesting depth available throughout.
Batch Layer 2 Set B 1 bit in Layer 2 reserved space 1 bit per batch header Enhancement applies to all records in the batch. Nesting resets at each batch boundary — depth counter clears when batch closes.
Category Category code Categories 1100, 1101, 1110 activate automatically Zero beyond category declaration Enhancement applies for the duration of the category structure. Category 1110 (Telegraph Emulation) opens a stream scope; nesting applies within that stream only.
Record Meta byte 2 bit 8 Signal Slot Presence byte follows Meta byte 2 1 byte when any slot active 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.
Inline Wave Meta byte 1 Category 1110 Wave with enhanced C0 bytes 1 Meta byte + N signal bytes Applies to the next enhanced C0 token only. No nesting — inline scope is a single-use enhancement burst (heartbeat, alert, flow control).

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.

Scope and depth interaction: 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.

Section 10.3

Industrial Strength Spectrum

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.

Level Name Features Active Overhead / Record Typical Use Case
0 No Enhancement Standard BitPads. No C0 grammar. No signal slots. 0 bytes Single-sensor IoT, heartbeat-only devices, constrained microcontrollers
1 Inline Signals Category 1110 Wave for pure control. Priority, ACK, Continuation flags on C0 signals. 1 Meta + N signal bytes per Wave Lightweight alerts, presence pulses, ACK-confirmed heartbeats
2 Record Signals All Level 1 features + Signal Slot Presence byte. Component boundary signalling per record. Slots P4–P8 available. 1 byte (presence) + 1 byte/slot active Multi-sensor reporting, confirmed delivery, record-level event annotation
3 Batch Enhancement All Level 2 features + Layer 2 batch flag. All records in batch can use signal slots. Zero per-record overhead. 0 bytes (1 bit paid at batch open) Industrial controller batches, mixed enhancement across a record group
4 Session Enhancement All Level 3 features + Layer 1 session flag. All 13 signal slots (P1–P13) available. Basic nesting depth declared in Layer 1 code. 0 bytes (1 bit paid at session open) Mission-critical telemetry, safety-critical links, high-BER environments
5 Full Telegraph Emulation 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. 0 bytes per record (session flag + 1 stream ctrl paid once) Rich binary telemetry, deep-space communication, legacy C0 system bridging
0
bytes — Level 0

No enhancement. Standard protocol validation only. Nothing spent.

1
bit — Level 3 & 4

Session or batch flag paid once. Zero overhead per record or batch thereafter.

1
byte — Level 2

Signal Slot Presence byte. Declares up to 5 slot positions in 8 bits. Paid once per record with any active slot.

20
bytes — frame size

Approximate size of one ParserStateFrame on a 32-bit embedded device. Stack memory determines hardware_max.

Section 15.1 — 15.2

Overhead Reference

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.

Per-Element Costs

Element Bits Bytes Frequency
Session enhancement flag (Layer 1) 1 <1 Once per session
Nesting Declaration Extension byte 8 1 Once per session (when depth > 4 declared, Layer 1 code = 11)
Signal Slot Presence byte (Meta2 bit8=1) 8 1 Once per record with any slot active
Individual signal slot — plain C0 (000 flag) 8 1 Per slot declared present
Individual signal slot — enhanced (001–111 flag) 8 1 Per slot declared present
Signal sequence continuation byte 8 1 Per additional signal in a C=1 sequence
Stream-Open Control byte (categories 1001/1110) 8 1 Once per stream
Context Declaration Block 8–32 1–4 Per context change (category 1101)
In-stream context opcode (field 111 + opcode) 16 2 Per in-stream context operation (DLE + opcode byte)

Overhead at Each Microservice Level

Level 0 — None
0 / 0 / 0 bytes
Level 1 — Inline
1 Meta + N signal
Level 2 — Record Signals
1B presence/record
Level 3 — Batch
1 bit/batch
Level 4 — Session
1 bit/session
Level 5 — Full Emulation
1 bit + 1 stream ctrl
Level Per Session Per Batch Per Record Per Signal
0 — None 0 0 0 N/A
1 — Inline 1 Meta byte 0 0 1 byte
2 — Record 0 0 1 byte (presence) 1 byte per slot
3 — Batch 1 bit (Layer 2) 0 0 1 byte per slot
4 — Session 1 bit (Layer 1) 0 0 1 byte per slot
5 — Full Emulation 1 bit + 1 stream ctrl 0 0 1 byte per signal

Nesting overhead: The Nesting Declaration Extension byte adds exactly 1 byte per session when depth beyond 4 is declared (Layer 1 code = 11). 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).

Section 15.3

Break-Even Analysis

At what transmission volume does enhancement grammar overhead pay for itself compared to application-layer alternatives?

The canonical comparison is between two approaches to conveying signal information alongside records: embedding a status byte at the application layer in every record (1 byte per record, always, in the payload), versus using the enhancement grammar at session scope (1 bit once at session open, then per-signal bytes only when a signal is actually sent).

Approach Comparison

Application-Layer Status Byte

  • 1 byte embedded in every record payload, every time
  • Cost = N records × 1 byte = N bytes total
  • No protocol-level semantics — application must parse
  • No priority, ACK, or continuation flags
  • No signal slot positions — decoder cannot validate placement
  • Works on all receivers without protocol negotiation

Enhancement Grammar (Level 4 Session)

  • 1 bit at session open (in Layer 1)
  • 1 byte per signal slot only when the slot is active
  • Priority, ACK-request, Continuation flags at no extra byte cost
  • 13 named positions with structural validation
  • Nesting and component escalation available at Level 4
  • Requires protocol negotiation at session open

Break-Even Table

Assume a typical record where one signal is sent per record on average (e.g., an STX at component start plus an ETX at end = 2 signal bytes per record when active). Enhancement grammar pays for itself when session overhead amortises below the per-record application-layer cost.

Session size (records) App-layer cost (bytes) Enhancement L4 cost (bytes) Enhancement L2 cost (bytes) Winner
1 1 ≈0 (1 bit session flag) 1 (presence byte, no signals) Level 4 if signals needed; L0 if not
5 5 ≈0 session + 5 × signal bytes 5 (presence bytes only) Equal at low signal density
10 10 ≈0 session + actual signal bytes only 10 (presence) + actual signal bytes Level 4 cheaper when >1 slot/record
100 100 ≈0 session overhead; signals only on use 100 (presence bytes) + signal bytes Level 4 dominant — fixed cost amortised
1,000 1,000 ≈0 session overhead; structured signals 1,000 (presence) + signal bytes Level 4 decisive — structural semantics free

The formal break-even between session-scope (Level 4, 1 bit) and record-scope (Level 2, 1 byte per record) is at eight records. After eight records in a session, the session flag is always cheaper. Between batch-scope (Level 3, 1 bit per batch) and record-scope, break-even is also at eight records per batch. For any session with more than eight records requiring any enhancement, session-scope activation is the optimal choice.

break_even_L4_vs_L2 = 8 records
   Level 4 (1 bit session flag) becomes cheaper than Level 2 (1 byte/record) after 8 records.
break_even_L3_vs_L2 = 8 records per batch
   Batch flag (1 bit) cheaper than presence byte per record after 8 records/batch.
cost_app_layer_N = N × 1 byte
cost_enhancement_L4_N = ~0 + (active_slots × 1 byte)
   Enhancement grammar cheaper whenever active_slots/record < 1.0 on average.

For mixed sessions: When only occasional records need enhancement signals, record-scope (Level 2) keeps overhead exactly proportional to actual use. Level 4 pays its 1-bit session cost upfront — always justified when more than 8 records in the session will ever use any signal slot.

Engineering Application

Deployment Guidance

Select the industrial strength level that matches the application's reliability requirements, hardware constraints, and signal density. The table below provides canonical starting points. Profiles may be tuned in the NestingPolicy dataclass and session profile JSON for production deployments.

Level 0
Single-Sensor IoT
No Enhancement

One data source, no multi-signal coordination. Standard BitPads Wave or Record mode is sufficient. No C0 grammar active. Zero protocol overhead beyond the record itself. Constrained 8-bit microcontrollers with no stack to spare.

Level 1
Multi-Sensor Reporting
Inline Signals / Signal Slots

Multiple sensors in a batch or session need heartbeat confirmation and occasional priority alerts. Category 1110 Wave bursts handle the signalling. Signal slots in records confirm delivery of critical readings. Minimal overhead per record.

Level 2 – 3
Industrial Controller
Commands + Context Declarations

Discrete command sequences (Category 1100) and context declarations (Category 1101) alongside instrumentation records. Batch-scope enhancement activates once and covers all records in the batch. Component escalation for structured event delivery within a stream.

Level 4
Mission-Critical Telemetry
Session Enhancement + Nesting

All 13 signal slots active across the session. Record-in-stream nesting via component escalation. Sub-session-in-session for independent subsystem identity. Parser stack negotiated at session open. One bit pays for the entire session's signalling infrastructure.

Level 5
Rich Binary Communication
Full Telegraph Emulation

Category 1110 stream with full C0 enhancement grammar. Rolling codebook for stream semantic obscuration. Binary pictography for compact rich data. Nesting Declaration Extension byte for deep stack. Complete Murray-Baudot lineage with legacy receiver compatibility via the Plain Form Rule.

Level 4 + NDE
Deep Space / High-BER Links
Session + Extended Nesting Depth

Layer 1 session flag + Nesting Declaration Extension byte (code 11). Maximum depth declared up to 15 levels. Overflow policy set to flatten (not reject) for graceful degradation. ACK-chained signals at P1 for confirmed session open. Timeout scale set to control bytes for deterministic retry bounds.

NestingPolicy Configuration Reference

The NestingPolicy dataclass is stored in the session profile JSON. It is the single source of truth for nesting behaviour at runtime. All fields are operator-configurable.

── NestingPolicy Dataclass (default values) ────────────────
max_depth = 3 # effective stack depth (≤ hardware_max)
overflow_policy = 'reject' # 'reject' | 'flatten' | 'error'
timeout_enabled = False # timeout on nested structures
timeout_units = 30 # timeout value in chosen scale
── Per-type limits ──────────────────────────────────────────
max_record_in_stream = 2 # Records-in-stream per stream
max_session_in_session = 1 # Sub-sessions per session
max_signal_sequence_len= 8 # C=1 sequence length per slot
max_compound_depth = 4 # 1111-chain depth in escalated record
── Warning threshold ────────────────────────────────────────
warn_at_depth = 2 # emit EM + Priority at this stack depth
────────────────────────────────────────────────────────────
── Profile JSON representation ──────────────────────────────
"nesting": {
"max_depth": 3,
"overflow_policy": "reject",
"per_type": {
"record_in_stream": 2,
"session_in_session": 1,
"signal_sequence": 8,
"compound_depth": 4
},
"warn_at_depth": 2
}

Microservice principle: If the C0 Enhancement Module is not activated, a transmission is byte-for-byte identical to a standard BitPads transmission. The module adds no overhead to transmissions that do not use it. Every byte of overhead it adds is directly earning its cost by providing a signal, a confirmation, or a nesting boundary that the transmission explicitly needs.