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{};
67 int64_t indexRecordOffset{};
68 int64_t descriptionRecordOffset{};
69 int64_t
70 firstUserRecordOffset{};
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();
119 Record::Type recordType,
120 StreamId streamId,
121 double timestamp,
122 uint32_t formatVersion,
123 CompressionType compressionType,
124 uint32_t previousRecordSize,
125 uint32_t recordSize,
126 uint32_t uncompressedSize);
127 uint32_t recordSize{};
128 uint32_t previousRecordSize{};
129 int32_t recordableTypeId{};
130 uint32_t formatVersion{};
131 double timestamp{};
132 uint16_t recordableInstanceId{};
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
constexpr uint32_t fourCharCode(char a, char b, char c, char d)
Definition FileFormat.h:220
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
Every record starts with this header, and is followed by a raw data blob, which semantic is private t...
Definition FileFormat.h:116
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
StreamId getStreamId() const
Definition FileFormat.h:163
CompressionType getCompressionType() const
Definition FileFormat.h:169