/** * Reads a 16-bit Short from the given ArrayView starting at the given position. * * @param source The ArrayView to read from. * @param position The position in the ArrayView to start reading at. * @return The read number. */ public static short readShort(ArrayView source, int position) { return (short) ((source.get(position) & 0xFF) << 8 | (source.get(position + 1) & 0xFF)); }
if (this.soughtKey.get(i) != keyData.get(i)) {
/** * Reads a 32-bit integer from the given ArrayView starting at the given position. * * @param source The ArrayView to read from. * @param position The position in the ArrayView to start reading at. * @return The read number. */ public static int readInt(ArrayView source, int position) { return (source.get(position) & 0xFF) << 24 | (source.get(position + 1) & 0xFF) << 16 | (source.get(position + 2) & 0xFF) << 8 | (source.get(position + 3) & 0xFF); }
/** * Reads a 64-bit long from the given ArrayView starting at the given position. * * @param source The ArrayView to read from. * @param position The position in the ArrayView to start reading at. * @return The read number. */ public static long readLong(ArrayView source, int position) { return (long) (source.get(position) & 0xFF) << 56 | (long) (source.get(position + 1) & 0xFF) << 48 | (long) (source.get(position + 2) & 0xFF) << 40 | (long) (source.get(position + 3) & 0xFF) << 32 | (long) (source.get(position + 4) & 0xFF) << 24 | (source.get(position + 5) & 0xFF) << 16 | (source.get(position + 6) & 0xFF) << 8 | (source.get(position + 7) & 0xFF); }
/** * Validates the contents of the Event, based on information from its Header. */ void validateContents() { int offset = HEADER_LENGTH; int endOffset = offset + this.contentLength; int nextValue = this.sequence; while (offset < endOffset) { byte expectedValue = (byte) (nextValue % 255 + Byte.MIN_VALUE); if (this.serialization.get(offset) != expectedValue) { throw new IllegalStateException(String.format( "Event Corrupted. Payload at index %d differs. Expected %d, actual %d.", offset - HEADER_LENGTH, expectedValue, this.serialization.get(offset))); } nextValue += this.routingKey + 1; offset++; } }
/** * Reads the Entry's Header from the given {@link ArrayView}. * * @param input The {@link ArrayView} to read from. * @return The Entry Header. * @throws SerializationException If an invalid header was detected. */ Header readHeader(@NonNull ArrayView input) throws SerializationException { byte version = input.get(0); int keyLength = BitConverter.readInt(input, 1); int valueLength = BitConverter.readInt(input, 1 + Integer.BYTES); validateHeader(keyLength, valueLength); return new Header(version, keyLength, valueLength); }