Skip to content

Instantly share code, notes, and snippets.

Last active April 3, 2022 13:12
What would you like to do?
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) {
// 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