primitive version of TCP that works over serial and protects data integrity.
Primitive and protects data integrity don't really go together well.
At the very least, you'll need a start and end of packet marker that is unique, ie the rest of the data cannot duplicate these markers, which adds a layer of complication itself when dealing with binary data, and a checksum for the actual contents of the data packet.
You'll also have to decide how you want to handle the cases where the packet is compromised as well. You don't really have complete data integrity if you just ignore corrupted packets. The typical method of handling this is with some sort of Ack/Nak protocol. If data transmission isn't bandwidth constrained, a rather simple approach to implementing an Ack/Nak would be:
Sender transmits packet, and waits for an Ack or a Nak.
If no Ack/Nak is received within some timeout period, or a Nak is received, packet is retransmitted and Sender again waits for Ack/Nak.
If Ack is received, next packet is transmitted.
On the receiver side, if a valid packet is received, send an Ack, if a corrupted packet is detected, then send a Nak. Your corrupted packet detection will need to be fairly good for this to work well. For the most part, you just want to be able to detect missing start and end packet markers and verify checksum. Other potential data integrity checks would be a sequence number and/or packet length value added to the packet as well.