3

Netty's ChannelBuffer class provides convenient methods for reading unsigned types from a ChannelBuffer, however there don't appear to be any equivalent methods for writing unsigned types to a ChannelBuffer.

I feel like I must be missing something. What's the recommended approach for say, writing an unsigned integer to a ChannelBuffer?

Thanks!

HolySamosa
  • 9,011
  • 14
  • 69
  • 102
  • i think this may help you http://stackoverflow.com/questions/4266756/can-we-make-unsigned-byte-in-java – duanji Jan 07 '17 at 05:07

2 Answers2

3

If you want to write a 32-bit value its all the same.

channelBuffer.writeInt(my32bitValue);
Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • Consider: `long reallyBigUnsignedInt = inChannelBuffer.readUnsignedInt();` Assume that reallyBigUnsignedInt exceeds the maximum for a signed int. What's the best way to write this value to another ChannelBuffer as an unsigned int? Thanks! – HolySamosa Dec 23 '11 at 20:02
  • 2
    Ah, I see. Downcasting a large unsigned int stored as a long to an int "just works". – HolySamosa Dec 23 '11 at 21:31
  • A 32-bit value is a value which uses 4 byte, what you make of it unsigned, signed, float etc is up to you when you read it. – Peter Lawrey Dec 23 '11 at 22:21
0

i think this may help you Can we make unsigned byte in Java

you can just send msg like this.

byteBuf.writeByte(0x80);
Community
  • 1
  • 1
duanji
  • 1