Java Code Examples for io.netty.buffer.ByteBuf.setIndex()

The following are Jave code examples for showing how to use setIndex() of the io.netty.buffer.ByteBuf class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: vertx-fastdfs-client   File: FdfsUtils.java   Source Code and License Vote up 4 votes
public static Buffer newZero(long size) {
	int _size = (int) size;
	ByteBuf byteBuf = Unpooled.buffer(_size, Integer.MAX_VALUE);
	byteBuf.setIndex(0, _size);
	return Buffer.buffer(byteBuf);
}
 
Example 2
Project: reactive-pg-client   File: MessageDecoder.java   Source Code and License Vote up 4 votes
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
  while (true) {
    if (in.readableBytes() < 5) {
      break;
    }
    int beginIdx = in.readerIndex();
    byte id = in.getByte(beginIdx);
    int length = in.getInt(beginIdx + 1);
    int endIdx = beginIdx + length + 1;
    final int writerIndex = in.writerIndex();
    if (writerIndex < endIdx) {
      break;
    }
    try {
      in.setIndex(beginIdx + 5, endIdx);
      switch (id) {
        case READY_FOR_QUERY: {
          decodeReadyForQuery(in, out);
          break;
        }
        case DATA_ROW: {
          decodeDataRow(in);
          break;
        }
        case COMMAND_COMPLETE: {
          decodeCommandComplete(in, out);
          break;
        }
        case BIND_COMPLETE: {
          decodeBindComplete(out);
          break;
        }
        default: {
          decodeMessage(id, in ,out);
        }
      }
    } finally {
      in.setIndex(endIdx, writerIndex);
    }
  }
}