use of com.palantir.atlasdb.ptobject.EncodingUtils.EncodingType in project atlasdb by palantir.
the class EncodingUtilsTest method testMulti.
@Test
public void testMulti() {
List<ValueType> valueTypes = ImmutableList.of(ValueType.FIXED_LONG, ValueType.FIXED_LONG_LITTLE_ENDIAN, ValueType.SHA256HASH, ValueType.VAR_LONG, ValueType.VAR_SIGNED_LONG, ValueType.VAR_STRING);
Random random = new Random();
for (int j = 0; j < 50; j++) {
byte[] bytesToHash = new byte[256];
rand.nextBytes(bytesToHash);
List<Object> defaultComponents = ImmutableList.<Object>of(rand.nextLong(), rand.nextLong(), Sha256Hash.computeHash(bytesToHash), rand.nextLong() & Long.MAX_VALUE, rand.nextLong(), new BigInteger(100, random).toString(32));
List<EncodingType> types = Lists.newArrayList();
List<Object> components = Lists.newArrayList();
for (int i = 0; i < 50; i++) {
int index = rand.nextInt(valueTypes.size());
ValueType type = valueTypes.get(index);
ValueByteOrder order = rand.nextBoolean() ? ValueByteOrder.ASCENDING : ValueByteOrder.DESCENDING;
types.add(new EncodingType(type, order));
components.add(defaultComponents.get(index));
}
byte[] b = EncodingUtils.toBytes(types, components);
List<Object> result = EncodingUtils.fromBytes(b, types);
assertEquals(components, result);
}
}
use of com.palantir.atlasdb.ptobject.EncodingUtils.EncodingType in project atlasdb by palantir.
the class GeneralTaskCheckpointer method getRowName.
private byte[] getRowName(String extraId, long rangeId) {
List<EncodingType> types = ImmutableList.of(new EncodingType(ValueType.VAR_STRING), new EncodingType(ValueType.VAR_LONG));
List<Object> components = ImmutableList.<Object>of(extraId, rangeId);
return EncodingUtils.toBytes(types, components);
}
Aggregations