in src/aws-cpp-sdk-core/source/client/UserAgent.cpp [99:177]
Aws::String UserAgent::SerializeWithFeatures(const Aws::Set<UserAgentFeature>& features) const {
// Need to be in order
Aws::StringStream userAgentValue;
auto SerializeMetadata = [&](const Aws::String& metadataName, const Aws::String& metadataValue) -> void {
if (!metadataValue.empty()) {
userAgentValue << metadataName<< METADATA_DELIMINATOR << metadataValue << RWS;
}
};
auto SerializeMetadataWithVersion = [&](const Aws::String& metadataName, const Aws::String& metadataValue, const Aws::String& metadataVersion) -> void {
if (!metadataValue.empty() && !metadataVersion.empty()) {
userAgentValue << metadataName<< METADATA_DELIMINATOR << metadataValue << METADATA_VALUE_DELIMINATOR << metadataVersion << RWS;
}
};
SerializeMetadata(SDK_VERSION, m_sdkVersion);
if (!m_customizations.empty()) {
userAgentValue << m_customizations << RWS;
}
SerializeMetadata(UA_VERSION, m_userAgentVersion);
if (!m_api.empty()) {
SerializeMetadata(API_NAME, m_api);
}
SerializeMetadata(OS_VERSION, m_osVersion);
SerializeMetadataWithVersion(LANG, CPP, m_cppVersion);
SerializeMetadataWithVersion(METADATA, CRT_VERSION, m_crtVersion);
if (!m_execEnv.empty()) {
SerializeMetadata(EXEC_ENV, m_execEnv);
}
// Does not need to be in order
if (!m_archName.empty()) {
SerializeMetadataWithVersion(METADATA, ARCH, m_archName);
}
if (!m_appId.empty()) {
SerializeMetadata(APP_ID, m_appId);
}
if (!m_compilerMetadata.empty()) {
SerializeMetadata(METADATA, m_compilerMetadata);
}
// metrics
Aws::Vector<Aws::String> encodedMetrics{};
// add retry encoded value
if (!m_retryStrategyName.empty()) {
const auto* const retryFeature = std::find_if(
std::begin(RETRY_FEATURE_MAPPING), std::end(RETRY_FEATURE_MAPPING),
[this](const std::pair<const char*, UserAgentFeature>& pair) -> bool { return strcmp(pair.first, FilterUserAgentToken(m_retryStrategyName.c_str()).c_str()) == 0; });
if (retryFeature != std::end(RETRY_FEATURE_MAPPING)) {
encodedMetrics.emplace_back(BusinessMetricForFeature(retryFeature->second));
}
}
auto EncodeFeatures = [&encodedMetrics](const Aws::Set<UserAgentFeature>& features) -> void {
for (const auto& feature : features) {
auto encodedValue = BusinessMetricForFeature(feature);
if (!encodedValue.empty()) {
encodedMetrics.emplace_back(std::move(encodedValue));
}
}
};
// add all features attached to request.
EncodeFeatures(features);
EncodeFeatures(m_features);
// serialize the business metrics string.
if (!encodedMetrics.empty()) {
userAgentValue << BUSINESS_METRICS << METADATA_DELIMINATOR
<< std::accumulate(encodedMetrics.begin(), encodedMetrics.end(), Aws::String{},
[](const Aws::String& acc, const Aws::String& value) -> Aws::String {
return acc.empty() ? value : acc + "," + value;
});
}
return userAgentValue.str();
}