I'm trying to replace my string based protocol with one that uses protobuf. I serialize move command with:
Schema<MoveCommand> schema = RuntimeSchema.getSchema(MoveCommand.class);
ProtostuffIOUtil.toByteArray(this, schema, buffer)
And my hit command with:
Schema<Hitcommand> schema = RuntimeSchema.getSchema(Hitcommand.class);
ProtostuffIOUtil.toByteArray(this, schema, buffer)
This works without problems. When i serialize the result is a byte[], this data is send over and socket to a serversocket.
On the serverside i read out the byte[] array, but how can i determine the type of the object that is inside the byte[] array? (is it and HitCommand or a MoveCommand?)
I ask this because to deserialize i need a Schema and i can only create/get the schema when i know the class of the object that is inside the byte[] array.
With my old string protocol i just had the type of the message at the beginning of the string.
I suspect i'm missing something crucial.