/** * Refill the {@link ByteBuf} by one byte. */ void refill() { int readData = in.readUnsignedByte(); bitBuffer = bitBuffer << 8 | readData; bitCount += 8; }
@Override public short readUnsignedByte() { return buf.readUnsignedByte(); }
@Override public short readUnsignedByte() { return buf.readUnsignedByte(); }
/** * Refill the {@link ByteBuf} by one byte. */ void refill() { int readData = in.readUnsignedByte(); bitBuffer = bitBuffer << 8 | readData; bitCount += 8; }
@Override public short readUnsignedByte() { return buf.readUnsignedByte(); }
@Override public short readUnsignedByte() { return buf.readUnsignedByte(); }
/** * Refill the {@link ByteBuf} by one byte. */ void refill() { int readData = in.readUnsignedByte(); bitBuffer = bitBuffer << 8 | readData; bitCount += 8; }
@Override public short readUnsignedByte() { checkReadableBytes(1); return buffer.readUnsignedByte(); }
private static Result<Integer> decodeMsbLsb(ByteBuf buffer, int min, int max) { short msbSize = buffer.readUnsignedByte(); short lsbSize = buffer.readUnsignedByte(); final int numberOfBytesConsumed = 2; int result = msbSize << 8 | lsbSize; if (result < min || result > max) { result = -1; } return new Result<Integer>(result, numberOfBytesConsumed); }
@Override public short readUnsignedByte() { checkReadableBytes(1); return buffer.readUnsignedByte(); }
private static void skipControlCharactersStandard(ByteBuf undecodedChunk) { for (;;) { char c = (char) undecodedChunk.readUnsignedByte(); if (!Character.isISOControl(c) && !Character.isWhitespace(c)) { undecodedChunk.readerIndex(undecodedChunk.readerIndex() - 1); break; } } }
/** * Reads the length varint (a series of bytes, where the lower 7 bits * are data and the upper bit is a flag to indicate more bytes to be * read). * * @param in The input buffer to read the preamble from * @return The calculated length based on the input buffer, or 0 if * no preamble is able to be calculated */ private static int readPreamble(ByteBuf in) { int length = 0; int byteIndex = 0; while (in.isReadable()) { int current = in.readUnsignedByte(); length |= (current & 0x7f) << byteIndex++ * 7; if ((current & 0x80) == 0) { return length; } if (byteIndex >= 4) { throw new DecompressionException("Preamble is greater than 4 bytes"); } } return 0; }
@Override public String readLine() throws IOException { if (!buffer.isReadable()) { return null; } if (lineBuf != null) { lineBuf.setLength(0); } loop: do { int c = buffer.readUnsignedByte(); switch (c) { case '\n': break loop; case '\r': if (buffer.isReadable() && (char) buffer.getUnsignedByte(buffer.readerIndex()) == '\n') { buffer.skipBytes(1); } break loop; default: if (lineBuf == null) { lineBuf = new StringBuilder(); } lineBuf.append((char) c); } } while (buffer.isReadable()); return lineBuf != null && lineBuf.length() > 0 ? lineBuf.toString() : StringUtil.EMPTY_STRING; }
/** * If padding is present in the payload, reads the next byte as padding. The padding also includes the one byte * width of the pad length field. Otherwise, returns zero. */ private int readPadding(ByteBuf payload) { if (!flags.paddingPresent()) { return 0; } return payload.readUnsignedByte() + 1; }
@Override public short readUnsignedByte() { checkReadableBytes(1); return buffer.readUnsignedByte(); }
private void verifyCrc(ByteBuf in) { long crcValue = 0; for (int i = 0; i < 4; ++i) { crcValue |= (long) in.readUnsignedByte() << i * 8; } long readCrc = crc.getValue(); if (crcValue != readCrc) { throw new DecompressionException( "CRC value mismatch. Expected: " + crcValue + ", Got: " + readCrc); } }
private void verifyCrc(ByteBuf in) { long crcValue = 0; for (int i = 0; i < 4; ++i) { crcValue |= (long) in.readUnsignedByte() << i * 8; } long readCrc = crc.getValue(); if (crcValue != readCrc) { throw new DecompressionException( "CRC value mismatch. Expected: " + crcValue + ", Got: " + readCrc); } }
private boolean readGZIPFooter(ByteBuf buf) { if (buf.readableBytes() < 8) { return false; } verifyCrc(buf); // read ISIZE and verify int dataLength = 0; for (int i = 0; i < 4; ++i) { dataLength |= buf.readUnsignedByte() << i * 8; } int readLength = inflater.getTotalOut(); if (dataLength != readLength) { throw new DecompressionException( "Number of bytes mismatch. Expected: " + dataLength + ", Got: " + readLength); } return true; }
private boolean readGZIPFooter(ByteBuf buf) { if (buf.readableBytes() < 8) { return false; } verifyCrc(buf); // read ISIZE and verify int dataLength = 0; for (int i = 0; i < 4; ++i) { dataLength |= buf.readUnsignedByte() << i * 8; } int readLength = inflater.getTotalOut(); if (dataLength != readLength) { throw new DecompressionException( "Number of bytes mismatch. Expected: " + dataLength + ", Got: " + readLength); } return true; }
private static Result<MqttConnAckVariableHeader> decodeConnAckVariableHeader(ByteBuf buffer) { final boolean sessionPresent = (buffer.readUnsignedByte() & 0x01) == 0x01; byte returnCode = buffer.readByte(); final int numberOfBytesConsumed = 2; final MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(MqttConnectReturnCode.valueOf(returnCode), sessionPresent); return new Result<MqttConnAckVariableHeader>(mqttConnAckVariableHeader, numberOfBytesConsumed); }