Go to the documentation of this file.
35 #include <google/protobuf/descriptor_database.h>
39 #include <google/protobuf/descriptor.pb.h>
40 #include <google/protobuf/stubs/map_util.h>
41 #include <google/protobuf/stubs/stl_util.h>
50 std::set<std::string>*
output) {
58 RecordMessageNames(d, full_name,
output);
63 std::set<std::string>*
output) {
69 template <
typename Fn>
71 std::vector<std::string>*
output) {
72 std::vector<std::string> file_names;
73 if (!db->FindAllFileNames(&file_names)) {
76 std::set<std::string>
set;
78 for (
const auto& f : file_names) {
80 if (!db->FindFileByName(f, &file_proto)) {
94 return ForAllFileProtos(
103 return ForAllFileProtos(
106 RecordMessageNames(file_proto,
set);
116 template <
typename Value>
130 for (
int i = 0;
i <
file.message_type_size();
i++) {
135 for (
int i = 0;
i <
file.enum_type_size();
i++) {
138 for (
int i = 0;
i <
file.extension_size();
i++) {
142 for (
int i = 0;
i <
file.service_size();
i++) {
153 bool ValidateSymbolName(StringPiece
name) {
154 for (
char c :
name) {
156 if (c !=
'.' && c !=
'_' && (c < '0' || c >
'9') && (c < 'A' || c >
'Z') &&
157 (c < 'a' || c >
'z')) {
167 template <
typename Container,
typename Key>
168 typename Container::const_iterator FindLastLessOrEqual(
176 template <
typename Container,
typename Key,
typename Cmp>
177 typename Container::const_iterator FindLastLessOrEqual(
187 bool IsSubSymbol(StringPiece sub_symbol, StringPiece super_symbol) {
188 return sub_symbol == super_symbol ||
190 super_symbol[sub_symbol.size()] ==
'.');
195 template <
typename Value>
203 if (!ValidateSymbolName(
name)) {
210 auto iter = FindLastLessOrEqual(&by_symbol_,
name);
212 if (
iter == by_symbol_.end()) {
219 if (IsSubSymbol(
iter->first,
name)) {
221 <<
"\" conflicts with the existing "
223 <<
iter->first <<
"\".";
234 if (
iter != by_symbol_.end() && IsSubSymbol(
name,
iter->first)) {
236 <<
"\" conflicts with the existing "
238 <<
iter->first <<
"\".";
252 template <
typename Value>
266 template <
typename Value>
270 if (!
field.extendee().empty() &&
field.extendee()[0] ==
'.') {
277 GOOGLE_LOG(
ERROR) <<
"Extension conflicts with extension already in database: "
291 template <
typename Value>
297 template <
typename Value>
300 auto iter = FindLastLessOrEqual(&by_symbol_,
name);
302 return (
iter != by_symbol_.end() && IsSubSymbol(
iter->first,
name))
307 template <
typename Value>
314 template <
typename Value>
317 typename std::map<std::pair<std::string, int>,
Value>::const_iterator
it =
319 bool success =
false;
323 output->push_back(
it->first.second);
330 template <
typename Value>
332 std::vector<std::string>*
output) {
333 output->resize(by_name_.size());
335 for (
const auto& kv : by_name_) {
336 (*output)[
i] = kv.first;
377 std::vector<std::string>*
output) {
384 if (
file ==
nullptr)
return false;
393 using Value = std::pair<const void*, int>;
396 template <
typename FileProto>
404 std::vector<int>*
output);
412 template <
typename DescProto>
415 template <
typename FieldProto>
495 auto package = entry.package(index);
504 template <
typename T,
typename U>
511 lhs_parts.first.substr(0, rhs_parts.first.size())
512 .compare(rhs_parts.first.substr(0, lhs_parts.first.size()))) {
515 }
else if (lhs_parts.first.size() == rhs_parts.first.size()) {
516 return lhs_parts.second < rhs_parts.second;
540 std::tuple<StringPiece, int>
b)
const {
556 if (
file.ParseFromArray(encoded_file_descriptor,
size)) {
560 "EncodedDescriptorDatabase::Add().";
586 if (encoded_file.first ==
nullptr)
return false;
591 encoded_file.second);
597 if (
input.ReadTagNoLastTag() == kNameTag) {
603 if (!file_proto.ParseFromArray(encoded_file.first, encoded_file.second)) {
623 template <
typename FileProto>
630 if (!ValidateSymbolName(
file.package())) {
663 template <
typename Iter,
typename Iter2,
typename Index>
667 if (IsSubSymbol((*iter)->AsString(
index), symbol_name)) {
669 <<
"\" conflicts with the existing symbol \""
670 << (*iter)->AsString(
index) <<
"\".";
681 if (*
iter !=
end && IsSubSymbol(symbol_name, (*iter)->AsString(
index))) {
683 <<
"\" conflicts with the existing symbol \""
684 << (*iter)->AsString(
index) <<
"\".";
702 if (!ValidateSymbolName(symbol)) {
730 template <
typename DescProto>
733 for (
const auto& nested_type :
message_type.nested_type()) {
742 template <
typename FieldProto>
745 if (!
field.extendee().empty() &&
field.extendee()[0] ==
'.') {
754 std::make_pair(
field.extendee().substr(1),
field.number()),
756 GOOGLE_LOG(
ERROR) <<
"Extension conflicts with extension already in database: "
758 <<
field.extendee() <<
" { " <<
field.name() <<
" = "
770 std::pair<const void*, int>
776 std::pair<const void*, int>
783 IsSubSymbol(
iter->AsString(*
this),
name)
788 std::pair<const void*, int>
793 auto it = std::lower_bound(
798 it->extension_number != field_number
799 ? std::make_pair(
nullptr, 0)
803 template <
typename T,
typename Less>
805 if (s->empty())
return;
806 std::vector<T> new_flat(s->size() + flat->size());
807 std::merge(s->begin(), s->end(), flat->begin(), flat->end(), &new_flat[0],
825 bool success =
false;
826 auto it = std::lower_bound(
832 output->push_back(
it->extension_number);
840 std::vector<std::string>*
output)
const {
843 for (
const auto& entry :
by_name_) {
853 std::pair<const void*, int>
861 ? std::make_pair(
nullptr, 0)
867 std::vector<std::string>*
output) {
874 if (encoded_file.first ==
nullptr)
return false;
875 return output->ParseFromArray(encoded_file.first, encoded_file.second);
896 if (
file ==
nullptr)
return false;
905 if (
file ==
nullptr)
return false;
915 if (extendee ==
nullptr)
return false;
918 pool_.FindExtensionByNumber(extendee, field_number);
928 const Descriptor* extendee =
pool_.FindMessageTypeByName(extendee_type);
929 if (extendee ==
nullptr)
return false;
931 std::vector<const FieldDescriptor*>
extensions;
945 sources_.push_back(source1);
946 sources_.push_back(source2);
949 const std::vector<DescriptorDatabase*>&
sources)
965 for (
size_t i = 0;
i < sources_.size();
i++) {
972 for (
size_t j = 0;
j <
i;
j++) {
987 for (
size_t i = 0;
i < sources_.size();
i++) {
995 for (
size_t j = 0;
j <
i;
j++) {
1009 std::set<int> merged_results;
1011 bool success =
false;
1014 if (source->FindAllExtensionNumbers(extendee_type, &
results)) {
1016 std::insert_iterator<std::set<int> >(merged_results,
1017 merged_results.begin()));
1023 std::copy(merged_results.begin(), merged_results.end(),
1024 std::insert_iterator<std::vector<int> >(*
output,
output->end()));
bool AddFile(const FileProto &file, Value value)
const std::string & name() const
DescriptorPoolDatabase(const DescriptorPool &pool)
Value FindExtension(StringPiece containing_type, int field_number)
~SimpleDescriptorDatabase() override
const Descriptor::ReservedRange value
void FindAllFileNames(std::vector< std::string > *output) const
bool FindAllExtensionNumbers(StringPiece containing_type, std::vector< int > *output)
std::vector< EncodedEntry > all_values_
std::vector< ExtensionEntry > by_extension_flat_
bool FindAllExtensionNumbers(const std::string &containing_type, std::vector< int > *output)
const DescriptorIndex & index
const Descriptor::ReservedRange const EnumValueDescriptor const MethodDescriptor extension
const grpc_generator::File * file
bool FindFileContainingSymbol(const std::string &symbol_name, FileDescriptorProto *output) override
bool MaybeParse(std::pair< const void *, int > encoded_file, FileDescriptorProto *output)
bool FindFileByName(const std::string &filename, FileDescriptorProto *output) override
bool FindFileContainingSymbol(const std::string &symbol_name, FileDescriptorProto *output) override
FieldDescriptorProto * AddExtension(FileDescriptorProto *file, const std::string &extendee, const std::string &name, int number, FieldDescriptorProto::Label label, FieldDescriptorProto::Type type)
static int copy(grpc_slice_buffer *input, grpc_slice_buffer *output)
std::string AsString(const DescriptorIndex &index) const
std::set< SymbolEntry, SymbolCompare > by_symbol_
bool FindFileContainingExtension(const std::string &containing_type, int field_number, FileDescriptorProto *output) override
bool FindFileContainingExtension(const std::string &containing_type, int field_number, FileDescriptorProto *output) override
~EncodedDescriptorDatabase() override
bool MaybeCopy(const FileDescriptorProto *file, FileDescriptorProto *output)
EncodedDescriptorDatabase()
bool operator()(const ExtensionEntry &a, std::tuple< StringPiece, int > b) const
std::vector< std::unique_ptr< const FileDescriptorProto > > files_to_delete_
const DescriptorIndex & index
StringPiece substr(size_type pos, size_type n=npos) const
bool Add(const void *encoded_file_descriptor, int size)
~DescriptorPoolDatabase() override
#define T(upbtypeconst, upbtype, ctype, default_value)
StringPiece package(const DescriptorIndex &index) const
string StrCat(const AlphaNum &a, const AlphaNum &b)
bool FindAllExtensionNumbers(const std::string &extendee_type, std::vector< int > *output) override
std::string AsString(const SymbolEntry &entry) const
SimpleDescriptorDatabase::DescriptorIndex< std::pair< const void *, int > > index_
Value FindFile(const std::string &filename)
const std::string & name() const
def Iter(n, format, sep='')
bool AddFile(const FileDescriptorProto &file, Value value)
bool FindNameOfFileContainingSymbol(const std::string &symbol_name, std::string *output)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
bool AddSymbol(const std::string &name, Value value)
constexpr absl::remove_reference_t< T > && move(T &&t) noexcept
const PROTOBUF_NAMESPACE_ID::DescriptorProto & message_type(int index) const
bool FindFileByName(const std::string &filename, FileDescriptorProto *output) override
bool operator()(std::tuple< StringPiece, int > a, const ExtensionEntry &b) const
MergedDescriptorDatabase(DescriptorDatabase *source1, DescriptorDatabase *source2)
Value FindExtension(const std::string &containing_type, int field_number)
GRPC_CUSTOM_CODEDINPUTSTREAM CodedInputStream
bool FindFileByName(const std::string &filename, FileDescriptorProto *output) override
bool FindFileByName(const std::string &filename, FileDescriptorProto *output) override
StringPiece extendee(const DescriptorIndex &index) const
void FindAllFileNames(std::vector< std::string > *output)
Value FindSymbol(const std::string &name)
GRPC_CUSTOM_DESCRIPTORDATABASE DescriptorDatabase
std::pair< StringPiece, StringPiece > GetParts(const SymbolEntry &entry) const
bool operator()(StringPiece a, const FileEntry &b) const
static void callback(void *arg, int status, int timeouts, struct hostent *host)
bool AddExtension(const std::string &filename, const FieldDescriptorProto &field, Value value)
bool FindAllExtensionNumbers(const std::string &extendee_type, std::vector< int > *output) override
bool operator()(const T &lhs, const U &rhs) const
PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final
String EncodeString(StringPiece str) const
Value FindFile(StringPiece filename)
bool HasPrefixString(const string &str, const string &prefix)
virtual ~DescriptorDatabase()
static const LogLevel ERROR
void CopyTo(FileDescriptorProto *proto) const
bool FindAllMessageNames(std::vector< std::string > *output)
bool AddSymbol(StringPiece symbol)
std::pair< const void *, int > Value
void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message &from) final
bool FindAllPackageNames(std::vector< std::string > *output)
bool AddExtension(StringPiece filename, const FieldProto &field)
const FieldDescriptor * field
std::set< ExtensionEntry, ExtensionCompare > by_extension_
std::pair< StringPiece, StringPiece > GetParts(StringPiece str) const
std::vector< FileEntry > by_name_flat_
bool FindFileContainingSymbol(const std::string &symbol_name, FileDescriptorProto *output) override
const std::string & name() const
bool AddAndOwn(const FileDescriptorProto *file)
const DescriptorIndex & index
internal::KeyMatcher< M > Key(M inner_matcher)
Value FindSymbolOnlyFlat(StringPiece name) const
bool FindFileContainingSymbol(const std::string &symbol_name, FileDescriptorProto *output) override
bool FindAllFileNames(std::vector< std::string > *output) override
bool AddCopy(const void *encoded_file_descriptor, int size)
std::vector< SymbolEntry > by_symbol_flat_
static const char prefix[]
#define GOOGLE_CHECK(EXPRESSION)
bool FindAllFileNames(std::vector< std::string > *output) override
bool FindAllExtensionNumbers(const std::string &extendee_type, std::vector< int > *output) override
bool AddNestedExtensions(const std::string &filename, const DescriptorProto &message_type, Value value)
bool operator()(const FileEntry &a, StringPiece b) const
std::set< FileEntry, FileCompare > by_name_
static StringPiece AsString(StringPiece str)
InternalDescriptorPool * pool
bool operator()(const ExtensionEntry &a, const ExtensionEntry &b) const
GRPC_CUSTOM_FILEDESCRIPTORPROTO FileDescriptorProto
bool FindFileContainingExtension(const std::string &containing_type, int field_number, FileDescriptorProto *output) override
const Collection::value_type::second_type & FindWithDefault(const Collection &collection, const typename Collection::value_type::first_type &key, const typename Collection::value_type::second_type &value)
static bool CheckForMutualSubsymbols(StringPiece symbol_name, Iter *iter, Iter2 end, const Index &index)
static void MergeIntoFlat(std::set< T, Less > *s, std::vector< T > *flat)
const std::string & name() const
DescriptorIndex< const FileDescriptorProto * > index_
const std::string & package() const
static PyObject * Index(PyContainer *self, PyObject *item)
SimpleDescriptorDatabase()
def merge(callgrind_files, srcs)
const FileDescriptor * file() const
bool operator()(const FileEntry &a, const FileEntry &b) const
std::vector< void * > files_to_delete_
#define GOOGLE_LOG(LEVEL)
bool FindFileContainingExtension(const std::string &containing_type, int field_number, FileDescriptorProto *output) override
bool AddNestedExtensions(StringPiece filename, const DescProto &message_type)
bool InsertIfNotPresent(Collection *const collection, const typename Collection::value_type &vt)
const PROTOBUF_NAMESPACE_ID::DescriptorProto & nested_type(int index) const
static struct async_container * container
bool FindAllExtensionNumbers(const std::string &extendee_type, std::vector< int > *output) override
Value FindSymbol(StringPiece name)
StringPiece name(const DescriptorIndex &index) const
StringPiece symbol(const DescriptorIndex &index) const
StringPiece DecodeString(const String &str, int) const
~MergedDescriptorDatabase() override
bool Add(const FileDescriptorProto &file)
const Descriptor::ReservedRange const EnumDescriptor::ReservedRange service
grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:14