Small style guide, naming and formatting fixes

PiperOrigin-RevId: 519993508
pull/12339/head
Jakob Buchgraber 2 years ago committed by Copybara-Service
parent 8c92452c99
commit 4745f526d4
  1. 20
      src/google/protobuf/compiler/rust/generator.cc

@ -58,13 +58,13 @@ bool ExperimentalRustGeneratorEnabled(
});
}
// Marks which kernel Rust codegen assumes and generates gencode for.
// Marks which kernel the Rust codegen should generate code for.
enum class Kernel {
kUpb,
kCpp,
};
absl::optional<Kernel> ParsekernelConfiguration(
absl::optional<Kernel> ParseKernelConfiguration(
const std::vector<std::pair<std::string, std::string>>& options) {
for (const auto& pair : options) {
if (pair.first == "kernel") {
@ -79,7 +79,7 @@ absl::optional<Kernel> ParsekernelConfiguration(
return absl::nullopt;
}
std::string get_crate_name(const FileDescriptor* dependency) {
std::string GetCrateName(const FileDescriptor* dependency) {
absl::string_view path = dependency->name();
auto basename = path.substr(path.rfind('/') + 1);
return absl::StrReplaceAll(basename, {
@ -90,11 +90,14 @@ std::string get_crate_name(const FileDescriptor* dependency) {
void GenerateForUpb(const FileDescriptor* file, google::protobuf::io::Printer& p) {
for (int i = 0; i < file->message_type_count(); ++i) {
std::string full_name = file->message_type(i)->full_name();
absl::StrReplaceAll({{".", "_"}}, &full_name);
// The prefix used by the UPB compiler to generate unique function
// names.
std::string upb_msg_prefix = file->message_type(i)->full_name();
absl::StrReplaceAll({{".", "_"}}, &upb_msg_prefix);
// TODO(b/275365731): Implement field accessors et. al.
p.Emit({{"Msg", file->message_type(i)->name()}, {"pkg_Msg", full_name}},
p.Emit(
{{"Msg", file->message_type(i)->name()}, {"pkg_Msg", upb_msg_prefix}},
R"rs(
pub struct $Msg$ {
msg: ::__std::ptr::NonNull<u8>,
@ -107,6 +110,7 @@ void GenerateForUpb(const FileDescriptor* file, google::protobuf::io::Printer& p
let msg = unsafe { $pkg_Msg$_new(arena) };
$Msg$ { msg, arena }
}
pub fn serialize(&self) -> ::__pb::SerializedData {
let arena = unsafe { ::__pb::__runtime::upb_Arena_New() };
let mut len = 0;
@ -158,7 +162,7 @@ bool RustGenerator::Generate(const FileDescriptor* file,
return false;
}
absl::optional<Kernel> kernel = ParsekernelConfiguration(options);
absl::optional<Kernel> kernel = ParseKernelConfiguration(options);
if (!kernel.has_value()) {
*error =
"Mandatory option `kernel` missing, please specify `cpp` or "
@ -182,7 +186,7 @@ bool RustGenerator::Generate(const FileDescriptor* file,
// Rust crate names (currently Bazel labels).
for (int i = 0; i < file->public_dependency_count(); ++i) {
const FileDescriptor* dep = file->public_dependency(i);
std::string crate_name = get_crate_name(dep);
std::string crate_name = GetCrateName(dep);
for (int j = 0; j < dep->message_type_count(); ++j) {
// TODO(b/272728844): Implement real logic
p.Emit(

Loading…
Cancel
Save