1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef TRACE_FILE_READER_H 16 #define TRACE_FILE_READER_H 17 18 #include "logging.h" 19 #include "nocopyable.h" 20 #include "trace_file_helper.h" 21 22 #include <cstdint> 23 #include <fstream> 24 #include <google/protobuf/message_lite.h> 25 #include <string> 26 27 using google::protobuf::MessageLite; 28 29 class TraceFileReader { 30 public: 31 TraceFileReader() = default; 32 33 ~TraceFileReader(); 34 35 bool Open(const std::string& path); 36 37 long Read(MessageLite& message); 38 39 long Read(uint8_t buffer[], uint32_t bufferSize); 40 41 bool ValidateHeader(); 42 43 TraceFileHeader GetHeader() const; 44 45 private: 46 std::string path_ {}; 47 std::ifstream stream_ {}; 48 TraceFileHeader header_ {}; 49 TraceFileHelper helper_ {}; 50 51 DISALLOW_COPY_AND_MOVE(TraceFileReader); 52 }; 53 54 using TraceFileReaderPtr = STD_PTR(shared, TraceFileReader); 55 56 #endif // !TRACE_FILE_READER_H