VRS
A file format for sensor data.
Loading...
Searching...
No Matches
Record.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 <memory>
20#include <vector>
21
22#include <vrs/ForwardDefinitions.h>
23#include <vrs/StreamId.h>
24#include <vrs/VrsExport.h>
25#include <vrs/helpers/EnumTemplates.hpp>
26#include <vrs/helpers/IOVector.h>
27
28namespace vrs {
29
30using std::unique_ptr;
31using std::vector;
32
33class DataSource;
34class DirectWriteRecordData;
35class Compressor;
36class RecordManager;
37
39enum class CompressionType : uint8_t {
40 None = 0,
41 Lz4,
42 Zstd,
43
44 COUNT
45};
46
83class VRS_API Record final {
84 public:
86 static const double kMaxTimestamp;
87
92 enum class Type : uint8_t {
93 UNDEFINED = 0,
94 STATE = 1,
95 CONFIGURATION = 2,
96 DATA = 3,
97 TAGS = 4,
98 COUNT
99 };
100
103 void recycle();
104
107 void set(
108 double timestamp,
109 Type type,
110 uint32_t formatVersion,
111 const DataSource& data,
112 uint64_t creationOrder);
113
115 void addDirectWriteRecordData(unique_ptr<DirectWriteRecordData>&& directWriteRecordData);
116
120 bool shouldTryToCompress() const;
121
125 uint32_t compressRecord(Compressor& compressor);
126
129 int writeRecord(
130 WriteFileHandler& file,
131 StreamId streamId,
132 uint32_t& inOutRecordSize,
133 Compressor& compressor,
134 uint32_t compressedSize);
135
137 double getTimestamp() const {
138 return timestamp_;
139 }
140
141 uint64_t getCreationOrder() const {
142 return creationOrder_;
143 }
144
146 size_t getSize() const {
147 return usedBufferSize_;
148 }
149
152 return recordType_;
153 }
154
156 static const char* typeName(Type type);
157
158 private:
159 friend class RecordManager;
160
162 explicit Record(RecordManager& recordManager);
163 ~Record();
164
165 double timestamp_{};
166 Type recordType_{};
167 uint32_t formatVersion_{};
168 helpers::IOVector<uint8_t> buffer_;
169 size_t usedBufferSize_{};
170 uint64_t creationOrder_{};
171 unique_ptr<DirectWriteRecordData> directWriteRecordData_;
172
173 RecordManager& recordManager_;
174};
175
177VRS_API string toString(Record::Type recordType);
178
180template <>
181VRS_API Record::Type toEnum(const string& name);
182
183} // namespace vrs
Helper class to compress data using lz4 or zstd presets.
Definition Compressor.h:83
A class referencing data to be captured in a record at creation.
Definition DataSource.h:153
Essential VRS class holding a record's details and payload in memory during creation.
Definition Record.h:83
Type getRecordType() const
Get the record's record type.
Definition Record.h:151
Type
Definition Record.h:92
double getTimestamp() const
Get the record's timestamp.
Definition Record.h:137
static const double kMaxTimestamp
Maximum timestamp for a record.
Definition Record.h:86
size_t getSize() const
Get the record's payload size, uncompressed.
Definition Record.h:146
VRS internal class to manage the records of a specific Recordable after their creation.
Definition RecordManager.h:39
VRS stream identifier class.
Definition StreamId.h:251
The WriteFileHandler interface adds write operations to the FileHandler interface.
Definition WriteFileHandler.h:43
Definition Compressor.cpp:113
@ None
No compression.
@ UNDEFINED
Unknown/unspecified.
CompressionType
Type of compression. Used in VRS record headers, so never modify the values.
Definition Record.h:39
@ Zstd
zstd compression.
@ Lz4
lz4 compression.