VRS
A file format for sensor data.
Loading...
Searching...
No Matches
RecordReaders.h
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
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#pragma once
18
19#include "DataReference.h"
20#include "Decompressor.h"
21#include "ErrorCode.h"
22
23namespace vrs {
24
25class FileHandler;
26
30 public:
31 virtual ~RecordReader();
32
38 RecordReader* init(FileHandler& file, uint32_t diskSize, uint32_t expandedSize);
39
44 virtual int read(DataReference& destination, uint32_t& outReadSize) = 0;
45
49 template <typename T, std::enable_if_t<std::is_trivially_copyable<T>::value, int> = 0>
50 int read(std::vector<T>& buffer) {
51 DataReference bufferDataReference(buffer);
52 uint32_t readSize = 0;
53 int res = read(bufferDataReference, readSize);
54 buffer.resize(readSize / sizeof(T));
55 return res;
56 }
57
63 int read(void* destination, size_t size) {
64 DataReference bufferDataReference(destination, static_cast<uint32_t>(size));
65 uint32_t readSize = 0;
66 const int res = read(bufferDataReference, readSize);
67 if (res != 0) {
68 return res;
69 }
70 return readSize == size ? 0 : READ_ERROR;
71 }
72
74 virtual void finish() {}
75
78 uint32_t getUnreadDiskBytes() const {
79 return remainingDiskBytes_;
80 }
81
84 uint32_t getUnreadBytes() const {
85 return remainingUncompressedSize_;
86 }
87
88 int64_t getFileOffset() const;
89
92 [[nodiscard]] virtual CompressionType getCompressionType() const = 0;
93
94 // for warning/error throttling only
95 const void* getRef() const {
96 return file_;
97 }
98
99 protected:
100 FileHandler* file_;
101 uint32_t remainingDiskBytes_;
102 uint32_t remainingUncompressedSize_;
103};
104
108 public:
109 int read(DataReference& destination, uint32_t& outReadSize) override;
110 CompressionType getCompressionType() const override;
111};
112
116 public:
117 void initCompressionType(CompressionType compressionType);
118 int read(DataReference& destination, uint32_t& outReadSize) override;
119 void finish() override;
120 CompressionType getCompressionType() const override;
121
122 private:
123 int read(void* dest, uint32_t destSize, uint32_t overallSize, uint32_t& outReadSize);
124
125 Decompressor decompressor_;
126};
127
128} // namespace vrs
RecordReader specialized to read compressed records. For VRS internal usage only.
Definition RecordReaders.h:115
void finish() override
Discard any unread data.
Definition RecordReaders.cpp:143
int read(DataReference &destination, uint32_t &outReadSize) override
Definition RecordReaders.cpp:78
CompressionType getCompressionType() const override
Definition RecordReaders.cpp:148
Container of data pointers, to tell where to write data when reading a record.
Definition DataReference.h:59
Decompressor helper class, to decompresses data at a target location.
Definition Decompressor.h:34
Class to abstract VRS file system operations, to enable support for alternate storage methods,...
Definition FileHandler.h:71
Abstract VRS internal helper class to read & (if necessary) uncompress records.
Definition RecordReaders.h:29
uint32_t getUnreadDiskBytes() const
Definition RecordReaders.h:78
RecordReader * init(FileHandler &file, uint32_t diskSize, uint32_t expandedSize)
Definition RecordReaders.cpp:43
int read(void *destination, size_t size)
Definition RecordReaders.h:63
virtual void finish()
Discard any unread data.
Definition RecordReaders.h:74
uint32_t getUnreadBytes() const
Definition RecordReaders.h:84
int read(std::vector< T > &buffer)
Definition RecordReaders.h:50
virtual CompressionType getCompressionType() const =0
virtual int read(DataReference &destination, uint32_t &outReadSize)=0
RecordReader specialized to read uncompressed records. For VRS internal usage only.
Definition RecordReaders.h:107
CompressionType getCompressionType() const override
Definition RecordReaders.cpp:70
int read(DataReference &destination, uint32_t &outReadSize) override
Definition RecordReaders.cpp:54
Definition AsyncDiskFileChunk.hpp:49
CompressionType
Type of compression. Used in VRS record headers, so never modify the values.
Definition Record.h:35