io.netty.buffer.ByteBuf.readRetainedSlice()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(607)

本文整理了Java中io.netty.buffer.ByteBuf.readRetainedSlice()方法的一些代码示例,展示了ByteBuf.readRetainedSlice()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteBuf.readRetainedSlice()方法的具体详情如下:
包路径:io.netty.buffer.ByteBuf
类名称:ByteBuf
方法名:readRetainedSlice

ByteBuf.readRetainedSlice介绍

[英]Returns a new retained slice of this buffer's sub-region starting at the current readerIndex and increases the readerIndex by the size of the new slice (= length).

Note that this method returns a #retain() buffer unlike #readSlice(int). This method behaves similarly to readSlice(...).retain() except that this method may return a buffer implementation that produces less garbage.
[中]返回从当前readerIndex开始的此缓冲区子区域的新保留切片,并将readerIndex增加新切片的大小(=长度)。
请注意,此方法返回一个与#readSlice(int)不同的#retain()缓冲区。此方法的行为类似于readSlice(…)。retain(),但此方法可能返回产生较少垃圾的缓冲区实现。

代码示例

代码示例来源:origin: netty/netty

@Override
public ByteBuf readRetainedSlice(int length) {
  return buf.readRetainedSlice(length);
}

代码示例来源:origin: redisson/redisson

@Override
public ByteBuf readRetainedSlice(int length) {
  return buf.readRetainedSlice(length);
}

代码示例来源:origin: wildfly/wildfly

@Override
public ByteBuf readRetainedSlice(int length) {
  return buf.readRetainedSlice(length);
}

代码示例来源:origin: netty/netty

/**
   * Create a frame out of the {@link ByteBuf} and return it.
   *
   * @param   ctx             the {@link ChannelHandlerContext} which this {@link ByteToMessageDecoder} belongs to
   * @param   in              the {@link ByteBuf} from which to read data
   * @return  frame           the {@link ByteBuf} which represent the frame or {@code null} if no frame could
   *                          be created.
   */
  protected Object decode(
      @SuppressWarnings("UnusedParameters") ChannelHandlerContext ctx, ByteBuf in) throws Exception {
    if (in.readableBytes() < frameLength) {
      return null;
    } else {
      return in.readRetainedSlice(frameLength);
    }
  }
}

代码示例来源:origin: redisson/redisson

/**
   * Create a frame out of the {@link ByteBuf} and return it.
   *
   * @param   ctx             the {@link ChannelHandlerContext} which this {@link ByteToMessageDecoder} belongs to
   * @param   in              the {@link ByteBuf} from which to read data
   * @return  frame           the {@link ByteBuf} which represent the frame or {@code null} if no frame could
   *                          be created.
   */
  protected Object decode(
      @SuppressWarnings("UnusedParameters") ChannelHandlerContext ctx, ByteBuf in) throws Exception {
    if (in.readableBytes() < frameLength) {
      return null;
    } else {
      return in.readRetainedSlice(frameLength);
    }
  }
}

代码示例来源:origin: netty/netty

@Override
public ByteBuf readRetainedSlice(int length) {
  checkReadableBytes(length);
  return buffer.readRetainedSlice(length);
}

代码示例来源:origin: netty/netty

@Override
public ByteBuf readRetainedSlice(int length) {
  return buf.readRetainedSlice(length).order(order);
}

代码示例来源:origin: redisson/redisson

@Override
public ByteBuf readRetainedSlice(int length) {
  checkReadableBytes(length);
  return buffer.readRetainedSlice(length);
}

代码示例来源:origin: redisson/redisson

@Override
public ByteBuf readRetainedSlice(int length) {
  return buf.readRetainedSlice(length).order(order);
}

代码示例来源:origin: apache/incubator-shardingsphere

@Override
protected void doDecode(final ChannelHandlerContext context, final ByteBuf in, final List<Object> out, final int readableBytes) {
  int messageTyepLength = 0;
  if ('\0' == in.markReaderIndex().readByte()) {
    in.resetReaderIndex();
  } else {
    messageTyepLength = PostgreSQLPacket.MESSAGE_TYPE_LENGTH;
  }
  int payloadLength = in.readInt();
  int realPacketLength = payloadLength + messageTyepLength;
  if (readableBytes < realPacketLength) {
    in.resetReaderIndex();
    return;
  }
  in.resetReaderIndex();
  out.add(in.readRetainedSlice(payloadLength + messageTyepLength));
}

