Effecient way: Fixed size prefix length header Not effecient way: delimiter based, means we have to inspect every byte in the message as any one of them can be a delimiter.
Each byte reserves its highest bit as a continuation flag:
• 1: another byte follows. • 0: this is the last byte.
The other seven bits carry the number. For example, length 300:
Byte 1: 10101100 → continuation=1, data=44 Byte 2: 00000010 → continuation=0, data=2
44 + (2 × 128) = 300
The decoder reads one byte at a time until it sees a cleared continuation bit. Then it knows the length prefix is finished and the string bytes begin.