我需要一些关于如何在 Java / Android 中做某事的解释。我需要构造一个字节数组/数据包,以便我可以通过 http 请求发送它。我需要它看起来像这样:
- 3 bytes reserved (zero padded)
- 1 byte - Operation Group
- 1 byte - Packet type
- the rest depends on the above
但我不知道我怎么能这样构造byte[]
。
这是我尝试过的:
String padding = "0000000000"; // first part of packet
String group = "0xA"; // second part of packet
String type = "02"; // third part of packet
String content = "ThisIsATestStringWhichYouWillReadButItsADumbAssStringDudeSorryForYou"; // last part of packet
String wholePacket = padding.concat(group.concat(type.concat(content)));
Log.v("","wholePacket : "+wholePacket);
byte[] bytes = EncodingUtils.getBytes(wholePacket, "UTF-8");
有什么建议么?