Really depends what is going to consume it. If you are exchanging data via websocket between two native apps (say a mobile java app and a c++ server) then something like protocol buffers is going to be pretty helpful. If the two apps are similar enough (say between two C++ apps) and the data structure is fairly simple you may even be able to just write the bytes and then cast on the other end.
If you are pushing binary data to a browser/javascript client, there are some built in features there for reading semi-formatted binary data. Specifically, take a look at ArrayBuffer and Typed Arrays / DataView.
In most browsers, binary data can be delivered either as a blob or as an ArrayBuffer. ArrayBuffer is used to read a raw byte sequence and is similar to a char array in c++. Typed Arrays let you overlay a fixed length format over the entire array, so if your array is of 32 bit signed ints you can overlay an Int32Array over the raw array buffer and pull out a sequence of signed 32 bit ints. A DataView is also overlaid over an ArrayBuffer but rather than using a uniform type it can be used to extract an arbitrary format (uint8, float32, int64, etc) at an arbitrary byte offset. For many situations this can be used to unpack a custom C++ struct. Typed Arrays and DataView can also be used to pack regular JS variables into a binary array for sending back to a C++ server.
Simple image transfer can be done by just sending uncompressed 8bpp buffers and then copying that into a canvas array. I’ve used this method for drawing realtime simulation visualizations, its fast, simple, maybe not the most bandwidth efficient. If you are sending compressed stuff, say PNG or JPEG, you’d want to use the blob method and Javascript has a createObjectURL that with a bit of additional glue can eat a blob of compressed image data and turn it into something that can be drawn to a canvas context.
If you have multiple different types of clients in different languages, something like protocol buffers gets a lot more useful. I haven’t looked, but there may be Javascript implementations of protocol buffers that would generate the TypedArrays/DataView code for you?
Peter