Refine search
private static boolean isValueFound(ByteBuf buffer, int index, ByteBuf search) { for (int i = 0; i < search.readableBytes(); i++) { if (buffer.getByte(index + i) != search.getByte(i)) { return false; } } return true; }
@Override public byte peekByte() { return buf.getByte( buf.readerIndex() ); }
@Override protected void decodeLast(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception { switch (buffer.readableBytes()) { case 0: return; case 1: // Ignore the last TC_RESET if (buffer.getByte(buffer.readerIndex()) == ObjectStreamConstants.TC_RESET) { buffer.skipBytes(1); return; } } decode(ctx, buffer, out); }
.map(DnsRawRecord.class::cast) .anyMatch(r -> r.type() == DnsRecordType.A && r.content().getByte(r.content().readerIndex()) == 127); final int contentLen = content.readableBytes(); content.getBytes(content.readerIndex(), addrBytes);
private boolean hasLengthHeader(ByteBuf buffer) { for (int i = 0; i < Math.min(buffer.readableBytes(), 10); i++) { byte b = buffer.getByte(buffer.readerIndex() + i); if (b == (byte)':' && i > 0) { return true; } if (b > 57 || b < 48) { return false; } } return false; }
private static int getMagicIndex(ByteBuf in) { boolean found = false; int readIndex = in.readerIndex(); int begin = 0; while (readIndex < in.writerIndex()) { if (in.getByte(readIndex) == MAGIC_HALF && in.getByte(readIndex + 1) == MAGIC_HALF) { begin = readIndex; found = true; break; } ++readIndex; } return found ? begin : NOT_FOUND_INDEX; } }
DeviceSession deviceSession; if (buf.getByte(0) == 'E' && buf.getByte(1) == 'L') { buf.skipBytes(2 + 2 + 2); // udp header uniqueId = ByteBufUtil.hexDump(buf.readSlice(8)).substring(1); } else if (type == MSG_HEARTBEAT && buf.readableBytes() >= 2) {
/** * Returns the index in the buffer of the end of line found. * Returns -1 if no end of line was found in the buffer. */ private int findEndOfLine(final ByteBuf buffer) { int totalLength = buffer.readableBytes(); int i = buffer.forEachByte(buffer.readerIndex() + offset, totalLength - offset, ByteProcessor.FIND_LF); if (i >= 0) { offset = 0; if (i > 0 && buffer.getByte(i - 1) == '\r') { i--; } } else { offset = totalLength; } return i; } }
private boolean isStringPacket(ByteBuf content) { return content.getByte(content.readerIndex()) == 0x0; }
for (int i = 0; i < buf.readableBytes(); i++) { int b = buf.getByte(i); if (b != 0x0b) { buf.setByte(i, b - 0x20);
@Override protected void decodeLast(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception { switch (buffer.readableBytes()) { case 0: return; case 1: // Ignore the last TC_RESET if (buffer.getByte(buffer.readerIndex()) == ObjectStreamConstants.TC_RESET) { buffer.skipBytes(1); return; } } decode(ctx, buffer, out); }
private static byte checksum(ByteBuf buf, int end) { byte result = 0; for (int i = 0; i < end; i++) { result += buf.getByte(buf.readerIndex() + i); } return result; }
/** * Returns the index in the buffer of the end of line found. * Returns -1 if no end of line was found in the buffer. */ private int findEndOfLine(final ByteBuf buffer) { int totalLength = buffer.readableBytes(); int i = buffer.forEachByte(buffer.readerIndex() + offset, totalLength - offset, ByteProcessor.FIND_LF); if (i >= 0) { offset = 0; if (i > 0 && buffer.getByte(i - 1) == '\r') { i--; } } else { offset = totalLength; } return i; } }
private boolean match(byte[] prefix, ByteBuf buffer) { final int idx = buffer.readerIndex(); for (int i = 0; i < prefix.length; i++) { final byte b = buffer.getByte(idx + i); if (b != prefix[i]) { return false; } } return true; } }
/** * Returns the proxy protocol specification version in the buffer if the version is found. * Returns -1 if no version was found in the buffer. */ private static int findVersion(final ByteBuf buffer) { final int n = buffer.readableBytes(); // per spec, the version number is found in the 13th byte if (n < 13) { return -1; } int idx = buffer.readerIndex(); return match(BINARY_PREFIX, buffer, idx) ? buffer.getByte(idx + BINARY_PREFIX_LENGTH) : 1; }
/** * Returns the index in the buffer of the end of line found. * Returns -1 if no end of line was found in the buffer. */ private static int findEndOfLine(final ByteBuf buffer) { final int n = buffer.writerIndex(); for (int i = buffer.readerIndex(); i < n; i++) { final byte b = buffer.getByte(i); if (b == '\r' && i < n - 1 && buffer.getByte(i + 1) == '\n') { return i; // \r\n } } return -1; // Not found. }
/** * Returns the index in the buffer of the end of line found. * Returns -1 if no end of line was found in the buffer. */ private int findEndOfLine(final ByteBuf buffer) { int totalLength = buffer.readableBytes(); int i = buffer.forEachByte(buffer.readerIndex() + offset, totalLength - offset, ByteProcessor.FIND_LF); if (i >= 0) { offset = 0; if (i > 0 && buffer.getByte(i - 1) == '\r') { i--; } } else { offset = totalLength; } return i; } }
private long readLong(ByteBuf chars, int length) { long result = 0; for (int i = chars.readerIndex(); i < chars.readerIndex() + length; i++) { int digit = ((int)chars.getByte(i) & 0xF); for (int j = 0; j < chars.readerIndex() + length-1-i; j++) { digit *= 10; } result += digit; } chars.readerIndex(chars.readerIndex() + length); return result; }
@Override protected void decodeLast(ChannelHandlerContext ctx, ByteBuf buffer, List<Object> out) throws Exception { switch (buffer.readableBytes()) { case 0: return; case 1: // Ignore the last TC_RESET if (buffer.getByte(buffer.readerIndex()) == ObjectStreamConstants.TC_RESET) { buffer.skipBytes(1); return; } } decode(ctx, buffer, out); }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> list) throws Exception { if (in.getByte(in.readerIndex()) != UpdateOpcodes.CLIENT_LOGGED_IN) { ctx.fireChannelRead(in.retain()); return; } in.skipBytes(4); }