Future proofed file read/write

This commit is contained in:
2022-09-09 23:28:25 +02:00
parent 699e2a4784
commit 2fc2170763
20 changed files with 690 additions and 607 deletions
+44
View File
@@ -0,0 +1,44 @@
#ifndef GERMANAIRLINESVA_FILE_RECORDING_H
#define GERMANAIRLINESVA_FILE_RECORDING_H
#include <cstdint>
#include <cstring>
#include <vector>
#include "recordingEntry.h"
namespace germanairlinesva
{
namespace file
{
namespace recording
{
/*
* Path Recording (6 + n * 24)
* HEADER | SEGMENTS
* Header (6)
* CHAR[5] | UINT8
* --------+--------
* VGAR | VERSION
* Path Segments (n)
* PATHSEGMENT[]
*/
class Recording
{
private:
std::uint64_t count = 0;
std::vector<std::uint8_t> file{'V', 'G', 'A', 'R', '\0', 1};
public:
void addSegment(const RecordingEntry &segment);
inline const std::uint8_t *getBinaryData() const { return file.data(); }
inline std::size_t getBinaryLength() const { return file.size(); }
};
} // namespace recording
} // namespace file
} // namespace germanairlinesva
#endif
+59
View File
@@ -0,0 +1,59 @@
#ifndef GERMANAIRLINESVA_FILE_RECORDINGENTRY_H
#define GERMANAIRLINESVA_FILE_RECORDINGENTRY_H
#include <cstdint>
#include <cstring>
#include <vector>
#include "geodata.h"
namespace germanairlinesva
{
namespace file
{
namespace recording
{
/*
* Path Segment (24)
* UINT32 | UINT16 | UINT16 | POINT
* -------+----------+-------------+------------
* TIME | ALTITUDE | GROUNDSPEED | COORDINATES
*/
class RecordingEntry
{
private:
std::uint32_t time = 0;
std::uint16_t altitude = 0;
std::uint16_t groundSpeed = 0;
struct germanairlinesva_geodata::point coordinates;
std::vector<std::uint8_t> file;
public:
RecordingEntry() = default;
RecordingEntry(std::uint32_t time,
std::uint16_t altitude,
std::uint16_t groundSpeed,
struct germanairlinesva_geodata::point coordinates);
inline const std::uint8_t *getBinaryData() const { return file.data(); }
inline std::size_t getBinaryLength() const { return file.size(); }
friend inline bool operator==(const RecordingEntry &lhs,
const RecordingEntry &rhs)
{
return lhs.altitude == rhs.altitude &&
lhs.groundSpeed == rhs.groundSpeed &&
lhs.coordinates.latitude == rhs.coordinates.latitude &&
lhs.coordinates.longitude == rhs.coordinates.longitude;
}
friend inline bool operator!=(const RecordingEntry &lhs,
const RecordingEntry &rhs)
{
return !(lhs == rhs);
}
};
} // namespace recording
} // namespace file
} // namespace germanairlinesva
#endif