I have two applications (one written in C++ and other in Java). I use msgpack
to pack the C++ class to the binary format. Then I send this to the Java side. I wonder if I unpack this message in java (using msgpack
too) do I get the correct Java class object?
Consider the following example:
// C++
class Foo
{
public:
// some methods here...
void Pack(uint8_t *data, size_t size);
private:
std::string m1_;
std::string m2_;
int m3_;
public:
MSGPACK_DEFINE(m1_, m2_, m3_);
}
void Foo::Pack(uint8_t *data, size_t size)
{
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, *this);
data = sbuf.data();
size = sbuf.size();
}
And Java side:
// Java
public class Foo
{
public void Unpack(byte[] raw, Foo obj)
{
MessagePack msgpack = new MessagePack();
try
{
obj = msgpack.read(raw, Foo.class);
// Does obj's m1_, m2_ and m3_ contains proper values from C++ class Foo?
}
catch(IOException ex)
{
// ...
}
}
// ...
private String m1_;
private String m2_;
private int m3_;
}
I don't want to pack the Foo's members one by one because I have a lot of them.
Thanks in advance.