VRS
A file format for sensor data.
Loading...
Searching...
No Matches
FileFormat.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 <vrs/Record.h>
20#include <vrs/VrsExport.h>
21
26
27namespace vrs {
28
57namespace FileFormat {
58#pragma pack(push, 1)
59
61struct VRS_API FileHeader {
62 uint32_t magicHeader1{};
63 uint32_t magicHeader2{};
64 uint64_t creationId{};
65 uint32_t fileHeaderSize{};
66 uint32_t recordHeaderSize{};
69 int64_t
72 uint64_t future2{};
73 uint64_t future3{};
74 uint64_t future4{};
75 uint32_t magicHeader3{};
76 uint32_t fileFormatVersion{};
77
79 void init();
81 void init(uint32_t magic1, uint32_t magic2, uint32_t magic3, uint32_t formatVersion);
85 static void setCreationIdOffset(uint64_t offset);
88 bool looksLikeAVRSFile() const;
91 bool looksLikeOurFiles(uint32_t magic1, uint32_t magic2, uint32_t magic3) const;
94 bool isFormatSupported() const;
101 void enableFrontIndexRecordSupport();
108 int64_t getEndOfUserRecordsOffset(int64_t fileSize) const;
109};
110
111// Re-interpret legacy recordable Type id
112VRS_API RecordableTypeId readRecordableTypeId(int32_t recordableTypeId);
113
116struct VRS_API RecordHeader {
117 RecordHeader();
118 RecordHeader(
120 StreamId streamId,
121 double timestamp,
122 uint32_t formatVersion,
124 uint32_t previousRecordSize,
125 uint32_t recordSize,
126 uint32_t uncompressedSize);
127 uint32_t recordSize{};
130 uint32_t formatVersion{};
131 double timestamp{};
133 uint8_t recordType{};
134 uint8_t compressionType{};
135 uint32_t uncompressedSize{};
136
139 inline void setRecordType(Record::Type type) {
140 recordType = static_cast<uint8_t>(type);
141 }
142
146 return static_cast<Record::Type>(recordType);
147 }
148
152 recordableTypeId = static_cast<int32_t>(typeId);
153 }
154
158 return readRecordableTypeId(recordableTypeId);
159 }
160
163 inline StreamId getStreamId() const {
164 return {getRecordableTypeId(), static_cast<uint16_t>(recordableInstanceId)};
165 }
166
170 return static_cast<CompressionType>(compressionType);
171 }
172
176 this->compressionType = static_cast<uint8_t>(type);
177 }
178
181 void initHeader(
182 Record::Type recordType,
183 StreamId streamId,
184 double timestamp,
185 uint32_t formatVersion,
186 CompressionType compressionType,
187 uint32_t previousRecordSize,
188 uint32_t recordSize,
189 uint32_t uncompressedSize);
190
196 void initIndexHeader(
197 uint32_t formatVersion,
198 uint32_t indexSize,
199 uint32_t previousRecordSize,
200 CompressionType compressionType);
201
206 void initDescriptionHeader(
207 uint32_t formatVersion,
208 uint32_t descriptionRecordSize,
209 uint32_t previousRecordSize);
210
213 bool isSanityCheckOk() const;
214};
215
216#pragma pack(pop)
217
220constexpr uint32_t fourCharCode(char a, char b, char c, char d) {
221 return static_cast<uint32_t>(a) | (static_cast<uint32_t>(b) << 8) |
222 (static_cast<uint32_t>(c) << 16) | (static_cast<uint32_t>(d) << 24);
223}
224
227VRS_API bool printVRSFileInternals(std::unique_ptr<FileHandler>& file);
228
229} // namespace FileFormat
230
231} // namespace vrs
Type
Definition Record.h:94
VRS stream identifier class.
Definition StreamId.h:251
Namespace for key datastructures of a VRS file.
Definition FileFormat.cpp:45
constexpr uint32_t fourCharCode(char a, char b, char c, char d)
Definition FileFormat.h:220
bool printVRSFileInternals(unique_ptr< FileHandler > &file)
Definition FileFormat.cpp:238
Definition Compressor.cpp:130
CompressionType
Type of compression. Used in VRS record headers, so never modify the values.
Definition Record.h:41
RecordableTypeId
VRS stream type or class identifier enum.
Definition StreamId.h:51
Every file starts with this header, which may grow but not shrink!
Definition FileFormat.h:61
int64_t firstUserRecordOffset
Definition FileFormat.h:70
uint32_t recordHeaderSize
Record headers' size, in bytes (same for all).
Definition FileFormat.h:66
uint32_t magicHeader2
magic value #2
Definition FileFormat.h:63
uint32_t fileFormatVersion
file format version.
Definition FileFormat.h:76
uint32_t magicHeader1
magic value #1
Definition FileFormat.h:62
uint64_t future3
For future use.
Definition FileFormat.h:73
int64_t descriptionRecordOffset
Description record offset in the whole file.
Definition FileFormat.h:68
uint64_t future4
For future use.
Definition FileFormat.h:74
uint64_t future2
For future use.
Definition FileFormat.h:72
int64_t indexRecordOffset
Index record offset in the whole file.
Definition FileFormat.h:67
uint32_t fileHeaderSize
This header size, in bytes.
Definition FileFormat.h:65
uint32_t magicHeader3
magic value #3
Definition FileFormat.h:75
uint64_t creationId
A timestamp, hopefully unique, to match files (future).
Definition FileFormat.h:64
uint8_t compressionType
compression used, or 0 for none
Definition FileFormat.h:134
void setRecordableTypeId(RecordableTypeId typeId)
Definition FileFormat.h:151
RecordableTypeId getRecordableTypeId() const
Definition FileFormat.h:157
void setCompressionType(CompressionType type)
Definition FileFormat.h:175
void setRecordType(Record::Type type)
Definition FileFormat.h:139
Record::Type getRecordType() const
Definition FileFormat.h:145
uint32_t previousRecordSize
byte count to the previous record, header + data
Definition FileFormat.h:128
double timestamp
record presentation time stamp
Definition FileFormat.h:131
uint8_t recordType
See Record::Type.
Definition FileFormat.h:133
uint32_t uncompressedSize
uncompressed payload size without header. 0 if not compressed.
Definition FileFormat.h:135
uint32_t formatVersion
data format version, as declared by the data producer
Definition FileFormat.h:130
StreamId getStreamId() const
Definition FileFormat.h:163
int32_t recordableTypeId
record handler type id
Definition FileFormat.h:129
uint16_t recordableInstanceId
record handle instance id
Definition FileFormat.h:132
uint32_t recordSize
byte count to the next record, header + data
Definition FileFormat.h:127
CompressionType getCompressionType() const
Definition FileFormat.h:169