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 "Record.h"
20
25
26namespace vrs {
27
56namespace FileFormat {
57#pragma pack(push, 1)
58
62template <class T>
63class LittleEndian final {
64 public:
66 LittleEndian() = default;
67
69 explicit LittleEndian(T value) {
70 set(value);
71 }
72
75 T get() const {
76 return value_;
77 }
80 void set(T value) {
81 value_ = value;
82 }
83
84 private:
85 T value_{};
86};
87
134
135// Re-interpret legacy recordable Type id
136RecordableTypeId readRecordableTypeId(const FileFormat::LittleEndian<int32_t>& recordableTypeId);
137
141 RecordHeader();
144 StreamId streamId,
145 double timestamp,
146 uint32_t formatVersion,
148 uint32_t previousRecordSize,
149 uint32_t recordSize,
150 uint32_t uncompressedSize);
161
165 recordType.set(static_cast<uint8_t>(type));
166 }
167
171 return static_cast<Record::Type>(recordType.get());
172 }
173
177 recordableTypeId.set(static_cast<int32_t>(typeId));
178 }
179
183 return readRecordableTypeId(recordableTypeId);
184 }
185
191
195 return static_cast<CompressionType>(compressionType.get());
196 }
197
201 this->compressionType.set(static_cast<uint8_t>(type));
202 }
203
206 void initHeader(
208 StreamId streamId,
209 double timestamp,
210 uint32_t formatVersion,
212 uint32_t previousRecordSize,
213 uint32_t recordSize,
214 uint32_t uncompressedSize);
215
221 void initIndexHeader(
222 uint32_t formatVersion,
223 uint32_t indexSize,
224 uint32_t previousRecordSize,
226
232 uint32_t formatVersion,
233 uint32_t descriptionRecordSize,
234 uint32_t previousRecordSize);
235
238 bool isSanityCheckOk() const;
239};
240
241#pragma pack(pop)
242
245constexpr uint32_t fourCharCode(char a, char b, char c, char d) {
246 return static_cast<uint32_t>(a) | (static_cast<uint32_t>(b) << 8) |
247 (static_cast<uint32_t>(c) << 16) | (static_cast<uint32_t>(d) << 24);
248}
249
252bool printVRSFileInternals(std::unique_ptr<FileHandler>& file);
253
254} // namespace FileFormat
255
256} // namespace vrs
Placeholder layer for endianness support, if we ever need it.
Definition FileFormat.h:63
void set(T value)
Definition FileFormat.h:80
LittleEndian()=default
Default constructor, using T's default initializer.
LittleEndian(T value)
Constructor with an init value.
Definition FileFormat.h:69
T get() const
Definition FileFormat.h:75
Type
Definition Record.h:88
VRS stream identifier class.
Definition StreamId.h:242
constexpr uint32_t fourCharCode(char a, char b, char c, char d)
Definition FileFormat.h:245
Definition AsyncDiskFileChunk.hpp:49
CompressionType
Type of compression. Used in VRS record headers, so never modify the values.
Definition Record.h:35
RecordableTypeId
VRS stream type or class identifier enum.
Definition StreamId.h:49
Every file starts with this header, which may grow but not shrink!
Definition FileFormat.h:89
bool looksLikeAVRSFile() const
Definition FileFormat.cpp:82
LittleEndian< uint32_t > magicHeader2
magic value #2
Definition FileFormat.h:91
void enableFrontIndexRecordSupport()
Definition FileFormat.cpp:108
LittleEndian< uint32_t > magicHeader3
magic value #3
Definition FileFormat.h:103
LittleEndian< uint64_t > future2
For future use.
Definition FileFormat.h:100
LittleEndian< uint32_t > magicHeader1
magic value #1
Definition FileFormat.h:90
LittleEndian< uint64_t > creationId
A timestamp, hopefully unique, to match files (future).
Definition FileFormat.h:92
LittleEndian< uint32_t > fileFormatVersion
file format version.
Definition FileFormat.h:104
LittleEndian< uint32_t > fileHeaderSize
This header size, in bytes.
Definition FileFormat.h:93
int64_t getEndOfUserRecordsOffset(int64_t fileSize) const
Definition FileFormat.cpp:112
LittleEndian< uint64_t > future4
For future use.
Definition FileFormat.h:102
LittleEndian< int64_t > descriptionRecordOffset
Description record offset in the whole file.
Definition FileFormat.h:96
LittleEndian< uint64_t > future3
For future use.
Definition FileFormat.h:101
LittleEndian< uint32_t > recordHeaderSize
Record headers' size, in bytes (same for all).
Definition FileFormat.h:94
LittleEndian< int64_t > indexRecordOffset
Index record offset in the whole file.
Definition FileFormat.h:95
bool looksLikeOurFiles(uint32_t magic1, uint32_t magic2, uint32_t magic3) const
Definition FileFormat.cpp:86
bool isFormatSupported() const
Definition FileFormat.cpp:102
LittleEndian< int64_t > firstUserRecordOffset
Definition FileFormat.h:98
void init()
Initialize the structure's fixed values with default values for a regular VRS file.
Definition FileFormat.cpp:54
Every record starts with this header, and is followed by a raw data blob, which semantic is private t...
Definition FileFormat.h:140
LittleEndian< uint32_t > previousRecordSize
byte count to the previous record, header + data
Definition FileFormat.h:152
void setRecordableTypeId(RecordableTypeId typeId)
Definition FileFormat.h:176
LittleEndian< double > timestamp
record presentation time stamp
Definition FileFormat.h:155
RecordableTypeId getRecordableTypeId() const
Definition FileFormat.h:182
void setCompressionType(CompressionType type)
Definition FileFormat.h:200
LittleEndian< uint8_t > recordType
See Record::Type.
Definition FileFormat.h:157
void setRecordType(Record::Type type)
Definition FileFormat.h:164
void initHeader(Record::Type recordType, StreamId streamId, double timestamp, uint32_t formatVersion, CompressionType compressionType, uint32_t previousRecordSize, uint32_t recordSize, uint32_t uncompressedSize)
Definition FileFormat.cpp:144
Record::Type getRecordType() const
Definition FileFormat.h:170
LittleEndian< uint8_t > compressionType
compression used, or 0 for none
Definition FileFormat.h:158
void initDescriptionHeader(uint32_t formatVersion, uint32_t descriptionRecordSize, uint32_t previousRecordSize)
Definition FileFormat.cpp:178
LittleEndian< uint32_t > uncompressedSize
uncompressed payload size without header. 0 if not compressed.
Definition FileFormat.h:160
LittleEndian< uint16_t > recordableInstanceId
record handle instance id
Definition FileFormat.h:156
bool isSanityCheckOk() const
Definition FileFormat.cpp:190
StreamId getStreamId() const
Definition FileFormat.h:188
LittleEndian< uint32_t > formatVersion
data format version, as declared by the data producer
Definition FileFormat.h:154
LittleEndian< uint32_t > recordSize
byte count to the next record, header + data
Definition FileFormat.h:151
void initIndexHeader(uint32_t formatVersion, uint32_t indexSize, uint32_t previousRecordSize, CompressionType compressionType)
Definition FileFormat.cpp:164
LittleEndian< int32_t > recordableTypeId
record handler type id
Definition FileFormat.h:153
CompressionType getCompressionType() const
Definition FileFormat.h:194