PiperOrigin-RevId: 666879420pull/17920/head
parent
138451296b
commit
9f4f302f9c
11 changed files with 357 additions and 53 deletions
@ -0,0 +1,40 @@ |
||||
#include "google/protobuf/compiler/rust/upb_helpers.h" |
||||
|
||||
#include <cstdint> |
||||
#include <string> |
||||
|
||||
#include "absl/log/absl_check.h" |
||||
#include "google/protobuf/descriptor.h" |
||||
#include "upb_generator/mangle.h" |
||||
|
||||
namespace google { |
||||
namespace protobuf { |
||||
namespace compiler { |
||||
namespace rust { |
||||
|
||||
std::string UpbMiniTableName(const Descriptor& msg) { |
||||
return upb::generator::MessageInit(msg.full_name()); |
||||
} |
||||
|
||||
uint32_t UpbMiniTableFieldIndex(const FieldDescriptor& field) { |
||||
auto* parent = field.containing_type(); |
||||
ABSL_CHECK(parent != nullptr); |
||||
|
||||
// TODO: b/361751487 - We should get the field_index from
|
||||
// UpbDefs directly, instead of independently matching
|
||||
// the sort order here.
|
||||
|
||||
uint32_t num_fields_with_lower_field_number = 0; |
||||
for (int i = 0; i < parent->field_count(); ++i) { |
||||
if (parent->field(i)->number() < field.number()) { |
||||
++num_fields_with_lower_field_number; |
||||
} |
||||
} |
||||
|
||||
return num_fields_with_lower_field_number; |
||||
} |
||||
|
||||
} // namespace rust
|
||||
} // namespace compiler
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
@ -0,0 +1,32 @@ |
||||
// Protocol Buffers - Google's data interchange format
|
||||
// Copyright 2024 Google LLC. All rights reserved.
|
||||
//
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file or at
|
||||
// https://developers.google.com/open-source/licenses/bsd
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_COMPILER_RUST_UPB_HELPERS_H__ |
||||
#define GOOGLE_PROTOBUF_COMPILER_RUST_UPB_HELPERS_H__ |
||||
|
||||
#include <cstdint> |
||||
#include <string> |
||||
|
||||
#include "google/protobuf/descriptor.h" |
||||
|
||||
namespace google { |
||||
namespace protobuf { |
||||
namespace compiler { |
||||
namespace rust { |
||||
|
||||
// The symbol name for the MiniTable generated by upb MiniTable C codegen.
|
||||
std::string UpbMiniTableName(const Descriptor& msg); |
||||
|
||||
// The field index that the provided field will be in a upb_MiniTable.
|
||||
uint32_t UpbMiniTableFieldIndex(const FieldDescriptor& field); |
||||
|
||||
} // namespace rust
|
||||
} // namespace compiler
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_COMPILER_RUST_UPB_HELPERS_H__
|
Loading…
Reference in new issue