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);
84 bool looksLikeAVRSFile() const;
87 bool looksLikeOurFiles(uint32_t magic1, uint32_t magic2, uint32_t magic3) const;
90 bool isFormatSupported() const;
97 void enableFrontIndexRecordSupport();
104 int64_t getEndOfUserRecordsOffset(int64_t fileSize) const;
105};
106
107// Re-interpret legacy recordable Type id
108VRS_API RecordableTypeId readRecordableTypeId(int32_t recordableTypeId);
109
112struct VRS_API RecordHeader {
113 RecordHeader();
115 Record::Type recordType,
116 StreamId streamId,
117 double timestamp,
118 uint32_t formatVersion,
119 CompressionType compressionType,
120 uint32_t previousRecordSize,
121 uint32_t recordSize,
122 uint32_t uncompressedSize);
123 uint32_t recordSize{};
124 uint32_t previousRecordSize{};
125 int32_t recordableTypeId{};
126 uint32_t formatVersion{};
127 double timestamp{};
128 uint16_t recordableInstanceId{};
129 uint8_t recordType{};
130 uint8_t compressionType{};
131 uint32_t uncompressedSize{};
132
135 inline void setRecordType(Record::Type type) {
136 recordType = static_cast<uint8_t>(type);
137 }
138
142 return static_cast<Record::Type>(recordType);
143 }
144
148 recordableTypeId = static_cast<int32_t>(typeId);
149 }
150
154 return readRecordableTypeId(recordableTypeId);
155 }
156
159 inline StreamId getStreamId() const {
160 return {getRecordableTypeId(), static_cast<uint16_t>(recordableInstanceId)};
161 }
162
166 return static_cast<CompressionType>(compressionType);
167 }
168
172 this->compressionType = static_cast<uint8_t>(type);
173 }
174
177 void initHeader(
178 Record::Type recordType,
179 StreamId streamId,
180 double timestamp,
181 uint32_t formatVersion,
182 CompressionType compressionType,
183 uint32_t previousRecordSize,
184 uint32_t recordSize,
185 uint32_t uncompressedSize);
186
192 void initIndexHeader(
193 uint32_t formatVersion,
194 uint32_t indexSize,
195 uint32_t previousRecordSize,
196 CompressionType compressionType);
197
202 void initDescriptionHeader(
203 uint32_t formatVersion,
204 uint32_t descriptionRecordSize,
205 uint32_t previousRecordSize);
206
209 bool isSanityCheckOk() const;
210};
211
212#pragma pack(pop)
213
216constexpr uint32_t fourCharCode(char a, char b, char c, char d) {
217 return static_cast<uint32_t>(a) | (static_cast<uint32_t>(b) << 8) |
218 (static_cast<uint32_t>(c) << 16) | (static_cast<uint32_t>(d) << 24);
219}
220
223VRS_API bool printVRSFileInternals(std::unique_ptr<FileHandler>& file);
224
225} // namespace FileFormat
226
227} // namespace vrs
Type
Definition Record.h:91
VRS stream identifier class.
Definition StreamId.h:251
constexpr uint32_t fourCharCode(char a, char b, char c, char d)
Definition FileFormat.h:216
Definition Compressor.cpp:113
CompressionType
Type of compression. Used in VRS record headers, so never modify the values.
Definition Record.h:38
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:112
void setRecordableTypeId(RecordableTypeId typeId)
Definition FileFormat.h:147
RecordableTypeId getRecordableTypeId() const
Definition FileFormat.h:153
void setCompressionType(CompressionType type)
Definition FileFormat.h:171
void setRecordType(Record::Type type)
Definition FileFormat.h:135
Record::Type getRecordType() const
Definition FileFormat.h:141
StreamId getStreamId() const
Definition FileFormat.h:159
CompressionType getCompressionType() const
Definition FileFormat.h:165