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


Java ByteBuf.readerIndex方法代碼示例

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


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

示例1: encrypt

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void encrypt(ByteBuf buf)
{
	if (!_isEnabled)
	{
		_isEnabled = true;
		onPacketSent(buf);
		return;
	}
	
	onPacketSent(buf);
	
	int a = 0;
	while (buf.isReadable())
	{
		final int b = buf.readByte() & 0xFF;
		a = b ^ _outKey[(buf.readerIndex() - 1) & 15] ^ a;
		buf.setByte(buf.readerIndex() - 1, a);
	}
	
	shiftKey(_outKey, buf.writerIndex());
}
 
開發者ID:rubenswagner,項目名稱:L2J-Global,代碼行數:23,代碼來源:Crypt.java

示例2: fromBytes

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void fromBytes(ByteBuf buf) {
	entityID = buf.readInt();
	type = buf.readByte();
	if (type == 0)
		intValue = buf.readInt();
	else if (type == 1)
		floatValue = buf.readFloat();
	else if (type == 2)
		byteValue = buf.readByte();
	else if (type == 3) {
		int stringLength = buf.readByte();
		stringValue = buf.toString(buf.readerIndex(), stringLength, StandardCharsets.UTF_8);
		buf.readerIndex(buf.readerIndex() + stringLength);
	}
	// value=buf.readInt();
	name = buf.toString(buf.readerIndex(), buf.readableBytes(), StandardCharsets.UTF_8);
}
 
開發者ID:rafradek,項目名稱:Mods,代碼行數:19,代碼來源:TF2Message.java

示例3: findText

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public static int findText(ByteBuf byteBuf, String str) {
  byte[] text = stringToBytes(str);
  int matchIndex = 0;
  for (int i = byteBuf.readerIndex(); i < byteBuf.readableBytes(); i++) {
    for (int j = matchIndex; j < text.length; j++) {
      if (byteBuf.getByte(i) == text[j]) {
        matchIndex = j + 1;
        if (matchIndex == text.length) {
          return i;
        }
      } else {
        matchIndex = 0;
      }
      break;
    }
  }
  return -1;
}
 
開發者ID:monkeyWie,項目名稱:proxyee-down,代碼行數:19,代碼來源:ByteUtil.java

示例4: readString

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public String readString(ByteBuf source) {
  int len = readUnsignedShort(source);
  String str = source.toString(source.readerIndex(), len, CharsetUtil.UTF_8);
  source.readerIndex(source.readerIndex() + len);
  return str;
}
 
開發者ID:datastax,項目名稱:simulacron,代碼行數:8,代碼來源:ByteBufCodec.java

示例5: parse

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public long parse(ByteBuf in) {
  seq = sequenceRef.get();

  seq.reset();
  size = 0;
  int i = in.forEachByte(this);
  in.readerIndex(i);

  Long result = Long.parseLong(seq.toString());
  seq = null;

  return result;
}
 
開發者ID:HubSpot,項目名稱:NioImapClient,代碼行數:14,代碼來源:NumberParser.java

示例6: decode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
    final byte[] array;
    final int offset;
    final int length = msg.readableBytes();
    if (msg.hasArray()) {
        array = msg.array();
        offset = msg.arrayOffset() + msg.readerIndex();
    } else {
        array = new byte[length];
        msg.getBytes(msg.readerIndex(), array, 0, length);
        offset = 0;
    }

    if (extensionRegistry == null) {
        if (HAS_PARSER) {
            out.add(prototype.getParserForType().parseFrom(array, offset, length));
        } else {
            out.add(prototype.newBuilderForType().mergeFrom(array, offset, length).build());
        }
    } else {
        if (HAS_PARSER) {
            out.add(prototype.getParserForType().parseFrom(array, offset, length, extensionRegistry));
        } else {
            out.add(prototype.newBuilderForType().mergeFrom(array, offset, length, extensionRegistry).build());
        }
    }
}
 
開發者ID:ninelook,項目名稱:wecard-server,代碼行數:29,代碼來源:ProtobufDecoder.java

示例7: decode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
/**
 * 解碼
 * 
 * @param in
 * @return
 * @throws Exception
 */
public static LibraMessage decode(ByteBuf in) throws Exception {
	LibraMessage message = new LibraMessage();
	message.setHead(LibraHead.decode(in));
	short bodyLength = in.readShort();// 消息體的長度
	if (bodyLength != in.readableBytes()) {
		LibraLog.error("LibraMessage.decode is error! params:bodyLength:" + bodyLength + "\treadableLength:" + in.readableBytes());
		return null;
	}
	ByteBuf bodyByteBuf = in.readBytes(in.readableBytes());
	byte[] array;
	// 反序列化數據的起始點
	int offset;
	// 可讀的數據字節長度
	int readableLen = bodyByteBuf.readableBytes();
	// 分為包含數組數據和不包含數組數據兩種形式
	if (bodyByteBuf.hasArray()) {
		array = bodyByteBuf.array();
		offset = bodyByteBuf.arrayOffset() + bodyByteBuf.readerIndex();
	} else {
		array = new byte[readableLen];
		bodyByteBuf.getBytes(bodyByteBuf.readerIndex(), array, 0, readableLen);
		offset = 0;
	}
	// 反序列化
	message.setBody(decodeBody(message.getHead().getProtocolID(), array, offset, readableLen));
	return message;
}
 
