| @@ -18,6 +18,7 @@ | |||||
| // Description: This imply file for protobuf message and json interconversion | // Description: This imply file for protobuf message and json interconversion | ||||
| #include "common/convert/pb2json.h" | #include "common/convert/pb2json.h" | ||||
| #include <google/protobuf/text_format.h> | |||||
| #include <set> | #include <set> | ||||
| #include <string> | #include <string> | ||||
| #include "securec.h" | #include "securec.h" | ||||
| @@ -129,8 +130,11 @@ void Pb2Json::OneField2Json(const ProtobufMsg &message, const ProtobufFieldDescr | |||||
| case ProtobufFieldDescriptor::TYPE_BYTES: { | case ProtobufFieldDescriptor::TYPE_BYTES: { | ||||
| string field_name = field->name(); | string field_name = field->name(); | ||||
| string type_bytes = reflection->GetString(message, field); | |||||
| json[field_name] = TypeBytes2String(field_name, type_bytes); | |||||
| std::string scratch; | |||||
| std::string value = reflection->GetStringReference(message, field, &scratch); | |||||
| std::string cescape_value = google::protobuf::CEscape(value); | |||||
| GELOGD("After cescape data:%s", cescape_value.c_str()); | |||||
| json[field_name] = cescape_value; | |||||
| break; | break; | ||||
| } | } | ||||
| @@ -356,5 +356,5 @@ target_link_libraries(ut_parser | |||||
| ut_parser_proto | ut_parser_proto | ||||
| -Wl,--whole-archive ut_parser_common -Wl,--no-whole-archive | -Wl,--whole-archive ut_parser_common -Wl,--no-whole-archive | ||||
| ut_parser_graph ut_parser_register error_manager_stub mmpa_stub attr_util_stub | ut_parser_graph ut_parser_register error_manager_stub mmpa_stub attr_util_stub | ||||
| gtest gtest_main slog_stub ascend_protobuf c_sec -lrt -ldl -lgcov | |||||
| gtest gtest_main slog_stub ascend_protobuf c_sec json -lrt -ldl -lgcov | |||||
| ) | ) | ||||
| @@ -19,6 +19,7 @@ | |||||
| #include <gtest/gtest.h> | #include <gtest/gtest.h> | ||||
| #include "proto/onnx/ge_onnx.pb.h" | #include "proto/onnx/ge_onnx.pb.h" | ||||
| #include "parser/common/convert/pb2json.h" | |||||
| namespace ge { | namespace ge { | ||||
| class UtestMessage2Operator : public testing::Test { | class UtestMessage2Operator : public testing::Test { | ||||
| @@ -55,4 +56,17 @@ TEST_F(UtestMessage2Operator, message_to_operator_fail) { | |||||
| ret = Message2Operator::ParseOperatorAttrs(attribute, 1, op_src); | ret = Message2Operator::ParseOperatorAttrs(attribute, 1, op_src); | ||||
| EXPECT_EQ(ret, FAILED); | EXPECT_EQ(ret, FAILED); | ||||
| } | } | ||||
| TEST_F(UtestMessage2Operator, pb2json_one_field_json) { | |||||
| ge::onnx::NodeProto input_node; | |||||
| ge::onnx::AttributeProto *attribute = input_node.add_attribute(); | |||||
| attribute->set_name("attribute"); | |||||
| attribute->set_type(onnx::AttributeProto::AttributeType(1)); | |||||
| ge::onnx::TensorProto *attribute_tensor = attribute->mutable_t(); | |||||
| attribute_tensor->set_data_type(1); | |||||
| attribute_tensor->add_dims(4); | |||||
| attribute_tensor->set_raw_data("\007"); | |||||
| Json json; | |||||
| ge::Pb2Json::Message2Json(input_node, std::set<std::string>{}, json, true); | |||||
| } | |||||
| } // namespace ge | } // namespace ge | ||||