|
14 | 14 |
|
15 | 15 | #include <viam/api/common/v1/common.pb.h> |
16 | 16 |
|
| 17 | +#include <viam/sdk/common/private/utils.hpp> |
17 | 18 | #include <viam/sdk/common/private/version_metadata.hpp> |
18 | 19 | #include <viam/sdk/components/component.hpp> |
19 | 20 | #include <viam/sdk/registry/registry.hpp> |
@@ -108,6 +109,53 @@ void ClientContext::set_client_ctx_authority_() { |
108 | 109 | wrapped_context_.set_authority("viam-placeholder"); |
109 | 110 | } |
110 | 111 |
|
| 112 | +std::string random_debug_key() { |
| 113 | + static const char alphanum[] = "abcdefghijklmnopqrstuvwxyz"; |
| 114 | + static std::default_random_engine generator( |
| 115 | + std::chrono::system_clock::now().time_since_epoch().count()); |
| 116 | + std::uniform_int_distribution<int> distribution(0, sizeof(alphanum) - 1); |
| 117 | + |
| 118 | + std::string key; |
| 119 | + key.reserve(6); |
| 120 | + |
| 121 | + for (int i = 0; i < 6; ++i) { |
| 122 | + key += alphanum[distribution(generator)]; |
| 123 | + }; |
| 124 | + |
| 125 | + return key; |
| 126 | +} |
| 127 | + |
| 128 | +AttributeMap debug_map() { |
| 129 | + auto debug_key = random_debug_key(); |
| 130 | + return debug_map(debug_key); |
| 131 | +} |
| 132 | + |
| 133 | +AttributeMap debug_map(std::string debug_key) { |
| 134 | + AttributeMap map = |
| 135 | + std::make_shared<std::unordered_map<std::string, std::shared_ptr<ProtoType>>>(); |
| 136 | + map->emplace(impl::debug_map_key, std::make_shared<ProtoType>(std::move(debug_key))); |
| 137 | + |
| 138 | + return map; |
| 139 | +} |
| 140 | + |
| 141 | +AttributeMap add_debug_entry(AttributeMap map, std::string debug_key) { |
| 142 | + map->emplace(impl::debug_map_key, std::make_shared<ProtoType>(std::move(debug_key))); |
| 143 | + return map; |
| 144 | +} |
| 145 | + |
| 146 | +AttributeMap add_debug_entry(AttributeMap&& map, std::string debug_key) { |
| 147 | + return add_debug_entry(map, std::move(debug_key)); |
| 148 | +} |
| 149 | + |
| 150 | +AttributeMap add_debug_entry(AttributeMap&& map) { |
| 151 | + auto debug_key = random_debug_key(); |
| 152 | + return add_debug_entry(map, std::move(debug_key)); |
| 153 | +} |
| 154 | + |
| 155 | +void ClientContext::set_debug_key(const std::string& debug_key) { |
| 156 | + wrapped_context_.AddMetadata("dtname", debug_key); |
| 157 | +} |
| 158 | + |
111 | 159 | void ClientContext::add_viam_client_version_() { |
112 | 160 | wrapped_context_.AddMetadata("viam_client", impl::k_version); |
113 | 161 | } |
|
0 commit comments