| 816 | } |
| 817 | |
| 818 | void EmitVariableConfigs(const Config& env_config, YAML::Emitter& out) { |
| 819 | const auto& variable_configs = env_config.GetVariableConfigs(); |
| 820 | if (variable_configs.empty()) { |
| 821 | return; |
| 822 | } |
| 823 | |
| 824 | // Sort variable_configs by name to ensure deterministic output. |
| 825 | std::vector<Config::VariableConfig> sorted_variable_configs = |
| 826 | variable_configs; |
| 827 | absl::c_sort(sorted_variable_configs, |
| 828 | [](const Config::VariableConfig& a, |
| 829 | const Config::VariableConfig& b) { return a.name < b.name; }); |
| 830 | |
| 831 | out << YAML::Key << "variables"; |
| 832 | out << YAML::Value << YAML::BeginSeq; |
| 833 | for (const Config::VariableConfig& variable_config : |
| 834 | sorted_variable_configs) { |
| 835 | out << YAML::BeginMap; |
| 836 | out << YAML::Key << "name"; |
| 837 | out << YAML::Value << YAML::DoubleQuoted << variable_config.name; |
| 838 | if (!variable_config.description.empty()) { |
| 839 | out << YAML::Key << "description"; |
| 840 | out << YAML::Value << YAML::DoubleQuoted << variable_config.description; |
| 841 | } |
| 842 | EmitTypeInfo(variable_config.type_info, out); |
| 843 | if (variable_config.value.has_value()) { |
| 844 | const Constant& constant = variable_config.value; |
| 845 | switch (constant.kind_case()) { |
| 846 | case ConstantKindCase::kUnspecified: |
| 847 | case ConstantKindCase::kNull: |
| 848 | break; |
| 849 | case ConstantKindCase::kBool: |
| 850 | out << YAML::Key << "value" << YAML::Value << constant.bool_value(); |
| 851 | break; |
| 852 | case ConstantKindCase::kInt: |
| 853 | out << YAML::Key << "value" << YAML::Value << constant.int_value(); |
| 854 | break; |
| 855 | case ConstantKindCase::kUint: |
| 856 | out << YAML::Key << "value" << YAML::Value << constant.uint_value(); |
| 857 | break; |
| 858 | case ConstantKindCase::kDouble: |
| 859 | out << YAML::Key << "value" << YAML::Value << constant.double_value(); |
| 860 | break; |
| 861 | case ConstantKindCase::kBytes: { |
| 862 | out << YAML::Key << "value"; |
| 863 | const std::string& bytes_value = constant.bytes_value(); |
| 864 | std::string hex_escaped = "b\""; |
| 865 | for (unsigned char byte : bytes_value) { |
| 866 | absl::StrAppend(&hex_escaped, "\\x"); |
| 867 | absl::StrAppendFormat(&hex_escaped, "%02x", byte); |
| 868 | } |
| 869 | absl::StrAppend(&hex_escaped, "\""); |
| 870 | out << YAML::Value << hex_escaped; |
| 871 | break; |
| 872 | } |
| 873 | case ConstantKindCase::kString: |
| 874 | out << YAML::Key << "value"; |
| 875 | out << YAML::Value << YAML::DoubleQuoted << constant.string_value(); |
no test coverage detected