Protocol Buffers - Google's data interchange format (grpc依赖)
https://developers.google.com/protocol-buffers/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.8 KiB
70 lines
1.8 KiB
1 year ago
|
// Protocol Buffers - Google's data interchange format
|
||
|
// Copyright 2023 Google LLC. All rights reserved.
|
||
2 years ago
|
//
|
||
1 year ago
|
// 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
|
||
2 years ago
|
|
||
6 months ago
|
#include "hpb_generator/output.h"
|
||
2 years ago
|
|
||
2 years ago
|
#include <string>
|
||
|
|
||
2 years ago
|
#include "absl/strings/str_replace.h"
|
||
|
|
||
|
namespace protos_generator {
|
||
|
namespace {
|
||
|
|
||
|
namespace protobuf = ::google::protobuf;
|
||
|
|
||
|
} // namespace
|
||
|
|
||
|
std::string StripExtension(absl::string_view fname) {
|
||
|
size_t lastdot = fname.find_last_of('.');
|
||
|
if (lastdot == std::string::npos) {
|
||
|
return std::string(fname);
|
||
|
}
|
||
|
return std::string(fname.substr(0, lastdot));
|
||
|
}
|
||
|
|
||
|
std::string ToCIdent(absl::string_view str) {
|
||
|
return absl::StrReplaceAll(str, {{".", "_"}, {"/", "_"}, {"-", "_"}});
|
||
|
}
|
||
|
|
||
|
std::string ToPreproc(absl::string_view str) {
|
||
|
return absl::AsciiStrToUpper(ToCIdent(str));
|
||
|
}
|
||
|
|
||
|
void EmitFileWarning(const protobuf::FileDescriptor* file, Output& output) {
|
||
|
output(
|
||
|
R"cc(
|
||
|
/* This file was generated by protos_generator (the upb C++ compiler) "
|
||
|
from the input
|
||
|
* file:
|
||
|
*
|
||
|
* $0
|
||
|
*
|
||
|
* Do not edit -- your changes will be discarded when the file is
|
||
|
* regenerated. */
|
||
|
)cc",
|
||
|
file->name());
|
||
|
output("\n");
|
||
|
}
|
||
|
|
||
|
std::string MessageName(const protobuf::Descriptor* descriptor) {
|
||
|
return ToCIdent(descriptor->full_name());
|
||
|
}
|
||
|
|
||
|
std::string FileLayoutName(const google::protobuf::FileDescriptor* file) {
|
||
|
return ToCIdent(file->name()) + "_upb_file_layout";
|
||
|
}
|
||
|
|
||
|
std::string CHeaderFilename(const google::protobuf::FileDescriptor* file) {
|
||
|
return StripExtension(file->name()) + ".upb.h";
|
||
|
}
|
||
|
|
||
|
std::string CSourceFilename(const google::protobuf::FileDescriptor* file) {
|
||
|
return StripExtension(file->name()) + ".upb.c";
|
||
|
}
|
||
|
|
||
|
} // namespace protos_generator
|