当前位置: 首页>>代码示例>>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;未经允许,请勿转载。