MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / EmitVariableConfigs

Function EmitVariableConfigs

env/env_yaml.cc:818–894  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

816}
817
818void 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();

Callers 1

EnvConfigToYamlFunction · 0.85

Calls 5

EmitTypeInfoFunction · 0.85
kind_caseMethod · 0.80
FormatDurationFunction · 0.50
emptyMethod · 0.45
has_valueMethod · 0.45

Tested by

no test coverage detected