在Netty 4.0中创建一个ByteBuf [英] Create a ByteBuf in Netty 4.0
本文介绍了在Netty 4.0中创建一个ByteBuf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
两个简单的问题,我无法在文档中解决这个问题:
Two simple questions, which I am not able to solve by ready in the documentation:
- 我有一个'byte []' 。
- 如何将其转换为ByteBuf?
- 如何将其转换为ByteBuf?
推荐答案
文档对我来说非常清楚:
创建缓冲区
建议使用 Unpoled中的辅助方法创建新缓冲区而不是调用单个实现的构造函数。
It is recommended to create a new buffer using the helper methods in Unpooled rather than calling an individual implementation's constructor.
然后在 Unpooled
,你有包装或复制的选择。例如:
Then in Unpooled
, you've got options of wrapping or copying. For example:
-
Unpooled.copiedBuffer(ByteBuffer)
-
Unpooled.copiedBuffer(字节[])
-
Unpooled.wrappedBuffer(ByteBuffer)
-
Unpooled.wrappedBuffer(byte[])$c$ c>
Unpooled.copiedBuffer(ByteBuffer)
Unpooled.copiedBuffer(byte[])
Unpooled.wrappedBuffer(ByteBuffer)
Unpooled.wrappedBuffer(byte[])
根据您是否希望在返回的中进行更改,选择适合的方法ByteBuf
将传递给原始字节数组/缓冲区。
Choose whichever method is appropriate based on whether you want changes made in the returned ByteBuf
to be passed through to the original byte array/buffer.
这篇关于在Netty 4.0中创建一个ByteBuf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文