forked from alibaba/MNN
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaffeUtils.cpp
More file actions
41 lines (33 loc) · 1.1 KB
/
Copy pathCaffeUtils.cpp
File metadata and controls
41 lines (33 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//
// 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);
// codedstr.SetTotalBytesLimit(INT_MAX / 2);
bool success = message->ParseFromCodedStream(&codedstr);
fs.close();
return success;
}