I’m preparing to make the conversion from Serialization to my own lightweight “protocol,” which will initially be on top of TCP (may move to datagrams at some point in the future if there seems to be a need). In order to facilitate this changeover, I am going to have all of my classes which currently implement the Serializible interface to implement this:
public interface ActiveSerializable {
public void fillByteBuffer(ByteBuffer in);
public void readByteBuffer(ByteBuffer in);
}
Basically, the class uses fillByteBuffer to call in.putXXX() for each of its members and conversely calls in.getXXX() in readByteBuffer(). Assuming that I have an active TCP connection to my client, what’s the most efficient way to get this data through the Socket? I’m assuming that I should just call ByteBuffer.array() and then pop that through my OutputStream, but how do I delimit the messages? Anything else I need to watch out for?