Search in sources :

Example 1 with EncodingType

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);
    }
}
Also used : ValueByteOrder(com.palantir.atlasdb.protos.generated.TableMetadataPersistence.ValueByteOrder) Random(java.util.Random) ValueType(com.palantir.atlasdb.table.description.ValueType) EncodingType(com.palantir.atlasdb.ptobject.EncodingUtils.EncodingType) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 2 with EncodingType

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);
}
Also used : EncodingType(com.palantir.atlasdb.ptobject.EncodingUtils.EncodingType)

Aggregations

EncodingType (com.palantir.atlasdb.ptobject.EncodingUtils.EncodingType)2 ValueByteOrder (com.palantir.atlasdb.protos.generated.TableMetadataPersistence.ValueByteOrder)1 ValueType (com.palantir.atlasdb.table.description.ValueType)1 BigInteger (java.math.BigInteger)1 Random (java.util.Random)1 Test (org.junit.Test)1