proto_sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct FieldNumberSorter { | |
bool operator()(const FieldDescriptor* left, | |
const FieldDescriptor* right) const { | |
// Sorting by tag order. | |
return left->number() < right->number(); | |
} | |
}; | |
void Reflection::ListFieldsMayFailOnStripped( | |
const Message& message, bool should_fail, | |
std::vector<const FieldDescriptor*>* output) const { | |
// Traverse all fields in their order of declaration. | |
for (int i = 0; i <= last_non_weak_field_index; i++) { | |
const FieldDescriptor* field = descriptor_->field(i); | |
if (FieldSize(message, field) > 0) { | |
output->push_back(field); | |
} | |
} | |
// Sort by their tag number | |
std::sort(output->begin(), output->end(), FieldNumberSorter()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment