Skip to content

Instantly share code, notes, and snippets.

@danlark1
Last active Apr 3, 2022
Embed
What would you like to do?
proto_sort
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