chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:33:03 +08:00
commit 5b57521aa1
8226 changed files with 3425766 additions and 0 deletions
@@ -0,0 +1,45 @@
//
// CaffeUtils.cpp
// MNNConverter
//
// Created by MNN on 2019/01/31.
// Copyright © 2018, Alibaba Group Holding Limited
//
#include "CaffeUtils.hpp"
#include <fstream>
bool read_proto_from_text(const char* filepath, google::protobuf::Message* message) {
std::ifstream fs(filepath, std::ifstream::in);
if (!fs.is_open()) {
fprintf(stderr, "open failed %s\n", filepath);
return false;
}
google::protobuf::io::IstreamInputStream input(&fs);
bool success = google::protobuf::TextFormat::Parse(&input, message);
fs.close();
return success;
}
bool read_proto_from_binary(const char* filepath, google::protobuf::Message* message) {
std::ifstream fs(filepath, std::ifstream::in | std::ifstream::binary);
if (!fs.is_open()) {
printf("open failed %s\n", filepath);
return false;
}
google::protobuf::io::IstreamInputStream input(&fs);
google::protobuf::io::CodedInputStream codedstr(&input);
#if GOOGLE_PROTOBUF_VERSION >= 3011000
codedstr.SetTotalBytesLimit(INT_MAX);
#else
codedstr.SetTotalBytesLimit(INT_MAX, INT_MAX/2);
#endif
bool success = message->ParseFromCodedStream(&codedstr);
fs.close();
return success;
}