Go Binary Protocols
From stream fragments to one complete frame with explicit buffer ownership.
1 / 9
From stream fragments to one complete frame with explicit buffer ownership.
AC 02 contributes 44 + (2 << 7) = 300.
00 or 01 is allowed.80 bytes: incomplete.80 bytes: malformed immediately.80 00: valid zero in this contract.For prefix 82 01, length is 130:
| Available bytes | Action |
|---|---|
82 |
Need more, consume 0 |
| Prefix + 40-byte body | Need more, consume 0 |
| Prefix + 130-byte body | Return body, consume 132 |
A retry receives the complete unconsumed buffer again.
maxLen?length > len(buf)-prefixBytes?prefixBytes + length can overflow if checked too early.
02 h i 01 ! contains two frames.
hi, consumed 3.!, consumed 2.nil,0,error.payload shares buf's backing array.85 01 encodes what length? What is the complete consumed count?
Why does [05] with limit 4 differ from [80] with the same limit?
Check the lesson's reasoning, implement the decoder, then take the checkpoint.