Binary serialization protocol

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.

+3
7

Google .

+1

Thrift - , . , , . (, zlib ssl). , , .

+1

:

- Thrift-vs-PB, . .

+1

amef, ++ amef,

    //Create a new AMEF object
    AMEFObject *object = new AMEFObject();

    //Add a child string object
    object->addPacket("This is the Automated Message Exchange Format Object property!!","adasd");   

    //Add a child integer object
    object->addPacket(21213);

    //Add a child boolean object
    object->addPacket(true);

    AMEFObject *object2 = new AMEFObject();
    string j = "This is the property of a nested Automated Message Exchange Format Object";
    object2->addPacket(j);
    object2->addPacket(134123);
    object2->addPacket(false);

    //Add a child character object
    object2->addPacket('d');

    //Add a child AMEF Object
    object->addPacket(object2);

    //Encode the AMEF obejct
    string str = new AMEFEncoder()->encode(object,false);

java ,

    byte arr = amef encoded byte array value;
    AMEFDecoder decoder = new AMEFDecoder()
    AMEFObject object1 = AMEFDecoder.decode(arr,true);

++, Java, , , , , . , .

+1

ASN.1?

, ( ). / .

+1

Java:

https://github.com/eishay/jvm-serializers/wiki

Some libraries also provide C ++ serialization. I have personally ported Python Construct to Java. If you have any interest, I will be happy to start a conversion project in C ++ and / or JavaScript!

0
source

All Articles