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("};");
}
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(", ", ")");
}
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);
}
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();
}
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);
}
Aggregations