當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteBuf類代碼示例

本文整理匯總了Java中io.netty.buffer.ByteBuf的典型用法代碼示例。如果您正苦於以下問題:Java ByteBuf類的具體用法?Java ByteBuf怎麽用?Java ByteBuf使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ByteBuf類屬於io.netty.buffer包,在下文中一共展示了ByteBuf類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testDeserialize

import io.netty.buffer.ByteBuf; //導入依賴的package包/類
@Test
public void testDeserialize() throws Exception {
  ByteBuf buf = Unpooled.buffer(16);
  buf.writeInt(0);
  buf.writeInt(1);
  buf.writeLong(2);
  buf.writeLong(3);
  buf.writeInt(4);
  buf.writeInt(3);
  buf.writeInt(-1);
  buf.writeInt(-2);
  buf.writeInt(-3);
  serverDenseIntRow.deserialize(buf);
  assertEquals(serverDenseIntRow.getRowId(), 0);
  assertEquals(serverDenseIntRow.getClock(), 1);
  assertEquals(serverDenseIntRow.getStartCol(), 2);
  assertEquals(serverDenseIntRow.getEndCol(), 3);
  assertEquals(serverDenseIntRow.getRowVersion(), 4);
  assertEquals(serverDenseIntRow.getData().get(0), -1, 0.0);
  assertEquals(serverDenseIntRow.getData().get(1), -2, 0.0);
  assertEquals(serverDenseIntRow.getData().get(2), -3, 0.0);
}
 
開發者ID:Tencent,項目名稱:angel,代碼行數:23,代碼來源:ServerDenseIntRowTest.java

示例2: startBodyParse

import io.netty.buffer.ByteBuf; //導入依賴的package包/類
@Timed
void startBodyParse(ByteBuf in) throws UnknownFetchItemTypeException, IOException {
  skipControlCharacters(in);

  char c = ((char) in.readUnsignedByte());

  //String bodySection = ""; At some point we will need to actually store the body section that is being parsed below
  if (c != '[') {
    // This is effectively BODYSTRUCTURE which is not yet supported
    lineParser.parse(in);
    checkpoint(State.RESET);
    throw new UnknownFetchItemTypeException("BODYSTRUCTURE");
  } else {
    c = ((char) in.readUnsignedByte());
    while (c != ']') { // Skip characters within "[]"
      c = ((char) in.readUnsignedByte());
    }
  }

  checkpoint(State.FETCH_BODY);
}
 
開發者ID:HubSpot,項目名稱:NioImapClient,代碼行數:22,代碼來源:ResponseDecoder.java

示例3: encode

import io.netty.buffer.ByteBuf; //導入依賴的package包/類
/**
 * <b>一定要 {@link ByteBuf#release()}
 */
public static ByteBuf encode(RemotingCommand cmd) {
    int reqId = cmd.getOpaque();
    byte[] body = cmd.getBody();
    HashMap<String, String> msgs = cmd.getExtFields();
    byte[] append = JsonUtil.toBytes(msgs);
    int initialCapacity = 4 + 4 // total size+reqId
            + 4 + body.length // body
            + 4 + append.length;// apend
    ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer(initialCapacity);
    buf.writeInt(initialCapacity);
    buf.writeInt(reqId);
    buf.writeInt(body.length);
    buf.writeBytes(body);
    buf.writeInt(append.length);
    buf.writeBytes(append);

    return buf;
}
 
開發者ID:jiumao-org,項目名稱:wechat-mall,代碼行數:22,代碼來源:RemotingCommand.java

示例4: fromBytes

import io.netty.buffer.ByteBuf; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void fromBytes(ByteBuf buf) {
	short len = buf.readShort();
	byte[] compressedBody = new byte[len];

	for (short i = 0; i < len; i++) {
		compressedBody[i] = buf.readByte();
	}

	try {
		ObjectInputStream obj = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(compressedBody)));
		values = (Map<String, Object>) obj.readObject();
		obj.close();
	}
	catch (Exception e) {
		Throwables.propagate(e);
	}
}
 
開發者ID:p455w0rd,項目名稱:DankNull,代碼行數:20,代碼來源:PacketConfigSync.java

示例5: getJson

import io.netty.buffer.ByteBuf; //導入依賴的package包/類
public static String getJson(Object msg) {
    String json;
    try {
        ByteBuf buf = (ByteBuf) msg;
        byte[] bytes = new byte[buf.readableBytes()];
        buf.readBytes(bytes);
        json = new String(bytes);
    } finally {
        ReferenceCountUtil.release(msg);
    }
    return json;

}
 
開發者ID:yu199195,項目名稱:happylifeplat-transaction,代碼行數:14,代碼來源:SocketUtils.java

示例6: setData

import io.netty.buffer.ByteBuf; //導入依賴的package包/類
public void setData(ByteBuf buff) {
  if (data == null) {
    data = getByteBuf();
  }

  data.writeBytes(buff);
}
 
開發者ID:Nordstrom,項目名稱:xrpc,代碼行數:8,代碼來源:XrpcRequest.java

示例7: encode

