非JAVA客户端与mina使用 PrefixedStringCodecFactory 通讯

与C++,C#不同,java的写入字节顺序是从高到低(左低到右高)

例如 内存数据:{ 0x67,0x45,0x23,0x01} ,java int值是:0x6745231 而C++是:0x1234567

这种差异会导致 非java客户端 解释 mina TCP header 时, 出现长度错误 ,所以要把java int长度转换成c++的

int cppInt=0x04000000;

byte[] targets = new byte[4];
targets[0] = (byte) (res & 0xff);// 最低位
targets[1] = (byte) ((res >> 8) & 0xff);// 次低位
targets[2] = (byte) ((res >> 16) & 0xff);// 次高位
targets[3] = (byte) (res >>> 24);// 最高位,无符号右移。

ByteBuffer buffer = ByteBuffer.wrap(bytes);
System.out.println(buffer.getInt());

输出 : 4