Parsing Shreds

This guide shows you how to parse the data shreds delivered by ShredStream.com, detect batch and slot boundaries, and reassemble complete block data. For the full binary layout, see Packet Format.

Extracting Fields

Every UDP packet is exactly 1203 bytes with variant 0xA5. The key fields you need for parsing are:

Field
Offset
How to Read

Slot

0x41

8-byte little-endian unsigned integer

Index

0x49

4-byte little-endian unsigned integer

Flags

0x55

Single byte, interpreted as a bitmask

Size

0x56

2-byte little-endian unsigned integer

Payload

0x58

Read exactly Size bytes starting at this offset

Detecting Batch Boundaries

The DATA_COMPLETE flag (0x40) in the flags byte signals the end of the current FEC set or entry batch. When you see this flag, you know that all data shreds for the current batch have been sent.

flags = packet[0x55]
is_batch_complete = (flags & 0x40) != 0

This is useful if you want to process entries incrementally rather than waiting for the entire slot to finish.

Detecting Slot Boundaries

The LAST_IN_SLOT flag (0x20) signals that this shred is the final data shred for the slot. Once you receive a shred with this flag set, the slot is complete and you can reassemble it.

Reassembling Entries

To reconstruct the full block data for a slot:

  1. Collect all shreds for the same slot number.

  2. Order them by the Index field (ascending).

  3. Concatenate their payloads in order.

The resulting byte stream is the slot's entry data.

Tip: Use a sorted data structure (like a BTreeMap in Rust or sorted keys in Python) so that ordering is handled automatically as shreds arrive.


Complete Examples

The examples below show end-to-end receivers that listen on a UDP socket, parse every incoming shred, accumulate payloads per slot, and print a summary when each slot is complete.

Python

Rust

TypeScript


Next Steps

  • Review Best Practices for tips on buffer sizing, loss detection, and production hardening.

  • See UDP Setup for network configuration and firewall requirements.

  • If packets are not arriving, check Troubleshooting.

Last updated

Was this helpful?