@Test void deserializationShouldRejectZeroLengthBytes() { assertThatThrownBy(() -> Bitlist.fromBytes(Bytes.EMPTY, BITLIST_MAX_SIZE)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("at least one byte"); }
public static Bitlist fromBytes(Bytes bytes, long maxSize) { int numBytes = bytes.size(); checkArgument(numBytes > 0, "Bitlist must contain at least one byte"); checkArgument(bytes.get(numBytes - 1) != 0, "Bitlist data must contain end marker bit"); int leadingBitIndex = 0; while ((bytes.get(numBytes - 1) >>> (7 - leadingBitIndex)) % 2 == 0) { leadingBitIndex++; } int bitlistSize = (7 - leadingBitIndex) + (8 * (numBytes - 1)); BitSet byteArray = new BitSet(bitlistSize); for (int i = bitlistSize - 1; i >= 0; i--) { if (((bytes.get(i / 8) >>> (i % 8)) & 0x01) == 1) { byteArray.set(i); } } return new Bitlist(bitlistSize, byteArray, maxSize); }
Bitlist { public static Bitlist fromBytes(Bytes bytes, long maxSize) { int numBytes = bytes.size(); checkArgument(numBytes > 0, "Bitlist must contain at least one byte"); checkArgument(bytes.get(numBytes - 1) != 0, "Bitlist data must contain end marker bit"); int leadingBitIndex = 0; while ((bytes.get(numBytes - 1) >>> (7 - leadingBitIndex)) % 2 == 0) { leadingBitIndex++; } int bitlistSize = (7 - leadingBitIndex) + (8 * (numBytes - 1)); BitSet byteArray = new BitSet(bitlistSize); for (int i = bitlistSize - 1; i >= 0; i--) { if (((bytes.get(i / 8) >>> (i % 8)) & 0x01) == 1) { byteArray.set(i); } } return new Bitlist(bitlistSize, byteArray, maxSize); } }
Bitlist { public static Bitlist fromBytes(Bytes bytes, long maxSize) { int numBytes = bytes.size(); checkArgument(numBytes > 0, "Bitlist must contain at least one byte"); checkArgument(bytes.get(numBytes - 1) != 0, "Bitlist data must contain end marker bit"); int leadingBitIndex = 0; while ((bytes.get(numBytes - 1) >>> (7 - leadingBitIndex)) % 2 == 0) { leadingBitIndex++; } int bitlistSize = (7 - leadingBitIndex) + (8 * (numBytes - 1)); BitSet byteArray = new BitSet(bitlistSize); for (int i = bitlistSize - 1; i >= 0; i--) { if (((bytes.get(i / 8) >>> (i % 8)) & 0x01) == 1) { byteArray.set(i); } } return new Bitlist(bitlistSize, byteArray, maxSize); } Bitlist(int arraySize, long maxSize);  Bitlist(Bitlist bitlist); private  Bitlist(int size, BitSet data, long maxSize); }
Bitlist { public static Bitlist fromBytes(Bytes bytes, long maxSize) { int numBytes = bytes.size(); checkArgument(numBytes > 0, "Bitlist must contain at least one byte"); checkArgument(bytes.get(numBytes - 1) != 0, "Bitlist data must contain end marker bit"); int leadingBitIndex = 0; while ((bytes.get(numBytes - 1) >>> (7 - leadingBitIndex)) % 2 == 0) { leadingBitIndex++; } int bitlistSize = (7 - leadingBitIndex) + (8 * (numBytes - 1)); BitSet byteArray = new BitSet(bitlistSize); for (int i = bitlistSize - 1; i >= 0; i--) { if (((bytes.get(i / 8) >>> (i % 8)) & 0x01) == 1) { byteArray.set(i); } } return new Bitlist(bitlistSize, byteArray, maxSize); } Bitlist(int arraySize, long maxSize);  Bitlist(Bitlist bitlist); private  Bitlist(int size, BitSet data, long maxSize); void setBit(int i); void setBits(int... indexes); boolean getBit(int i); int getBitCount(); boolean intersects(Bitlist other); boolean isSuperSetOf(final Bitlist other); List<Integer> getAllSetBits(); IntStream streamAllSetBits(); void setAllBits(Bitlist other); long getMaxSize(); int getCurrentSize(); @SuppressWarnings("NarrowingCompoundAssignment") Bytes serialize(); static int sszSerializationLength(final int size); static Bitlist fromBytes(Bytes bytes, long maxSize); Bitlist copy(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString(); }
Bitlist { public static Bitlist fromBytes(Bytes bytes, long maxSize) { int numBytes = bytes.size(); checkArgument(numBytes > 0, "Bitlist must contain at least one byte"); checkArgument(bytes.get(numBytes - 1) != 0, "Bitlist data must contain end marker bit"); int leadingBitIndex = 0; while ((bytes.get(numBytes - 1) >>> (7 - leadingBitIndex)) % 2 == 0) { leadingBitIndex++; } int bitlistSize = (7 - leadingBitIndex) + (8 * (numBytes - 1)); BitSet byteArray = new BitSet(bitlistSize); for (int i = bitlistSize - 1; i >= 0; i--) { if (((bytes.get(i / 8) >>> (i % 8)) & 0x01) == 1) { byteArray.set(i); } } return new Bitlist(bitlistSize, byteArray, maxSize); } Bitlist(int arraySize, long maxSize);  Bitlist(Bitlist bitlist); private  Bitlist(int size, BitSet data, long maxSize); void setBit(int i); void setBits(int... indexes); boolean getBit(int i); int getBitCount(); boolean intersects(Bitlist other); boolean isSuperSetOf(final Bitlist other); List<Integer> getAllSetBits(); IntStream streamAllSetBits(); void setAllBits(Bitlist other); long getMaxSize(); int getCurrentSize(); @SuppressWarnings("NarrowingCompoundAssignment") Bytes serialize(); static int sszSerializationLength(final int size); static Bitlist fromBytes(Bytes bytes, long maxSize); Bitlist copy(); @Override boolean equals(final Object o); @Override int hashCode(); @Override String toString();  }