1 #include "google/protobuf/compiler/rust/upb_helpers.h" 2 3 #include <cstdint> 4 #include <string> 5 6 #include "absl/log/absl_check.h" 7 #include "google/protobuf/descriptor.h" 8 #include "upb_generator/minitable/names.h" 9 10 namespace google { 11 namespace protobuf { 12 namespace compiler { 13 namespace rust { 14 UpbMiniTableName(const Descriptor & msg)15std::string UpbMiniTableName(const Descriptor& msg) { 16 return upb::generator::MiniTableMessageVarName(msg.full_name()); 17 } 18 UpbMiniTableFieldIndex(const FieldDescriptor & field)19uint32_t UpbMiniTableFieldIndex(const FieldDescriptor& field) { 20 auto* parent = field.containing_type(); 21 ABSL_CHECK(parent != nullptr); 22 23 // TODO: b/361751487 - We should get the field_index from 24 // UpbDefs directly, instead of independently matching 25 // the sort order here. 26 27 uint32_t num_fields_with_lower_field_number = 0; 28 for (int i = 0; i < parent->field_count(); ++i) { 29 if (parent->field(i)->number() < field.number()) { 30 ++num_fields_with_lower_field_number; 31 } 32 } 33 34 return num_fields_with_lower_field_number; 35 } 36 37 } // namespace rust 38 } // namespace compiler 39 } // namespace protobuf 40 } // namespace google 41