kb wrote:
I'm implementing binary serialization for primitive data types both in
java and c++. Also I need to handle serialization/de-serialization
across java and c++ i.e. serialization from java and de-serialization
in c++ and vice-versa.
For this I need to decide an encoding for primitive data types which
is independent of language and platform. Does any one have some idea
about such an encoding format.
You might try DataInputStream and DataOutputStream. These classes allow
you to do basic binary IO on primitives and strings. Even if you do use
Serialization I think you'll end up overriding the serialization IO
methods and using Data*Stream classes to do the actual work.
<http://java.sun.com/docs/books/tutorial/essential/io/datastreams.html>
However, data streams won't do everything, like little endian formats.
For that, I think a ByteBuffer and associated classes are best.
<http://java.sun.com/javase/6/docs/api/java/nio/class-use/ByteBuffer.html>
Or just use the Data*Stream's and switch the bytes around. It is not
exactly difficult to code.