• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
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 ReadLen();
40     bool ReadData(uint8_t buffer[], uint32_t bufferSize);
41 
42     bool ValidateHeader();
43 
44     TraceFileHeader GetHeader() const;
45 
46 private:
47     std::string path_ {};
48     std::ifstream stream_ {};
49     TraceFileHeader header_ {};
50     TraceFileHelper helper_ {};
51 
52     DISALLOW_COPY_AND_MOVE(TraceFileReader);
53 };
54 
55 using TraceFileReaderPtr = STD_PTR(shared, TraceFileReader);
56 
57 #endif // !TRACE_FILE_READER_H