我正试图找到 python 的 java 等价物
struct.unpack('hccccc',raw)
https://docs.python.org/2/library/struct.html
我怎样才能以干净的方式做到这一点?
最佳答案
JBBP library能帮上忙
byte [] data = new byte [] {1,2,3,4,5,6,7,8};
JBBPFieldStruct parsed = JBBPParser.prepare("short; ubyte [5];").parse(new ByteArrayInputStream(data));
System.out.println("short = "+parsed.findFieldForType(JBBPFieldShort.class).getAsInt());
System.out.println("array = "+Arrays.toString(parsed.findFieldForType(JBBPFieldArrayUByte.class).getArray()));
关于java - 如何将 python struct.unpack 转换为 java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29879009/