開發者ID:inspingcc,項目名稱:LibraSock,代碼行數:35,代碼來源:LibraMessage.java

示例8: checkReadLength

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private void checkReadLength(OperationParameters operationParameters, ByteBuf data) {
    final int actuallyRead = data.writerIndex() - data.readerIndex();
    if (actuallyRead != operationParameters.cmdLength) {

        LOGGER.error("responding to from {} length {} handle {}", operationParameters.cmdOffset, actuallyRead, operationParameters.cmdHandle);
        final String msg = "i messed up and tried to return the wrong about of read data.. " +
                "from " + operationParameters.cmdOffset +
                " length " + actuallyRead +
                " requested " + operationParameters.cmdLength +
                " handle " + operationParameters.cmdHandle;
        throw new IllegalStateException(msg);
    }
}
 
開發者ID:MineboxOS,項目名稱:minebox,代碼行數:14,代碼來源:TransmissionPhase.java

示例9: parse

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public String parse(ByteBuf buffer) {
  AppendableCharSequence sequence = sequenceReference.get();

  int readerIndex = buffer.readerIndex();
  try {
    super.parse(buffer);
  } catch (Signal e) {
    e.expect(REPLAYING_SIGNAL);
    buffer.readerIndex(readerIndex + size);
    return sequence.toString();
  }

  return sequence.toString();
}
 
開發者ID:HubSpot,項目名稱:NioImapClient,代碼行數:16,代碼來源:AllBytesParser.java

示例10: parse

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public String parse(ByteBuf buffer) {
  seq = sequenceReference.get();

  seq.reset();
  size = 0;
  int i = buffer.forEachByte(this);
  buffer.readerIndex(i + 1);

  String result = seq.toString();
  seq = null;

  return result;
}
 
開發者ID:HubSpot,項目名稱:NioImapClient,代碼行數:14,代碼來源:BaseStringParser.java

示例11: parseSearch

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
private UntaggedSearchResponse parseSearch(ByteBuf in) {
  List<Long> ids = new ArrayList<>();
  for (; ; ) {
    char c = ((char) in.readUnsignedByte());
    in.readerIndex(in.readerIndex() - 1);
    if (c == HttpConstants.CR || c == HttpConstants.LF) {
      lineParser.parse(in);
      break;
    }

    ids.add(Long.parseLong(atomOrStringParser.parse(in)));
  }

  return new UntaggedSearchResponse(ids);
}
 
開發者ID:HubSpot,項目名稱:NioImapClient,代碼行數:16,代碼來源:ResponseDecoder.java

示例12: decode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@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);
    }
  }
}
 
開發者ID:vietj,項目名稱:reactive-pg-client,代碼行數:43,代碼來源:MessageDecoder.java

示例13: decodeText

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public T decodeText(int len, ByteBuf buff) {
  // Default to null
  buff.readerIndex(buff.readerIndex() + len);
  return null;
}
 
開發者ID:vietj,項目名稱:reactive-pg-client,代碼行數:6,代碼來源:DataType.java

示例14: decodeBinary

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
public T decodeBinary(int len, ByteBuf buff) {
  // Default to null
  buff.readerIndex(buff.readerIndex() + len);
  return null;
}
 
開發者ID:vietj,項目名稱:reactive-pg-client,代碼行數:6,代碼來源:DataType.java

示例15: parse

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public Optional<byte[]> parse(ByteBuf in) {
  for (;;) {
    switch (state) {
      case START:
        char c = ((char) in.readUnsignedByte());
        if (c == '{') {
          in.readerIndex(in.readerIndex() - 1);
          expectedSize = sizeParser.parse(in);
          state = State.SKIP_CRLF;
          return Optional.empty();
        } else if (Character.isWhitespace(c)) {
          continue;
        } else {
          in.readerIndex(in.readerIndex() - 1);
          state = State.PARSE_STRING;
          continue;
        }
      case SKIP_CRLF:
        in.readBytes(2);
        state = State.PARSE_SIZE;
        continue;
      case PARSE_STRING:
        return Optional.of(stringParser.parse(in).getBytes(StandardCharsets.UTF_8));
      case PARSE_SIZE:
        if (buf == null) {
          buf = PooledByteBufAllocator.DEFAULT.buffer(expectedSize);
        }

        pos = in.readerIndex();
        try {
          while (size < expectedSize) {
            buf.writeByte((char) in.readUnsignedByte());
            inc();
          }
        } catch (Signal e) {
          e.expect(REPLAYING_SIGNAL);
          in.readerIndex(pos);
          return Optional.empty();
        }

        byte[] result = new byte[buf.readableBytes()];
        buf.getBytes(buf.readerIndex(), result);
        reset();

        return Optional.of(result);
    }
  }

}
 
開發者ID:HubSpot,項目名稱:NioImapClient,代碼行數:51,代碼來源:BufferedBodyParser.java


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