forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxds_resource.h
79 lines (68 loc) · 2.61 KB
/
xds_resource.h
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once
#include "envoy/common/exception.h"
#include "absl/strings/string_view.h"
#include "xds/core/v3/resource_locator.pb.h"
#include "xds/core/v3/resource_name.pb.h"
namespace Envoy {
namespace Config {
// Utilities for URI encoding/decoding of xds::core::v3::Resource{Name,Locator}.
class XdsResourceIdentifier {
public:
// Options for encoded URIs.
struct EncodeOptions {
// Should the context params be sorted by key? This provides deterministic encoding.
bool sort_context_params_{};
};
/**
* Encode a xds::core::v3::ResourceName message as a xdstp:// URN string.
*
* @param resource_name resource name message.
* @param options encoding options.
* @return std::string xdstp:// URN for resource_name.
*/
static std::string encodeUrn(const xds::core::v3::ResourceName& resource_name,
const EncodeOptions& options);
static std::string encodeUrn(const xds::core::v3::ResourceName& resource_name) {
return encodeUrn(resource_name, {});
}
/**
* Encode a xds::core::v3::ResourceLocator message as a xdstp:// URL string.
*
* @param resource_name resource name message.
* @param options encoding options.
* @return std::string xdstp:// URL for resource_name.
*/
static std::string encodeUrl(const xds::core::v3::ResourceLocator& resource_locator,
const EncodeOptions& options);
static std::string encodeUrl(const xds::core::v3::ResourceLocator& resource_locator) {
return encodeUrl(resource_locator, {});
}
// Thrown when an exception occurs during URI decoding.
class DecodeException : public EnvoyException {
public:
DecodeException(const std::string& what) : EnvoyException(what) {}
};
/**
* Decode a xdstp:// URN string to a xds::core::v3::ResourceName.
*
* @param resource_urn xdstp:// resource URN.
* @return xds::core::v3::ResourceName resource name message for resource_urn.
* @throws DecodeException when parsing fails.
*/
static xds::core::v3::ResourceName decodeUrn(absl::string_view resource_urn);
/**
* Decode a xdstp:// URL string to a xds::core::v3::ResourceLocator.
*
* @param resource_url xdstp:// resource URL.
* @return xds::core::v3::ResourceLocator resource name message for resource_url.
* @throws DecodeException when parsing fails.
*/
static xds::core::v3::ResourceLocator decodeUrl(absl::string_view resource_url);
/**
* @param resource_name resource name.
* @return bool does resource_name have a xdstp: scheme?
*/
static bool hasXdsTpScheme(absl::string_view resource_name);
};
} // namespace Config
} // namespace Envoy