代码示例来源:origin: wildfly/wildfly

@Override
public ByteBuf readRetainedSlice(int length) {
  checkReadableBytes(length);
  return buffer.readRetainedSlice(length);
}

代码示例来源:origin: apache/incubator-shardingsphere

@Override
protected void doDecode(final ChannelHandlerContext context, final ByteBuf in, final List<Object> out, final int readableBytes) {
  int payloadLength = in.markReaderIndex().readMediumLE();
  int realPacketLength = payloadLength + MySQLPacket.PAYLOAD_LENGTH + MySQLPacket.SEQUENCE_LENGTH;
  if (readableBytes < realPacketLength) {
    in.resetReaderIndex();
    return;
  }
  out.add(in.readRetainedSlice(payloadLength + MySQLPacket.SEQUENCE_LENGTH));
}

代码示例来源:origin: apache/incubator-shardingsphere

@Override
protected void doDecode(final ChannelHandlerContext context, final ByteBuf in, final List<Object> out, final int readableBytes) {
  int payloadLength = in.markReaderIndex().readMediumLE();
  int realPacketLength = payloadLength + MySQLPacket.PAYLOAD_LENGTH + MySQLPacket.SEQUENCE_LENGTH;
  if (readableBytes < realPacketLength) {
    in.resetReaderIndex();
    return;
  }
  out.add(in.readRetainedSlice(payloadLength + MySQLPacket.SEQUENCE_LENGTH));
}

代码示例来源:origin: netty/netty

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out)
    throws Exception {
  in.markReaderIndex();
  int preIndex = in.readerIndex();
  int length = readRawVarint32(in);
  if (preIndex == in.readerIndex()) {
    return;
  }
  if (length < 0) {
    throw new CorruptedFrameException("negative length: " + length);
  }
  if (in.readableBytes() < length) {
    in.resetReaderIndex();
  } else {
    out.add(in.readRetainedSlice(length));
  }
}

代码示例来源:origin: wildfly/wildfly

@Override
public ByteBuf readRetainedSlice(int length) {
  return buf.readRetainedSlice(length).order(order);
}

代码示例来源:origin: traccar/traccar

@Override
protected Object decode(
    ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
  int length = messageLength(buf);
  if (buf.readableBytes() >= length) {
    return buf.readRetainedSlice(length);
  }
  return null;
}

代码示例来源:origin: traccar/traccar

@Override
protected Object decode(
    ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
  buf.readerIndex(buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 'E'));
  int endIndex = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 'E');
  if (endIndex > 0) {
    return buf.readRetainedSlice(endIndex - buf.readerIndex());
  } else {
    return buf.readRetainedSlice(buf.readableBytes()); // assume full frame
  }
}

代码示例来源:origin: traccar/traccar

@Override
protected Object decode(
    ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
  int length = 4 + buf.getIntLE(buf.readerIndex());
  if (buf.readableBytes() >= length) {
    return buf.readRetainedSlice(length);
  } else {
    return null;
  }
}

代码示例来源:origin: wildfly/wildfly

private static Result<ByteBuf> decodePublishPayload(ByteBuf buffer, int bytesRemainingInVariablePart) {
  ByteBuf b = buffer.readRetainedSlice(bytesRemainingInVariablePart);
  return new Result<ByteBuf>(b, bytesRemainingInVariablePart);
}

代码示例来源:origin: redisson/redisson

@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out)
    throws Exception {
  in.markReaderIndex();
  int preIndex = in.readerIndex();
  int length = readRawVarint32(in);
  if (preIndex == in.readerIndex()) {
    return;
  }
  if (length < 0) {
    throw new CorruptedFrameException("negative length: " + length);
  }
  if (in.readableBytes() < length) {
    in.resetReaderIndex();
  } else {
    out.add(in.readRetainedSlice(length));
  }
}

相关文章

ByteBuf类方法