Create Framework for raw data or Binary read and write
I am working on one project in which data has to read in binary format but one can put into a structure format. In java Structure is not available. I have send the data in byte array. It also has some structure.
For Example
Packet
int length
int sequence no
MessageData
MessageData MessageHeader MessageBody
MessageHeader int data1 long data2 char[] data3//2bytes char[] data4//3 bytes
Same for MessageBody
But data should be packed in byte array.
One can do in CPP as
#pragma(2) //for word alignment
struct Packet{
int length
int sequence no
MessageData msgdata
}
I have to implement in java.
for reading data I am using Preon library
But for writing data I am still using normal method for packaging data in byte array with help of 开发者_高级运维some function Anybody have work on same kind project or have better idea
The current codebase does contain some bytes for writing data, however, it's not completed yet. Having said that, it might work for your current case:
Codec<Packet> codec = Codecs.create(Packet.class);
Packet packet = ...;
OutputStream out = ...;
codecs.encode(packet, codec, out);
精彩评论