Project import generated by Copybara.
GitOrigin-RevId: afeb9cf5a8c069c0a566d16e1622bbb086170e4d
This commit is contained in:
@@ -94,5 +94,30 @@ std::string CanonicalNodeName(const CalculatorGraphConfig& graph_config,
|
||||
return absl::StrCat(node_name, "_", sequence + 1);
|
||||
}
|
||||
|
||||
std::string ParseNameFromStream(const std::string& stream) {
|
||||
std::string tag, name;
|
||||
int index;
|
||||
MEDIAPIPE_CHECK_OK(tool::ParseTagIndexName(stream, &tag, &index, &name));
|
||||
return name;
|
||||
}
|
||||
|
||||
std::pair<std::string, int> ParseTagIndexFromStream(const std::string& stream) {
|
||||
std::string tag, name;
|
||||
int index;
|
||||
MEDIAPIPE_CHECK_OK(tool::ParseTagIndexName(stream, &tag, &index, &name));
|
||||
return {tag, index};
|
||||
}
|
||||
|
||||
std::string CatTag(const std::string& tag, int index) {
|
||||
return absl::StrCat(tag, index <= 0 ? "" : absl::StrCat(":", index));
|
||||
}
|
||||
|
||||
std::string CatStream(const std::pair<std::string, int>& tag_index,
|
||||
const std::string& name) {
|
||||
std::string tag = CatTag(tag_index.first, tag_index.second);
|
||||
tag = tag.empty() ? tag : absl::StrCat(tag, ":");
|
||||
return absl::StrCat(tag, name);
|
||||
}
|
||||
|
||||
} // namespace tool
|
||||
} // namespace mediapipe
|
||||
|
||||
@@ -73,6 +73,19 @@ std::string GetUnusedNodeName(const CalculatorGraphConfig& config,
|
||||
std::string CanonicalNodeName(const CalculatorGraphConfig& graph_config,
|
||||
int node_id);
|
||||
|
||||
// Parses the name from a "tag:index:name".
|
||||
std::string ParseNameFromStream(const std::string& stream);
|
||||
|
||||
// Parses the TagIndex from a "tag:index:name".
|
||||
std::pair<std::string, int> ParseTagIndexFromStream(const std::string& stream);
|
||||
|
||||
// Formats to "tag:index".
|
||||
std::string CatTag(const std::string& tag, int index);
|
||||
|
||||
// Concatenates "tag:index:name" into a single std::string.
|
||||
std::string CatStream(const std::pair<std::string, int>& tag_index,
|
||||
const std::string& name);
|
||||
|
||||
} // namespace tool
|
||||
} // namespace mediapipe
|
||||
|
||||
|
||||
@@ -40,13 +40,13 @@ template <typename T>
|
||||
struct IsExtension {
|
||||
private:
|
||||
template <typename U>
|
||||
static decltype(U::ext, std::true_type()) test(int);
|
||||
static char test(decltype(&U::ext));
|
||||
|
||||
template <typename>
|
||||
static std::false_type test(...);
|
||||
static int test(...);
|
||||
|
||||
public:
|
||||
static constexpr bool value = decltype(test<T>(0))();
|
||||
static constexpr bool value = (sizeof(test<T>(0)) == sizeof(char));
|
||||
};
|
||||
|
||||
// A map from object type to object.
|
||||
|
||||
@@ -79,7 +79,11 @@ mediapipe::Status ReadFile(const std::string& proto_source, bool read_text,
|
||||
// Write a proto to a text or a binary file.
|
||||
mediapipe::Status WriteFile(const std::string& proto_output, bool write_text,
|
||||
const proto_ns::Message& message) {
|
||||
std::ofstream ofs(proto_output, std::ofstream::out | std::ofstream::trunc);
|
||||
std::ios_base::openmode mode = std::ios_base::out | std::ios_base::trunc;
|
||||
if (!write_text) {
|
||||
mode |= std::ios_base::binary;
|
||||
}
|
||||
std::ofstream ofs(proto_output, mode);
|
||||
proto_ns::io::OstreamOutputStream out(&ofs);
|
||||
MP_RETURN_IF_ERROR(WriteProto(message, write_text, proto_output, &out));
|
||||
return mediapipe::OkStatus();
|
||||
|
||||
Reference in New Issue
Block a user