所以通常我使用 Netty,它是 BigEndianHeapChannelBuffer 来接收 Java 中的 unsinged short(来自 c++ 软件)。当我这样做时:
buf.readUnsignedByte(); buf.readUnsignedByte();
它返回:
 149 and 00。直到现在一切都很好。因为服务器将 149 作为无符号短 [2 字节] 发送。
而不是这个,我想收到 unsigned short (重启我的应用程序后的ofc):
buf.readUnsignedShort(); 
神奇的事情发生了。它返回:38144。
下一步是检索无符号字节:
short type = buf.readUnsignedByte();
        System.out.println(type); 
它返回:1这是正确的输出。
谁能帮我解决这个问题?我看得更深,这就是 netty 所做的:
public short readShort() {
    checkReadableBytes(2);
    short v = getShort(readerIndex);
    readerIndex += 2;
    return v;
}
public int readUnsignedShort() {
    return readShort() & 0xFFFF;
}
但我仍然无法弄清楚出了什么问题。我希望能够阅读那 149。