Merge "Clean up toStatsDimensionsValueParcel" into rvc-dev am: f555086191
Change-Id: I01c793c9ab7bcfbab574cbb5a258c9f197f2cfac
This commit is contained in:
@@ -40,53 +40,62 @@ const static int STATS_DIMENSIONS_VALUE_TUPLE_TYPE = 7;
|
|||||||
* Recursive helper function that populates a parent StatsDimensionsValueParcel
|
* Recursive helper function that populates a parent StatsDimensionsValueParcel
|
||||||
* with children StatsDimensionsValueParcels.
|
* with children StatsDimensionsValueParcels.
|
||||||
*
|
*
|
||||||
|
* \param parent parcel that will be populated with children
|
||||||
|
* \param childDepth depth of children FieldValues
|
||||||
|
* \param childPrefix expected FieldValue prefix of children
|
||||||
* \param dims vector of FieldValues stored by HashableDimensionKey
|
* \param dims vector of FieldValues stored by HashableDimensionKey
|
||||||
* \param index positions in dims vector to start reading children from
|
* \param index position in dims to start reading children from
|
||||||
* \param depth level of parent parcel in the full StatsDimensionsValueParcel
|
|
||||||
* tree
|
|
||||||
*/
|
*/
|
||||||
static void populateStatsDimensionsValueParcelChildren(StatsDimensionsValueParcel &parentParcel,
|
static void populateStatsDimensionsValueParcelChildren(StatsDimensionsValueParcel& parent,
|
||||||
const vector<FieldValue>& dims, size_t& index,
|
int childDepth, int childPrefix,
|
||||||
int depth, int prefix) {
|
const vector<FieldValue>& dims,
|
||||||
|
size_t& index) {
|
||||||
|
if (childDepth > 2) {
|
||||||
|
ALOGE("Depth > 2 not supported by StatsDimensionsValueParcel.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
while (index < dims.size()) {
|
while (index < dims.size()) {
|
||||||
const FieldValue& dim = dims[index];
|
const FieldValue& dim = dims[index];
|
||||||
int fieldDepth = dim.mField.getDepth();
|
int fieldDepth = dim.mField.getDepth();
|
||||||
int fieldPrefix = dim.mField.getPrefix(depth);
|
int fieldPrefix = dim.mField.getPrefix(childDepth);
|
||||||
StatsDimensionsValueParcel childParcel;
|
|
||||||
childParcel.field = dim.mField.getPosAtDepth(depth);
|
StatsDimensionsValueParcel child;
|
||||||
if (depth > 2) {
|
child.field = dim.mField.getPosAtDepth(childDepth);
|
||||||
ALOGE("Depth > 2 not supported by StatsDimensionsValueParcel.");
|
|
||||||
return;
|
if (fieldDepth == childDepth && fieldPrefix == childPrefix) {
|
||||||
}
|
|
||||||
if (depth == fieldDepth && prefix == fieldPrefix) {
|
|
||||||
switch (dim.mValue.getType()) {
|
switch (dim.mValue.getType()) {
|
||||||
case INT:
|
case INT:
|
||||||
childParcel.valueType = STATS_DIMENSIONS_VALUE_INT_TYPE;
|
child.valueType = STATS_DIMENSIONS_VALUE_INT_TYPE;
|
||||||
childParcel.intValue = dim.mValue.int_value;
|
child.intValue = dim.mValue.int_value;
|
||||||
break;
|
break;
|
||||||
case LONG:
|
case LONG:
|
||||||
childParcel.valueType = STATS_DIMENSIONS_VALUE_LONG_TYPE;
|
child.valueType = STATS_DIMENSIONS_VALUE_LONG_TYPE;
|
||||||
childParcel.longValue = dim.mValue.long_value;
|
child.longValue = dim.mValue.long_value;
|
||||||
break;
|
break;
|
||||||
case FLOAT:
|
case FLOAT:
|
||||||
childParcel.valueType = STATS_DIMENSIONS_VALUE_FLOAT_TYPE;
|
child.valueType = STATS_DIMENSIONS_VALUE_FLOAT_TYPE;
|
||||||
childParcel.floatValue = dim.mValue.float_value;
|
child.floatValue = dim.mValue.float_value;
|
||||||
break;
|
break;
|
||||||
case STRING:
|
case STRING:
|
||||||
childParcel.valueType = STATS_DIMENSIONS_VALUE_STRING_TYPE;
|
child.valueType = STATS_DIMENSIONS_VALUE_STRING_TYPE;
|
||||||
childParcel.stringValue = dim.mValue.str_value;
|
child.stringValue = dim.mValue.str_value;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
ALOGE("Encountered FieldValue with unsupported value type.");
|
ALOGE("Encountered FieldValue with unsupported value type.");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
parentParcel.tupleValue.push_back(childParcel);
|
parent.tupleValue.push_back(child);
|
||||||
} else if (fieldDepth > depth && fieldPrefix == prefix) {
|
} else if (fieldDepth > childDepth && fieldPrefix == childPrefix) {
|
||||||
childParcel.valueType = STATS_DIMENSIONS_VALUE_TUPLE_TYPE;
|
// This FieldValue is not a child of the current parent, but it is
|
||||||
populateStatsDimensionsValueParcelChildren(childParcel, dims, index, depth + 1,
|
// an indirect descendant. Thus, create a direct child of TUPLE_TYPE
|
||||||
dim.mField.getPrefix(depth + 1));
|
// and recurse to parcel the indirect descendants.
|
||||||
parentParcel.tupleValue.push_back(childParcel);
|
child.valueType = STATS_DIMENSIONS_VALUE_TUPLE_TYPE;
|
||||||
|
populateStatsDimensionsValueParcelChildren(child, childDepth + 1,
|
||||||
|
dim.mField.getPrefix(childDepth + 1), dims,
|
||||||
|
index);
|
||||||
|
parent.tupleValue.push_back(child);
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -94,17 +103,21 @@ static void populateStatsDimensionsValueParcelChildren(StatsDimensionsValueParce
|
|||||||
}
|
}
|
||||||
|
|
||||||
StatsDimensionsValueParcel HashableDimensionKey::toStatsDimensionsValueParcel() const {
|
StatsDimensionsValueParcel HashableDimensionKey::toStatsDimensionsValueParcel() const {
|
||||||
StatsDimensionsValueParcel parcel;
|
StatsDimensionsValueParcel root;
|
||||||
if (mValues.size() == 0) {
|
if (mValues.size() == 0) {
|
||||||
return parcel;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
parcel.field = mValues[0].mField.getTag();
|
root.field = mValues[0].mField.getTag();
|
||||||
parcel.valueType = STATS_DIMENSIONS_VALUE_TUPLE_TYPE;
|
root.valueType = STATS_DIMENSIONS_VALUE_TUPLE_TYPE;
|
||||||
|
|
||||||
|
// Children of the root correspond to top-level (depth = 0) FieldValues.
|
||||||
|
int childDepth = 0;
|
||||||
|
int childPrefix = 0;
|
||||||
size_t index = 0;
|
size_t index = 0;
|
||||||
populateStatsDimensionsValueParcelChildren(parcel, mValues, index, /*depth=*/0, /*prefix=*/0);
|
populateStatsDimensionsValueParcelChildren(root, childDepth, childPrefix, mValues, index);
|
||||||
return parcel;
|
|
||||||
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
android::hash_t hashDimension(const HashableDimensionKey& value) {
|
android::hash_t hashDimension(const HashableDimensionKey& value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user