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

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

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

ByteBuf.readLong介绍

[英]Gets a 64-bit integer at the current readerIndexand increases the readerIndex by 8 in this buffer.
[中]获取当前readerIndex处的64位整数,并在此缓冲区中将readerIndex增加8。

代码示例

代码示例来源:origin: qunarcorp/qmq

private DelaySyncRequest deserializeSyncRequest(RemotingCommand request) {
  ByteBuf body = request.getBody();
  int logType = body.readByte();
  long messageLogOffset = body.readLong();
  int dispatchLogSegmentBaseOffset = body.readInt();
  long dispatchLogOffset = body.readLong();
  int lastDispatchLogBaseOffset = body.readInt();
  long lastDispatchLogOffset = body.readLong();
  return new DelaySyncRequest(messageLogOffset, dispatchLogSegmentBaseOffset, dispatchLogOffset, lastDispatchLogBaseOffset, lastDispatchLogOffset, logType);
}

代码示例来源:origin: weibocom/motan

private void decodeV1(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
  long startTime = System.currentTimeMillis();
  in.resetReaderIndex();
  in.skipBytes(2);// skip magic num
  byte messageType = (byte) in.readShort();
  long requestId = in.readLong();
  int dataLength = in.readInt();
  // FIXME 如果dataLength过大,可能导致问题
  if (in.readableBytes() < dataLength) {
    in.resetReaderIndex();
    return;
  }
  checkMaxContext(dataLength, ctx, messageType == MotanConstants.FLAG_REQUEST, requestId);
  byte[] data = new byte[dataLength];
  in.readBytes(data);
  decode(data, out, messageType == MotanConstants.FLAG_REQUEST, requestId).setStartTime(startTime);
}

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

private long readValue(ByteBuf buf, int length, boolean signed) {
  switch (length) {
    case 1:
      return signed ? buf.readByte() : buf.readUnsignedByte();
    case 2:
      return signed ? buf.readShort() : buf.readUnsignedShort();
    case 4:
      return signed ? buf.readInt() : buf.readUnsignedInt();
    default:
      return buf.readLong();
  }
}

代码示例来源:origin: org.apache.distributedlog/distributedlog-protocol

