Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a netty ByteBuf to a String and vice versa

Is there a way to convert a netty ByteBuf to a String and vice versa?

public String toString(ByteBuf b){

 //return b enconded to a String
}

public Bytebuf ToByteBuff(String s){

  //return s decoded to Bytebuf
}
like image 925
Kaleb Blue Avatar asked Oct 27 '16 15:10

Kaleb Blue


1 Answers

You can use ByteBuf.toString(Charset) to convert to string.

You can use String.getBytes(Charset) and Unpooled.wrappedBuffer(byte[]) to convert to ByteBuf.

like image 142
Chris O'Toole Avatar answered Sep 18 '22 12:09

Chris O'Toole