protobuf/src/google/protobuf/any_lite.cc
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #include <google/protobuf/any.h>
32 
33 #include <google/protobuf/io/zero_copy_stream_impl_lite.h>
34 #include <google/protobuf/arenastring.h>
35 #include <google/protobuf/generated_message_util.h>
36 #include <google/protobuf/stubs/strutil.h>
37 
38 namespace google {
39 namespace protobuf {
40 namespace internal {
41 
42 std::string GetTypeUrl(StringPiece message_name,
43  StringPiece type_url_prefix) {
44  if (!type_url_prefix.empty() &&
45  type_url_prefix[type_url_prefix.size() - 1] == '/') {
46  return StrCat(type_url_prefix, message_name);
47  } else {
48  return StrCat(type_url_prefix, "/", message_name);
49  }
50 }
51 
52 const char kAnyFullTypeName[] = "google.protobuf.Any";
53 const char kTypeGoogleApisComPrefix[] = "type.googleapis.com/";
54 const char kTypeGoogleProdComPrefix[] = "type.googleprod.com/";
55 
57  StringPiece type_url_prefix,
60  GetTypeUrl(type_name, type_url_prefix), arena);
61  return message.SerializeToString(
63 }
64 
66  MessageLite* message) const {
67  if (!InternalIs(type_name)) {
68  return false;
69  }
70  return message->ParseFromString(value_->Get());
71 }
72 
73 bool AnyMetadata::InternalIs(StringPiece type_name) const {
74  StringPiece type_url = type_url_->Get();
75  return type_url.size() >= type_name.size() + 1 &&
76  type_url[type_url.size() - type_name.size() - 1] == '/' &&
78 }
79 
81  std::string* full_type_name) {
82  size_t pos = type_url.find_last_of('/');
83  if (pos == std::string::npos || pos + 1 == type_url.size()) {
84  return false;
85  }
86  if (url_prefix) {
87  *url_prefix = std::string(type_url.substr(0, pos + 1));
88  }
89  *full_type_name = std::string(type_url.substr(pos + 1));
90  return true;
91 }
92 
94  return ParseAnyTypeUrl(type_url, nullptr, full_type_name);
95 }
96 
97 } // namespace internal
98 } // namespace protobuf
99 } // namespace google
pos
int pos
Definition: libuv/docs/code/tty-gravity/main.c:11
google::protobuf.internal::AnyMetadata::value_
ValueType * value_
Definition: bloaty/third_party/protobuf/src/google/protobuf/any.h:115
google::protobuf.internal::ParseAnyTypeUrl
bool ParseAnyTypeUrl(const std::string &type_url, std::string *full_type_name)
Definition: bloaty/third_party/protobuf/src/google/protobuf/any_lite.cc:116
google::protobuf.internal::AnyMetadata::type_url_
UrlType * type_url_
Definition: bloaty/third_party/protobuf/src/google/protobuf/any.h:114
Arena
Definition: arena.c:39
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
google::protobuf.internal::kAnyFullTypeName
const char kAnyFullTypeName[]
Definition: bloaty/third_party/protobuf/src/google/protobuf/any_lite.cc:52
google::protobuf
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
google::protobuf.internal::ArenaStringPtr::Get
const ::std::string & Get() const
Definition: bloaty/third_party/protobuf/src/google/protobuf/arenastring.h:90
google::protobuf::MessageLite
Definition: bloaty/third_party/protobuf/src/google/protobuf/message_lite.h:184
message
char * message
Definition: libuv/docs/code/tty-gravity/main.c:12
google::protobuf::StrCat
string StrCat(const AlphaNum &a, const AlphaNum &b)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/strutil.cc:1482
arena
grpc_core::ScopedArenaPtr arena
Definition: binder_transport_test.cc:237
google::protobuf.internal::ArenaStringPtr::Mutable
inline ::std::string * Mutable(const ::std::string *default_value, Arena *arena)
Definition: bloaty/third_party/protobuf/src/google/protobuf/arenastring.h:92
google::protobuf.internal::kTypeGoogleApisComPrefix
const char kTypeGoogleApisComPrefix[]
Definition: bloaty/third_party/protobuf/src/google/protobuf/any_lite.cc:53
google::protobuf::StringPiece
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/stringpiece.h:180
google::protobuf.internal::AnyMetadata::InternalIs
bool InternalIs(StringPiece type_name) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/any_lite.cc:96
google::protobuf.internal::AnyMetadata::InternalUnpackTo
bool InternalUnpackTo(StringPiece type_name, MessageLite *message) const
Definition: bloaty/third_party/protobuf/src/google/protobuf/any_lite.cc:68
google::protobuf.internal::kTypeGoogleProdComPrefix
const char kTypeGoogleProdComPrefix[]
Definition: bloaty/third_party/protobuf/src/google/protobuf/any_lite.cc:54
google::protobuf.internal::GetEmptyString
const PROTOBUF_EXPORT std::string & GetEmptyString()
Definition: bloaty/third_party/protobuf/src/google/protobuf/generated_message_util.h:87
type_url
string * type_url
Definition: bloaty/third_party/protobuf/conformance/conformance_cpp.cc:72
google::protobuf.internal::ArenaStringPtr::EmptyDefault
Definition: protobuf/src/google/protobuf/arenastring.h:187
google::protobuf.internal::GetTypeUrl
std::string GetTypeUrl(StringPiece message_name, StringPiece type_url_prefix)
Definition: bloaty/third_party/protobuf/src/google/protobuf/any_lite.cc:42
internal
Definition: benchmark/test/output_test_helper.cc:20
google::protobuf::HasSuffixString
bool HasSuffixString(const string &str, const string &suffix)
Definition: bloaty/third_party/protobuf/src/google/protobuf/stubs/strutil.h:137
google
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:11
google::protobuf.internal::AnyMetadata::InternalPackFrom
void InternalPackFrom(const MessageLite &message, StringPiece type_url_prefix, StringPiece type_name)
Definition: bloaty/third_party/protobuf/src/google/protobuf/any_lite.cc:59
google::protobuf.internal::ArenaStringPtr::Set
void Set(const ::std::string *default_value, const ::std::string &value, Arena *arena)
Definition: bloaty/third_party/protobuf/src/google/protobuf/arenastring.h:75
type_name
static const char * type_name(int type)
Definition: adig.c:889


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:41