Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binary serialization protocol

I have a requirement where i need to transfer information through the wire(binary over tcp) between 2 applications. One is in Java and the other in C++. I need a protocol implementation to transfer objects between these 2 applications. The Object classes are present in both the applications (are mapped accordingly). I just need some encoding scheme on one side which retains the Object representation on one side and can be decoded on the other side as a complete Object.

For eg,

C++ class

class Person
{
   int age;
   string name;
};

Java class

class Person
{
   int age;
   String name;
}

C++ encoding

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 which maintains the object representational state so that using reflection i can get back the object later.

like image 910
user775757 Avatar asked Aug 26 '26 23:08

user775757


1 Answers

Sounds like you want Protobufs: http://code.google.com/apis/protocolbuffers/docs/tutorials.html

like image 66
Femi Avatar answered Aug 29 '26 13:08

Femi