import io.netty.buffer.ByteBuf; //導入依賴的package包/類
@Override
public void encode ( final ProtocolOptions options, final ByteBuf out )
{
    EncodeHelper.encodeHeader ( this, options, this.values.size (), this.header, out );

    this.startAddress.encode ( options, out );

    for ( final Value<Float> value : this.values )
    {
        TypeHelper.encodeFloatValue ( options, out, value, false );
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:13,代碼來源:MeasuredValueShortFloatingPointSequence.java

示例8: toBytes

import io.netty.buffer.ByteBuf; //導入依賴的package包/類
@Override
public void toBytes(ByteBuf buf)
{
    buf.writeByte(windowId);
    buf.writeByte(tank);
    NBTTagCompound fluidNbt = fluid == null ? null : fluid.writeToNBT(new NBTTagCompound());
    ByteBufUtils.writeTag(buf, fluidNbt);
}
 
開發者ID:cubex2,項目名稱:customstuff4,代碼行數:9,代碼來源:PacketSyncContainerFluid.java

示例9: decode

import io.netty.buffer.ByteBuf; //導入依賴的package包/類
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    if (in.readableBytes() < 8) {
        return;
    }

    short dataLen = in.getShort(in.readerIndex() + 6);
    if (in.readableBytes() < dataLen) {
        return;
    }

    ByteBuf msg = in.readRetainedSlice(8 + dataLen);
    out.add(msg);
}
 
開發者ID:szhnet,項目名稱:kcp-netty,代碼行數:15,代碼來源:TcpRttDecoder.java

示例10: add

import io.netty.buffer.ByteBuf; //導入依賴的package包/類
public RtMessageBuilder add(RtTag tag, RtMessage msg) {
  checkNotNull(tag, "tag must be non-null");
  checkNotNull(msg, "msg must be non-null");

  ByteBuf encoded = RtWire.toWire(msg, allocator);
  return add(tag, encoded);
}
 
開發者ID:int08h,項目名稱:nearenough,代碼行數:8,代碼來源:RtMessageBuilder.java

示例11: cacheRemainByte

import io.netty.buffer.ByteBuf; //導入依賴的package包/類
/**
 * 緩存可讀數據中的非完整幀,拚接為完整幀後,執行正常操作
 *
 * @param msg 可讀數據
 * @return 緩存為完整幀
 */
private boolean cacheRemainByte(ByteBuf msg) {
    while (msg.isReadable()) {
        bytes[index] = msg.readByte();
        index++;
        if (index >= 13) {
            index = 0;
            return true;
        }
    }
    return false;
}
 
開發者ID:bitkylin,項目名稱:ClusterDeviceControlPlatform,代碼行數:18,代碼來源:CanFrameChannelInboundHandler.java

示例12: encode

import io.netty.buffer.ByteBuf; //導入依賴的package包/類
private static void encode(String portal, int rowCount, ByteBuf out) {
  int pos = out.writerIndex();
  out.writeByte(EXECUTE);
  out.writeInt(0);
  if (portal != null) {
    out.writeCharSequence(portal, StandardCharsets.UTF_8);
  }
  out.writeByte(0);
  out.writeInt(rowCount); // Zero denotes "no limit" maybe for ReadStream<Row>
  out.setInt(pos + 1, out.writerIndex() - pos - 1);
}
 
開發者ID:vietj,項目名稱:reactive-pg-client,代碼行數:12,代碼來源:Execute.java

示例13: writeValue

import io.netty.buffer.ByteBuf; //導入依賴的package包/類
public static void writeValue(ByteBuffer bytes, ByteBuf cb)
{
    if (bytes == null)
    {
        cb.writeInt(-1);
        return;
    }

    int remaining = bytes.remaining();
    cb.writeInt(remaining);

    if (remaining > 0)
        cb.writeBytes(bytes.duplicate());
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:15,代碼來源:CBUtil.java

示例14: testBuffers

import io.netty.buffer.ByteBuf; //導入依賴的package包/類
private void testBuffers(ByteBuf[] buffers, SerializedField.Builder[] fields) {
  int i = 0;
  for (SerializedField.Builder field : fields) {
    i += fieldBuffersCount(field, buffers, i, buffers.length);
  }
  while (i < buffers.length && buffers[i].readableBytes() == 0) {
    ++ i;
  }
  assertEquals(buffers.length, i);
  for (ByteBuf byteBuf : buffers) {
    byteBuf.release();
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:14,代碼來源:TestBackwardsCompatibilityEncoder.java

示例15: channelRead0

import io.netty.buffer.ByteBuf; //導入依賴的package包/類
@Override
protected void channelRead0(ChannelHandlerContext ctx, FrameMajor msg) throws Exception {
    FrameMajorHeader head = msg.getHead();
    ByteBuf byteBuf = msg.getData();
    while (byteBuf.readableBytes() >= FrameSetting.SUB_FRAME_HEAD_LENGTH) {
        int subMsgId = byteBuf.readByte() & 0xFF;
        byte[] data = new byte[byteBuf.readShort()];
        byteBuf.readBytes(data);
        server.decodeAndHuntMessage(head, subMsgId, data, ctx.channel());
    }
}
 
開發者ID:bitkylin,項目名稱:ClusterDeviceControlPlatform,代碼行數:12,代碼來源:ParsedMessageInBoundHandler.java


注:本文中的io.netty.buffer.ByteBuf類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。