提交 538245e3 编写于 作者: A Aaron Xiao 提交者: Jiangtao Hu

Common: Retire yaml_util which is not used.

上级 68f02852
......@@ -268,34 +268,6 @@ cc_test(
],
)
cc_library(
name = "yaml_util",
srcs = [
"yaml_util.cc",
],
hdrs = [
"yaml_util.h",
],
deps = [
"@com_google_protobuf//:protobuf",
"@yaml_cpp//:yaml",
],
)
cc_test(
name = "yaml_util_test",
size = "small",
srcs = [
"yaml_util_test.cc",
],
deps = [
":util",
":yaml_util",
"//modules/common/util/testdata:simple_proto",
"@gtest//:main",
],
)
cc_library(
name = "http_client",
srcs = ["http_client.cc"],
......
message {
integer: 1
text: "234"
header {
module_name: "Message 1"
status {
msg: "Status"
error_code: OK
}
}
}
message {
integer: 2
}
message:
- integer: 1
text: "234"
header:
module_name: "Message 1"
status:
msg: "Status"
error_code: "OK"
- integer: 2
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/common/util/yaml_util.h"
#include <google/protobuf/util/json_util.h>
#include <yaml-cpp/yaml.h>
namespace apollo {
namespace common {
namespace util {
namespace {
void YamlNodeToJson(const YAML::Node& node, std::ostringstream* oss) {
switch (node.Type()) {
case YAML::NodeType::Undefined:
*oss << "\"\"";
break;
case YAML::NodeType::Null:
*oss << "\"\"";
break;
case YAML::NodeType::Scalar:
*oss << "\"" << node.as<std::string>() << "\"";
break;
case YAML::NodeType::Sequence:
*oss << "[\n";
for (const auto& sub_node : node) {
YamlNodeToJson(sub_node, oss);
*oss << ", ";
}
*oss << "]\n";
break;
case YAML::NodeType::Map:
*oss << "{\n";
for (const auto& sub_node : node) {
YamlNodeToJson(sub_node.first, oss);
*oss << ": ";
YamlNodeToJson(sub_node.second, oss);
*oss << ",\n";
}
*oss << "}\n";
break;
}
}
} // namespace
// Load YAML file to an equivalent json string.
std::string YamlToJson(const std::string& yaml_file) {
std::ostringstream oss;
YamlNodeToJson(YAML::LoadFile(yaml_file), &oss);
return oss.str();
}
// Load YAML file to an equivalent proto message.
// Return false if failed.
bool YamlToProto(const std::string& yaml_file,
google::protobuf::Message* proto) {
const std::string json = YamlToJson(yaml_file);
return google::protobuf::util::JsonStringToMessage(json, proto).ok();
}
} // namespace util
} // namespace common
} // namespace apollo
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#pragma once
#include <string>
#include "google/protobuf/message.h"
namespace apollo {
namespace common {
namespace util {
// Load YAML file to an equivalent json string.
std::string YamlToJson(const std::string& yaml_file);
// Load YAML file to an equivalent proto message.
// Return false if failed.
bool YamlToProto(const std::string& yaml_file,
google::protobuf::Message* proto);
} // namespace util
} // namespace common
} // namespace apollo
/******************************************************************************
* Copyright 2018 The Apollo Authors. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*****************************************************************************/
#include "modules/common/util/yaml_util.h"
#include "gtest/gtest.h"
#include "modules/common/util/file.h"
#include "modules/common/util/testdata/simple.pb.h"
#include "modules/common/util/util.h"
namespace apollo {
namespace common {
namespace util {
TEST(YamlUtilTest, YamlToProto) {
const std::string kInputYamlFile =
"/apollo/modules/common/util/testdata/simple_proto.yaml";
const std::string kExpectedProtoFile =
"/apollo/modules/common/util/testdata/simple_proto.pb.txt";
test::SimpleRepeatedMessage loaded_proto;
EXPECT_TRUE(YamlToProto(kInputYamlFile, &loaded_proto));
test::SimpleRepeatedMessage expected_proto;
ASSERT_TRUE(GetProtoFromASCIIFile(kExpectedProtoFile, &expected_proto));
EXPECT_TRUE(IsProtoEqual(expected_proto, loaded_proto));
}
} // namespace util
} // namespace common
} // namespace apollo
......@@ -66,7 +66,6 @@ cc_library(
"//modules/common/proto:drive_event_proto",
"//modules/common/util:map_util",
"//modules/common/util:message_util",
"//modules/common/util:yaml_util",
"//modules/data/util:info_collector",
"//modules/dreamview/backend/common:dreamview_gflags",
"//modules/dreamview/proto:hmi_config_proto",
......
......@@ -27,7 +27,6 @@
#include "modules/common/util/message_util.h"
#include "modules/common/util/string_tokenizer.h"
#include "modules/common/util/string_util.h"
#include "modules/common/util/yaml_util.h"
#include "modules/data/util/info_collector.h"
#include "modules/dreamview/backend/common/dreamview_gflags.h"
#include "modules/dreamview/backend/hmi/vehicle_manager.h"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册