1 //
2 // Copyright 2018 gRPC authors.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 #ifndef GRPC_SRC_CORE_XDS_GRPC_XDS_COMMON_TYPES_PARSER_H
18 #define GRPC_SRC_CORE_XDS_GRPC_XDS_COMMON_TYPES_PARSER_H
19
20 #include "absl/types/optional.h"
21 #include "envoy/config/core/v3/base.upb.h"
22 #include "envoy/extensions/transport_sockets/tls/v3/tls.upb.h"
23 #include "google/protobuf/any.upb.h"
24 #include "google/protobuf/duration.upb.h"
25 #include "google/protobuf/struct.upb.h"
26 #include "google/protobuf/wrappers.upb.h"
27 #include "src/core/lib/iomgr/resolved_address.h"
28 #include "src/core/util/time.h"
29 #include "src/core/util/validation_errors.h"
30 #include "src/core/xds/grpc/xds_common_types.h"
31 #include "src/core/xds/xds_client/xds_resource_type.h"
32
33 namespace grpc_core {
34
35 Duration ParseDuration(const google_protobuf_Duration* proto_duration,
36 ValidationErrors* errors);
37
38 inline bool ParseBoolValue(const google_protobuf_BoolValue* bool_value_proto,
39 bool default_value = false) {
40 if (bool_value_proto == nullptr) return default_value;
41 return google_protobuf_BoolValue_value(bool_value_proto);
42 }
43
ParseUInt64Value(const google_protobuf_UInt64Value * proto)44 inline absl::optional<uint64_t> ParseUInt64Value(
45 const google_protobuf_UInt64Value* proto) {
46 if (proto == nullptr) return absl::nullopt;
47 return google_protobuf_UInt64Value_value(proto);
48 }
49
ParseUInt32Value(const google_protobuf_UInt32Value * proto)50 inline absl::optional<uint32_t> ParseUInt32Value(
51 const google_protobuf_UInt32Value* proto) {
52 if (proto == nullptr) return absl::nullopt;
53 return google_protobuf_UInt32Value_value(proto);
54 }
55
56 // Returns the IP address in URI form.
57 absl::optional<grpc_resolved_address> ParseXdsAddress(
58 const envoy_config_core_v3_Address* address, ValidationErrors* errors);
59
60 CommonTlsContext CommonTlsContextParse(
61 const XdsResourceType::DecodeContext& context,
62 const envoy_extensions_transport_sockets_tls_v3_CommonTlsContext*
63 common_tls_context_proto,
64 ValidationErrors* errors);
65
66 absl::StatusOr<Json> ParseProtobufStructToJson(
67 const XdsResourceType::DecodeContext& context,
68 const google_protobuf_Struct* resource);
69
70 absl::optional<XdsExtension> ExtractXdsExtension(
71 const XdsResourceType::DecodeContext& context,
72 const google_protobuf_Any* any, ValidationErrors* errors);
73
74 } // namespace grpc_core
75
76 #endif // GRPC_SRC_CORE_XDS_GRPC_XDS_COMMON_TYPES_PARSER_H
77