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.
我正在开发一个项目,其中数据必须以二进制格式读取,但可以将其放入结构格式中。在Java结构中不可用。我已经以字节数组发送数据。它也有一些结构。
For Example
Packet
int length
int sequence no
MessageData
MessageData MessageHeader MessageBody
MessageData MessageHeader MessageBody
MessageHeader int data1 long data2 char[] data3//2bytes char[] data4//3 bytes
MessageHeader int data1 long data2 char [] data3 // 2bytes char [] data4 // 3个字节
Same for MessageBody
MessageBody也是如此
But data should be packed in byte array.
但是数据应该以字节数组打包。
One can do in CPP as
人们可以在CPP中做到
#pragma(2) //for word alignment
struct Packet{
int length
int sequence no
MessageData msgdata
}
I have to implement in java.
我必须在java中实现。
for reading data I am using Preon library
用于读取数据我正在使用Preon库
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
但是对于写入数据,我仍然使用常规方法在一些函数的帮助下打包字节数组中的数据任何人都有相同类型的项目工作或有更好的想法
1 个解决方案
#1
0
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);
#1
0
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);