You might also want to consider looking up the subject of "ber tlv"
This is the data stream format used by the worlds financial processing network, and is the backbone behind Chip & Pin terminals, ATM's and many other banking systems.
The best part about it is it's very simple to use.
The T,L,V part stands for
The Tag is a numerical identifier that specify's the type of message, in your case if your just making use of the format, you can most likely define your own tags for this, but if you where actually handling real financial data you'd have to use the tag numbers defined in the standard.
The Length part is again simple, it specify's how many bytes of data the value part is, like any value the more bytes you allocate to the length, the longer your payload can be.
The Value part is then just the payload for your actual message, and how you format the bytes for this is entirely up to you.
Beacuse it's such a simple to decode/encode protocol (You can do it entirely using byte arrays) you can easily sent it over UDP using a very small, very fast packet size.
It's also suitable for streaming, and multiple messages can be sent back to back in a continuous non closing connection, which is quite ideal if you decide you must use TCP.
It would in theory work well over HTTP too using a web socket, but I've never actually tried that so I couldn't comment on how well.
As for libraries supporting it, last time I looked "Craig's Utility Library"
had very good support for TLV based structures in it, as do many of the smartcard libraries that are floating around (TLV is used on a lot of cards too)
If TLV is not your thing, then I'd definately back up what others have said and take a good close look at "Protobuf"
I don't know what language your working in, or even if what I'm about to post will be of any use to you :-) , but here goes anyway.
This is a TLV decoder (Note it has no encoding capabilities, but it should be easy to reverse it) I wrote back in 2008(ish) using C# , it was designed for decoding ber-tlv packets coming off a smart card in a payment terminal, but it might serve as a starting point for you to hack it into a more useful shape.
public class tlv
public int tag = 0;
public int length = 0;
public byte tagClass = 0;
public byte constructed = 0;
public List<byte> data = new List<byte>();
public class tlvparser
// List of found TLV structures
public List<tlv> tlvList = new List<tlv>();
public tlvparser(byte data)
if (data != null)
// Main parsing function
public void doParse(byte data)
int fulltag = 0;
int tlvlen = 0;
int dptr = 0;
while (dptr < data.Length)
byte temp = data[dptr];
int iclass = temp & 0xC0;
int dobj = temp & 0x20;
int tag = temp & 0x1F;
if (tag >= 31) // Using extracted vars, decide if tag is a 2 byte tag
fulltag = (temp << 8) + data[dptr + 1];
tlvlen = data[dptr + 2];
dptr += 3;
fulltag = temp;
tlvlen = data[dptr + 1];
dptr += 2;
}// End if tag 16 bit
if ((tlvlen & 128) == 128)
tlvlen = (tlvlen << 8) + data[dptr];
tlv myTlv = new tlv();
myTlv.tag = fulltag;
myTlv.length = tlvlen;
myTlv.tagClass = Convert.ToByte(iclass >> 6);
myTlv.constructed = Convert.ToByte(dobj >> 5);
for (int i = 0; i < tlvlen; i++)
if(dptr < data.Length)
if (myTlv.constructed == 1)
}// End main while loop
}// End constructor
}// end class tlvparser
}// end namespace
If it's of no use, then feel free to just ignore it.