-
Notifications
You must be signed in to change notification settings - Fork 16.1k
Expand file tree
/
Copy pathany.cc
More file actions
65 lines (54 loc) · 2.38 KB
/
any.cc
File metadata and controls
65 lines (54 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. 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
#include "google/protobuf/any.h"
#include "absl/strings/cord.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/generated_message_util.h"
#include "google/protobuf/message.h"
// Must be included last.
#include "google/protobuf/port_def.inc"
namespace google {
namespace protobuf {
namespace internal {
using UrlType = std::string;
using ValueType = std::string;
bool InternalPackFrom(const Message& message, UrlType* PROTOBUF_NONNULL dst_url,
ValueType* PROTOBUF_NONNULL dst_value) {
return InternalPackFromLite(message, kTypeGoogleApisComPrefix,
message.GetTypeName(), dst_url, dst_value);
}
bool InternalPackFrom(const Message& message, absl::string_view type_url_prefix,
UrlType* PROTOBUF_NONNULL dst_url,
ValueType* PROTOBUF_NONNULL dst_value) {
return InternalPackFromLite(message, type_url_prefix, message.GetTypeName(),
dst_url, dst_value);
}
bool InternalUnpackTo(absl::string_view type_url, const ValueType& value,
Message* PROTOBUF_NONNULL message) {
return InternalUnpackToLite(message->GetTypeName(), type_url, value, message);
}
bool GetAnyFieldDescriptors(const Message& message,
const FieldDescriptor * PROTOBUF_NULLABLE *
PROTOBUF_NONNULL type_url_field,
const FieldDescriptor * PROTOBUF_NULLABLE *
PROTOBUF_NONNULL value_field) {
const Descriptor* descriptor = message.GetDescriptor();
if (descriptor->full_name() != kAnyFullTypeName) {
return false;
}
*type_url_field = descriptor->FindFieldByNumber(1);
*value_field = descriptor->FindFieldByNumber(2);
return (*type_url_field != nullptr &&
(*type_url_field)->type() == FieldDescriptor::TYPE_STRING &&
*value_field != nullptr &&
(*value_field)->type() == FieldDescriptor::TYPE_BYTES);
}
} // namespace internal
} // namespace protobuf
} // namespace google
#include "google/protobuf/port_undef.inc"