Updated parse_proto_utils

This commit is contained in:
Prianka Liz Kariat 2023-05-24 19:26:01 +05:30
parent b74280e629
commit 2842e21665
2 changed files with 7 additions and 10 deletions

View File

@ -17,7 +17,6 @@ limitations under the License.
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include "google/protobuf/io/zero_copy_stream_impl.h"
namespace mediapipe::tasks::ios::test::vision::utils { namespace mediapipe::tasks::ios::test::vision::utils {
@ -26,18 +25,16 @@ namespace {
} }
absl::Status get_proto_from_pbtxt(const std::string file_path, google::protobuf::Message& proto) { absl::Status get_proto_from_pbtxt(const std::string file_path, google::protobuf::Message& proto) {
std::ifstream fin(file_path);
if(!fin.is_open()) return absl::InvalidArgumentError( std::ifstream file_input_stream(file_path);
if(!file_input_stream.is_open()) return absl::InvalidArgumentError(
"Cannot read input file."); "Cannot read input file.");
std::stringstream strings_stream ; std::stringstream strings_stream ;
strings_stream << file_input_stream.rdbuf();
strings_stream << fin.rdbuf();
return TextFormat::ParseFromString(strings_stream.str(), &proto) ? absl::OkStatus() : absl::InvalidArgumentError( return TextFormat::ParseFromString(strings_stream.str(), &proto) ? absl::OkStatus() : absl::InvalidArgumentError(
"Cannot read a valid proto from the input file."); "Cannot read a valid proto from the input file.");
} }
} // namespace mediapipe::tasks::text::utils } // namespace mediapipe::tasks::ios::test::vision::utils

View File

@ -23,6 +23,6 @@ limitations under the License.
namespace mediapipe::tasks::ios::test::vision::utils { namespace mediapipe::tasks::ios::test::vision::utils {
absl::Status get_proto_from_pbtxt(const std::string file_path, google::protobuf::Message& proto); absl::Status get_proto_from_pbtxt(const std::string file_path, google::protobuf::Message& proto);
} // namespace mediapipe::tasks::ios::test::utils } // namespace mediapipe::tasks::ios::test::vision::utils
#endif // MEDIAPIPE_TASKS_IOS_TEST_VISION_UTILS_H_ #endif // MEDIAPIPE_TASKS_IOS_TEST_VISION_UTILS_H_