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