protoMessageFieldIndexes function
Returns the indexes (not tags!) of the message (i.e. non-primitive) fields that might be set.
Includes at most one value for each "oneOf".
The results are not sorted.
Implementation
List<int> protoMessageFieldIndexes(GeneratedMessage proto) {
final metadata = _messageMetadata(proto);
if (metadata.numOneOfFields == 0) {
// No oneof fields - just return the non-oneof message field indexes.
return metadata.nonOneOfMessageFieldIndexes;
}
final result = List<int>.from(metadata.nonOneOfMessageFieldIndexes);
// Iterate over the oneof fields and add the indexes of the set fields to the
// result.
for (var i = 0; i < metadata.numOneOfFields; i++) {
final tag = proto.$_whichOneof(i);
if (tag != 0) {
final index = metadata.tagToIndex[tag];
if (index >= 0) {
result.add(index);
}
}
}
return result;
}