I have a requirement when I need to transfer information through a wire (binary code via tcp) between two applications. One of them is in Java, and the other is in C ++. I need a protocol implementation to transfer objects between these two applications. Object classes are present in both applications (correspondingly mapped). I just need a coding scheme on the one hand, which stores the Object representation on the one hand and can be decoded on the other hand as a complete object.
For instance,
C ++ class
class Person
{
int age;
string name;
};
Java class
class Person
{
int age;
String name;
}
C ++ - coding
Person p;
p.age = 20;
p.name = "somename";
char[] arr = SomeProtocolEncoder.encode(p);
socket.send(arr);
Java decoding
byte[] arr = socket.read();
SomeProtocolIntermediateObject object = SomeProtocolDecoder.decode(arr);
Person p = (Person)ReflectionUtil.get(object);
The protocol should provide some intermediate object that maintains the representative state of the object, so that using reflection I can return the object later.