if (in.readableBytes() <= 0) {
  return null;
  long metadata = in.readLong();
  nextRecordInStream.setTransactionId(in.readLong());
  if (LOG.isTraceEnabled()) {
    if (nextRecordInStream.isControl()) {
      LOG.trace("Reading {} Control DLSN {}",
        recordStream.getName(), nextRecordInStream.getDlsn());
    } else {
      LOG.trace("Reading {} Valid DLSN {}",
        recordStream.getName(), nextRecordInStream.getDlsn());

代码示例来源:origin: org.apache.distributedlog/distributedlog-protocol

flags = in.readLong();
  currTxId = in.readLong();
} else {
  if (LOG.isTraceEnabled()) {
    LOG.trace("Found position {} beyond {}", recordStream.getCurrentPosition(), dlsn);
    if (LOG.isTraceEnabled()) {
      LOG.trace("Found position {} beyond {}", currTxId, txId);
  recordSetReader = LogRecordSet.of(record);
} else {
  int length = in.readInt();
  if (length < 0) {
  if (LOG.isTraceEnabled()) {
    LOG.trace("Skipped Record with TxId {} DLSN {}",
      currTxId, recordStream.getCurrentPosition());

代码示例来源:origin: weibocom/motan

private void decodeV2(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
  long startTime = System.currentTimeMillis();
  in.resetReaderIndex();
  if (in.readableBytes() < 21) {
    return;
  boolean isRequest = isV2Request(in.readByte());
  in.skipBytes(2);
  long requestId = in.readLong();
  int size = 13;
  int metaSize = in.readInt();
  size += 4;
  if (metaSize > 0) {
    size += metaSize;
    if (in.readableBytes() < metaSize) {
      in.resetReaderIndex();
      return;
  if (in.readableBytes() < 4) {
    in.resetReaderIndex();
    return;
  int bodySize = in.readInt();
  checkMaxContext(bodySize, ctx, isRequest, requestId);
  size += 4;

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

case 119:
  position.set("eventData", ByteBufUtil.hexDump(
      buf, buf.readerIndex(), Math.min(buf.readableBytes(), 1024)));
  break;
case 121:
case 142:
  buf.readLong();
  break;
case 130:

代码示例来源:origin: qunarcorp/qmq

private RawMessage deserializeRawMessageWithCrc(ByteBuf body) {
  long bodyCrc = body.readLong();
  int headerStart = body.readerIndex();
  body.markReaderIndex();
  MessageHeader header = deserializeMessageHeader(body);
  header.setBodyCrc(bodyCrc);
  int bodyLen = body.readInt();
  int headerLen = body.readerIndex() - headerStart;
  int totalLen = headerLen + bodyLen;
  body.resetReaderIndex();
  ByteBuf messageBuf = body.readSlice(totalLen);
  return new RawMessage(header, messageBuf, totalLen);
}

代码示例来源:origin: org.onosproject/onos-protocols-lisp-msg

@Override
public LispMapNotify readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException {
  if (byteBuf.readerIndex() != 0) {
    return null;
  long nonce = byteBuf.readLong();
  short keyId = byteBuf.readShort();
  short authLength = byteBuf.readShort();

代码示例来源:origin: alibaba/fescar

@Override
public boolean decode(ByteBuf in) {
  int leftLen = in.readableBytes();
  int read = 0;
  int xidLen = in.readShort();
  if (xidLen > 0) {
    if (leftLen < xidLen) {
    leftLen -= xidLen;
  this.branchId = in.readLong();
  leftLen -= 8;
  this.branchType = BranchType.get(in.readByte());
  leftLen --;
  int resourceIdLen = in.readShort();
  if (resourceIdLen > 0) {
    if (leftLen < resourceIdLen) {
  int applicationDataLen = in.readInt();
  if (applicationDataLen > 0) {
    if (leftLen < applicationDataLen) {

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

private long readValue(ByteBuf buf, int length, boolean signed) {
  switch (length) {
    case 1:
      return signed ? buf.readByte() : buf.readUnsignedByte();
    case 2:
      return signed ? buf.readShort() : buf.readUnsignedShort();
    case 4:
      return signed ? buf.readInt() : buf.readUnsignedInt();
    default:
      return buf.readLong();
  }
}

代码示例来源:origin: alibaba/Sentinel

@Override
  public FlowRequestData decode(ByteBuf source) {
    if (source.readableBytes() >= 12) {
      FlowRequestData requestData = new FlowRequestData()
        .setFlowId(source.readLong())
        .setCount(source.readInt());
      if (source.readableBytes() >= 1) {
        requestData.setPriority(source.readBoolean());
      }
      return requestData;
    }
    return null;
  }
}

代码示例来源:origin: com.github.javaclub/mq-common

public int decode(ByteBuf in){
  int readindex = super.decode(in);
  if(readindex != -1){  
    if(in.readableBytes() >= 8){
      ip = in.readLong();
      return 0;
    }else{
      in.readerIndex(readindex); // 恢复readindex
      return -1;
    }
  }
  return -1;
}

代码示例来源:origin: qunarcorp/qmq

@Override
public void process(Datagram syncData) {
  ByteBuf body = syncData.getBody();
  int size = body.readInt();
  if (size == 0) {
    LOGGER.debug("sync dispatch log data empty");
    return;
  }
  long startOffset = body.readLong();
  long baseOffset = body.readLong();
  appendLogs(startOffset, baseOffset, body);
}

代码示例来源:origin: org.onosproject/onos-protocols-lisp-msg

@Override
public LispMapRegister readFrom(ByteBuf byteBuf) throws LispParseError, LispReaderException {
  if (byteBuf.readerIndex() != 0) {
    return null;
  long nonce = byteBuf.readLong();
  short keyId = byteBuf.readShort();
  short authLength = byteBuf.readShort();

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

final long magic = in.readLong();
if (magic != MAGIC_NUMBER) {
  throw new DecompressionException("unexpected block identifier");
int blockType = token & 0xF0;
int compressedLength = Integer.reverseBytes(in.readInt());
if (compressedLength < 0 || compressedLength > MAX_BLOCK_SIZE) {
  throw new DecompressionException(String.format(
int decompressedLength = Integer.reverseBytes(in.readInt());
final int maxDecompressedLength = 1 << compressionLevel;
if (decompressedLength < 0 || decompressedLength > maxDecompressedLength) {
int currentChecksum = Integer.reverseBytes(in.readInt());
if (decompressedLength == 0 && compressedLength == 0) {
  if (currentChecksum != 0) {
currentChecksum = this.currentChecksum;
if (in.readableBytes() < compressedLength) {
  break;
      uncompressed = in.retainedSlice(in.readerIndex(), decompressedLength);
      break;
    case BLOCK_TYPE_COMPRESSED:

代码示例来源:origin: alibaba/Sentinel

params.add(source.readInt());
  return true;
case ClusterConstants.PARAM_TYPE_STRING:
  int length = source.readInt();
  byte[] bytes = new byte[length];
  source.readBytes(bytes);
  return true;
case ClusterConstants.PARAM_TYPE_LONG:
  params.add(source.readLong());
  return true;
case ClusterConstants.PARAM_TYPE_FLOAT:
  return true;
case ClusterConstants.PARAM_TYPE_SHORT:
  params.add(source.readShort());
  return true;
default:

代码示例来源:origin: alibaba/Sentinel

@Override
public ParamFlowRequestData decode(ByteBuf source) {
  if (source.readableBytes() >= 16) {
    ParamFlowRequestData requestData = new ParamFlowRequestData()
      .setFlowId(source.readLong())
      .setCount(source.readInt());
    int amount = source.readInt();
    if (amount > 0) {
      List<Object> params = new ArrayList<>(amount);
      for (int i = 0; i < amount; i++) {
        decodeParam(source, params);
      }
      requestData.setParams(params);
      return requestData;
    }
  }
  return null;
}

代码示例来源:origin: io.netty/netty-codec-http2

private void processPayloadState(ChannelHandlerContext ctx, ByteBuf in, Http2FrameListener listener)
        throws Http2Exception {
  if (in.readableBytes() < payloadLength) {
  int payloadEndIndex = in.readerIndex() + payloadLength;
      break;
    case PING:
      readPingFrame(ctx, in.readLong(), listener);
      break;
    case GO_AWAY:
      break;
  in.readerIndex(payloadEndIndex);

代码示例来源:origin: qunarcorp/qmq

@Override
public void process(Datagram syncData) {
  final ByteBuf body = syncData.getBody();
  final int size = body.readInt();
  if (size == 0) {
    LOGGER.debug("sync message log data empty");
    return;
  }
  final long startOffset = body.readLong();
  appendLogs(startOffset, body);
}

相关文章

ByteBuf类方法