blob: dc72420fcba03cac26440a0cdb8569dddeb573fa [file] [log] [blame]
Keun Soo Yim08400372016-03-03 13:28:51 -08001/*
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 <iostream>
22
23#include <google/protobuf/message.h>
24#include <google/protobuf/text_format.h>
25
26#include "test/vts/sysfuzzer/common/proto/InterfaceSpecificationMessage.pb.h"
27
28using namespace std;
29
30namespace android {
31namespace vts {
32
33
34bool InterfaceSpecificationParser::parse(
35 const char* file_path, InterfaceSpecificationMessage* is_message) {
36 cout << __FUNCTION__ << " " << file_path << endl;
37
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();
46const 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 "
50 << file_path << "." << endl;
51 cerr << data << endl;
52 return false;
53 }
54
55 return true;
56}
57
58} // namespace vts
59} // namespace android