Merge pull request #4465 from priankakariatyml:ios-landmark-test-cpp-utils

PiperOrigin-RevId: 535441782
This commit is contained in:
Copybara-Service 2023-05-25 17:26:30 -07:00
commit f4337356fe
3 changed files with 83 additions and 0 deletions

View File

@ -9,3 +9,13 @@ objc_library(
module_name = "MPPImageTestUtils", module_name = "MPPImageTestUtils",
deps = ["//mediapipe/tasks/ios/vision/core:MPPImage"], deps = ["//mediapipe/tasks/ios/vision/core:MPPImage"],
) )
cc_library(
name = "parse_proto_utils",
srcs = ["sources/parse_proto_utils.cc"],
hdrs = ["sources/parse_proto_utils.h"],
deps = [
"@com_google_absl//absl/status",
"@com_google_protobuf//:protobuf",
],
)

View File

@ -0,0 +1,44 @@
/* Copyright 2023 The MediaPipe Authors.
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 <fstream>
#include <sstream>
#include "absl/status/status.h"
#include "google/protobuf/text_format.h"
namespace mediapipe::tasks::ios::test::vision::utils {
namespace {
using ::google::protobuf::Message;
using ::google::protobuf::TextFormat;
} // anonymous namespace
::absl::Status get_proto_from_pbtxt(const std::string file_path,
Message& proto) {
std::ifstream file_input_stream(file_path);
if (!file_input_stream.is_open())
return absl::InvalidArgumentError("Cannot read input file.");
std::stringstream strings_stream;
strings_stream << file_input_stream.rdbuf();
return TextFormat::ParseFromString(strings_stream.str(), &proto)
? ::absl::OkStatus()
: ::absl::InvalidArgumentError(
"Cannot read a valid proto from the input file.");
}
} // namespace mediapipe::tasks::ios::test::vision::utils

View File

@ -0,0 +1,29 @@
/* Copyright 2023 The MediaPipe Authors.
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.
==============================================================================*/
#ifndef MEDIAPIPE_TASKS_IOS_TEST_VISION_UTILS_H_
#define MEDIAPIPE_TASKS_IOS_TEST_VISION_UTILS_H_
#include <string>
#include "absl/status/status.h"
#include "google/protobuf/message.h"
namespace mediapipe::tasks::ios::test::vision::utils {
absl::Status get_proto_from_pbtxt(std::string file_path,
::google::protobuf::Message& proto);
} // namespace mediapipe::tasks::ios::test::vision::utils
#endif // MEDIAPIPE_TASKS_IOS_TEST_VISION_UTILS_H_