5 lines
1.3 KiB
HTML
5 lines
1.3 KiB
HTML
<!doctype html><html lang="en"><meta charset="utf-8"><title>A byte stream needs framing</title><h1>A byte stream needs framing</h1><p>15-minute session: read for 3 minutes, trace for 3, experiment for 7, and complete the check for 2. Spend longer whenever you need.</p><p>A TCP read may return part of a message or several messages together. Define framing using a length, delimiter, or specified format. Validate maximum length before allocation and handle truncated input. The model parses a two-byte length prefix from fixed bytes; no network connection is made in the sandbox.</p><p><strong>Practice and evidence:</strong> Predict the example or draw its state transitions. Change one assumption, test the boundary, and record the actual result. Explain what this small model does not establish about a production system.</p><pre><code class="language-python">packet=bytes([0,3])+b"cat"
|
|
length=int.from_bytes(packet[:2],"big")
|
|
assert length<=100 and len(packet)-2==length
|
|
print(packet[2:].decode())
|
|
</code></pre><p><strong>Expected result:</strong> <code>cat</code></p><h3>Practice and evidence</h3><p>Keep three notes: your prediction, the actual result, and why they match or differ. The completion check grades understanding; the practice task builds skill.</p></html> |