use of org.locationtech.geowave.core.store.flatten.FlattenedUnreadDataSingleRow in project geowave by locationtech.
the class DataStoreUtils method decomposeFlattenedFields.
/**
* Takes a byte array representing a serialized composite group of FieldInfos sharing a common
* visibility and returns a List of the individual FieldInfos
*
* @param bitmask the composite bitmask representing the fields contained within the
* flattenedValue
* @param flattenedValue the serialized composite FieldInfo
* @param commonVisibility the shared visibility
* @param maxFieldPosition can short-circuit read and defer decomposition of fields after a given
* position
* @return the dataset that has been read
*/
public static <T> FlattenedDataSet decomposeFlattenedFields(final byte[] bitmask, final byte[] flattenedValue, final byte[] commonVisibility, final int maxFieldPosition) {
final List<FlattenedFieldInfo> fieldInfoList = new LinkedList<>();
if ((flattenedValue != null) && (flattenedValue.length > 0)) {
if ((bitmask != null) && (bitmask.length > 0)) {
final List<Integer> fieldPositions = BitmaskUtils.getFieldPositions(bitmask);
final boolean sharedVisibility = fieldPositions.size() > 1;
if (sharedVisibility) {
final ByteBuffer input = ByteBuffer.wrap(flattenedValue);
for (int i = 0; i < fieldPositions.size(); i++) {
final Integer fieldPosition = fieldPositions.get(i);
if ((maxFieldPosition > -2) && (fieldPosition > maxFieldPosition)) {
return new FlattenedDataSet(fieldInfoList, new FlattenedUnreadDataSingleRow(input, i, fieldPositions));
}
final int fieldLength = VarintUtils.readUnsignedInt(input);
final byte[] fieldValueBytes = ByteArrayUtils.safeRead(input, fieldLength);
fieldInfoList.add(new FlattenedFieldInfo(fieldPosition, fieldValueBytes));
}
} else {
fieldInfoList.add(new FlattenedFieldInfo(fieldPositions.get(0), flattenedValue));
}
} else {
// assume fields are in positional order
final ByteBuffer input = ByteBuffer.wrap(flattenedValue);
for (int i = 0; input.hasRemaining(); i++) {
final Integer fieldPosition = i;
final int fieldLength = VarintUtils.readUnsignedInt(input);
final byte[] fieldValueBytes = ByteArrayUtils.safeRead(input, fieldLength);
fieldInfoList.add(new FlattenedFieldInfo(fieldPosition, fieldValueBytes));
}
}
}
return new FlattenedDataSet(fieldInfoList, null);
}
Aggregations