Search in sources :

Example 6 with NameComponentDescription

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

the class RowOrDynamicColumnRenderer method bytesHydrator.

private void bytesHydrator() {
    line("public static final Hydrator<", Name, "> BYTES_HYDRATOR = new Hydrator<", Name, ">() {");
    {
        line("@Override");
        line("public ", Name, " hydrateFromBytes(byte[] __input) {");
        {
            line("int __index = 0;");
            List<String> vars = Lists.newArrayList();
            for (NameComponentDescription comp : desc.getRowParts()) {
                String var = varName(comp);
                vars.add(var);
                if (comp.getOrder() == ValueByteOrder.ASCENDING) {
                    line(TypeName(comp), " ", var, " = ", comp.getType().getHydrateCode("__input", "__index"), ";");
                } else {
                    line(TypeName(comp), " ", var, " = ", comp.getType().getFlippedHydrateCode("__input", "__index"), ";");
                }
                line("__index += ", comp.getType().getHydrateSizeCode(var), ";");
            }
            line("return new ", Name, "(", Joiner.on(", ").join(vars), ");");
        }
        line("}");
    }
    line("};");
}
Also used : NameComponentDescription(com.palantir.atlasdb.table.description.NameComponentDescription)

Example 7 with NameComponentDescription

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

the class RowOrDynamicColumnRenderer method renderArgumentList.

private void renderArgumentList(int i) {
    lineEnd("(");
    for (NameComponentDescription comp : desc.getRowParts().subList(0, i)) {
        lineEnd(varName(comp), ", ");
    }
    replace(", ", ")");
}
Also used : NameComponentDescription(com.palantir.atlasdb.table.description.NameComponentDescription)

Example 8 with NameComponentDescription

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

the class AtlasDeserializers method deserializeRowish.

private static byte[] deserializeRowish(NameMetadataDescription description, JsonNode node, boolean mustBeFull) {
    if (node == null) {
        return new byte[0];
    }
    int size = node.size();
    List<NameComponentDescription> components = description.getRowParts();
    Preconditions.checkArgument(size <= components.size(), "Received %s values for a row with only %s components.", size, components.size());
    Preconditions.checkArgument(!mustBeFull || size == components.size(), "Received %s values for a row with %s components.", size, components.size());
    byte[][] bytes = new byte[size][];
    Iterator<JsonNode> rowValues = getComponentNodes(node, components);
    for (int i = 0; i < size; i++) {
        NameComponentDescription component = components.get(i);
        bytes[i] = component.getType().convertFromJson(rowValues.next().toString());
        if (component.isReverseOrder()) {
            EncodingUtils.flipAllBitsInPlace(bytes[i]);
        }
    }
    return Bytes.concat(bytes);
}
Also used : NameComponentDescription(com.palantir.atlasdb.table.description.NameComponentDescription) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 9 with NameComponentDescription

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

the class AtlasSerializers method serializeRowish.

public static void serializeRowish(JsonGenerator jgen, NameMetadataDescription rowDescription, byte[] row) throws IOException {
    int offset = 0;
    byte[] flippedRow = null;
    jgen.writeStartObject();
    for (NameComponentDescription part : rowDescription.getRowParts()) {
        if (part.isReverseOrder() && flippedRow == null) {
            flippedRow = EncodingUtils.flipAllBits(row);
        }
        Pair<String, Integer> parse;
        if (part.isReverseOrder()) {
            parse = part.getType().convertToJson(flippedRow, offset);
        } else {
            parse = part.getType().convertToJson(row, offset);
        }
        jgen.writeFieldName(part.getComponentName());
        jgen.writeRawValue(parse.getLhSide());
        offset += parse.getRhSide();
    }
    jgen.writeEndObject();
}
Also used : NameComponentDescription(com.palantir.atlasdb.table.description.NameComponentDescription)

Example 10 with NameComponentDescription

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

NameComponentDescription (com.palantir.atlasdb.table.description.NameComponentDescription)17 MethodSpec (com.squareup.javapoet.MethodSpec)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 RangeRequest (com.palantir.atlasdb.keyvalue.api.RangeRequest)2 BatchingVisitableView (com.palantir.common.base.BatchingVisitableView)2 ImmutableList (com.google.common.collect.ImmutableList)1 Lists (com.google.common.collect.Lists)1 RowResult (com.palantir.atlasdb.keyvalue.api.RowResult)1 ValueByteOrder (com.palantir.atlasdb.protos.generated.TableMetadataPersistence.ValueByteOrder)1 NameMetadataDescription (com.palantir.atlasdb.table.description.NameMetadataDescription)1 ValueType (com.palantir.atlasdb.table.description.ValueType)1 Persistables (com.palantir.common.persist.Persistables)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 SortedMap (java.util.SortedMap)1 Collectors (java.util.stream.Collectors)1