This beginner-level project simulates how binary data packets can be framed, written, and decoded just like real-world systems such as network protocols or embedded serial communication.
This is a foundation project I’ll be improving as I learn more about low-level programming, file handling, and protocols.
- Encodes data (int, float, string) into a binary file (
stream.bin) - Frames each packet using sync bytes (
0xAA,0x55) for easy detection - Includes a type tag, length, and checksum for validation
- Reads the file byte-by-byte, detecting packets and decoding them
fread(),fwrite()for binary file I/O- Unions, enums, structs for flexible data types
- Byte-by-byte stream decoding (like UART or TCP)
- Checksum validation for data integrity
- Safe copying of binary data using
memcpy()
Each packet in the binary stream has the following structure:
| Field | Size | Description |
|---|---|---|
| Sync 1 | 1 byte | 0xAA |
| Sync 2 | 1 byte | 0x55 |
| Type | 1 byte | 1 = int, 2 = float, 3 = string |
| Length | 1 byte | Number of bytes in payload |
| Payload | N bytes | Actual data |
| Checksum | 1 byte | XOR of all previous bytes |