本文整理匯總了Java中io.netty.buffer.ByteBuf.arrayOffset方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteBuf.arrayOffset方法的具體用法?Java ByteBuf.arrayOffset怎麽用?Java ByteBuf.arrayOffset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.buffer.ByteBuf
的用法示例。
在下文中一共展示了ByteBuf.arrayOffset方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decode
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out)
throws Exception {
byte[] data;
int offset;
int length = msg.readableBytes();
if (msg.hasArray()) {
data = msg.array();
offset = msg.arrayOffset();
msg.skipBytes(length);
} else {
data = new byte[length];
msg.readBytes(data);
offset = 0;
}
out.add(Unpooled.wrappedBuffer(backend.unwrap(data, offset, length)));
}
示例2: decode
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
final byte[] array;
final int offset;
final int length = msg.readableBytes();
if (msg.hasArray()) {
array = msg.array();
offset = msg.arrayOffset() + msg.readerIndex();
} else {
array = new byte[length];
msg.getBytes(msg.readerIndex(), array, 0, length);
offset = 0;
}
if (extensionRegistry == null) {
if (HAS_PARSER) {
out.add(prototype.getParserForType().parseFrom(array, offset, length));
} else {
out.add(prototype.newBuilderForType().mergeFrom(array, offset, length).build());
}
} else {
if (HAS_PARSER) {
out.add(prototype.getParserForType().parseFrom(array, offset, length, extensionRegistry));
} else {
out.add(prototype.newBuilderForType().mergeFrom(array, offset, length, extensionRegistry).build());
}
}
}
示例3: decode
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
* 解碼
*
* @param in
* @return
* @throws Exception
*/
public static LibraMessage decode(ByteBuf in) throws Exception {
LibraMessage message = new LibraMessage();
message.setHead(LibraHead.decode(in));
short bodyLength = in.readShort();// 消息體的長度
if (bodyLength != in.readableBytes()) {
LibraLog.error("LibraMessage.decode is error! params:bodyLength:" + bodyLength + "\treadableLength:" + in.readableBytes());
return null;
}
ByteBuf bodyByteBuf = in.readBytes(in.readableBytes());
byte[] array;
// 反序列化數據的起始點
int offset;
// 可讀的數據字節長度
int readableLen = bodyByteBuf.readableBytes();
// 分為包含數組數據和不包含數組數據兩種形式
if (bodyByteBuf.hasArray()) {
array = bodyByteBuf.array();
offset = bodyByteBuf.arrayOffset() + bodyByteBuf.readerIndex();
} else {
array = new byte[readableLen];
bodyByteBuf.getBytes(bodyByteBuf.readerIndex(), array, 0, readableLen);
offset = 0;
}
// 反序列化
message.setBody(decodeBody(message.getHead().getProtocolID(), array, offset, readableLen));
return message;
}
示例4: heapBuffer
import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
* Listing 5.1
*/
public static void heapBuffer(ByteBuf heapBuf) {
if (heapBuf.hasArray()) {
System.out.println("has array");
byte[] array = heapBuf.array();
int offset = heapBuf.arrayOffset() + heapBuf.readerIndex();
int length = heapBuf.readableBytes();
System.out.println(offset+" " + length);
handleArray(array, offset, length);
}
}