1 /* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "specification_parser/InterfaceSpecificationParser.h" 18 19 #include <stdio.h> 20 21 #include <fstream> 22 #include <iostream> 23 #include <sstream> 24 #include <string> 25 26 #include <google/protobuf/message.h> 27 #include <google/protobuf/text_format.h> 28 29 #include "test/vts/proto/ComponentSpecificationMessage.pb.h" 30 31 using namespace std; 32 33 namespace android { 34 namespace vts { 35 36 bool InterfaceSpecificationParser::parse( 37 const char* file_path, ComponentSpecificationMessage* is_message) { 38 ifstream in_file(file_path); 39 stringstream str_stream; 40 if (!in_file.is_open()) { 41 cerr << "Unable to open file. " << file_path << endl; 42 return false; 43 } 44 str_stream << in_file.rdbuf(); 45 in_file.close(); 46 const string data = str_stream.str(); 47 48 if (!google::protobuf::TextFormat::MergeFromString(data, is_message)) { 49 cerr << __FUNCTION__ << ": Can't parse a given proto file " << file_path 50 << "." << endl; 51 cerr << data << endl; 52 return false; 53 } 54 return true; 55 } 56 57 } // namespace vts 58 } // namespace android 59