本文整理汇总了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());
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
}
}
示例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;
}
示例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);
}
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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);
}
}
}