如何将netty ByteBuf转换为String,反之亦然 [英] How to convert a netty ByteBuf to a String and vice versa

查看:901
本文介绍了如何将netty ByteBuf转换为String,反之亦然的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  public String toString(ByteBuf b)有一种将netty ByteBuf转换为String的方法, {

// return b enconded to a String
}

public Bytebuf ToByteBuff(String s){

//返回s解码为Bytebuf
}


解决方案

ByteBuf.toString(Charset) 转换为字符串。



您可以使用 String.getBytes(Charset) Unpooled.wrappedBuffer(byte []) 转换为ByteBuf。


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
}

解决方案

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

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

这篇关于如何将netty ByteBuf转换为String,反之亦然的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