Search in sources :

Example 1 with ValueType

use of com.palantir.atlasdb.table.description.ValueType 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 ValueType

use of com.palantir.atlasdb.table.description.ValueType in project atlasdb by palantir.

the class TableMetadataDeserializer method deserializeRowish.

private NameMetadataDescription deserializeRowish(JsonNode node) {
    List<NameComponentDescription> rowComponents = Lists.newArrayList();
    for (JsonNode rowNode : node.get("row")) {
        String name = rowNode.get("name").asText();
        ValueType type = ValueType.valueOf(rowNode.get("type").asText());
        ValueByteOrder order = ValueByteOrder.valueOf(rowNode.get("order").asText());
        rowComponents.add(new NameComponentDescription.Builder().componentName(name).type(type).byteOrder(order).build());
    }
    return NameMetadataDescription.create(rowComponents);
}
Also used : NameComponentDescription(com.palantir.atlasdb.table.description.NameComponentDescription) ValueByteOrder(com.palantir.atlasdb.protos.generated.TableMetadataPersistence.ValueByteOrder) ValueType(com.palantir.atlasdb.table.description.ValueType) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

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