11#include <initializer_list>
126 void AddSchema(std::string_view name, std::string_view type,
127 std::span<const uint8_t> schema, int64_t timestamp = 0);
144 void AddSchema(std::string_view name, std::string_view type,
145 std::string_view schema, int64_t timestamp = 0) {
148 std::span<const uint8_t>{
149 reinterpret_cast<const uint8_t*
>(schema.data()), schema.size()},
161 template <ProtobufSerializable T>
163 if (timestamp == 0) {
167 [
this](
auto typeString) {
return HasSchema(typeString); },
168 [
this, timestamp](
auto typeString,
auto schema) {
169 AddSchema(typeString,
"proto:FileDescriptorProto", schema, timestamp);
181 template <
typename T,
typename... I>
184 if (timestamp == 0) {
188 [
this, timestamp](
auto typeString,
auto schema) {
189 this->
AddSchema(typeString,
"structschema", schema, timestamp);
208 int Start(std::string_view name, std::string_view type,
209 std::string_view metadata = {}, int64_t timestamp = 0);
217 void Finish(
int entry, int64_t timestamp = 0);
226 void SetMetadata(
int entry, std::string_view metadata, int64_t timestamp = 0);
235 void AppendRaw(
int entry, std::span<const uint8_t> data, int64_t timestamp);
244 void AppendRaw2(
int entry, std::span<
const std::span<const uint8_t>> data,
290 void AppendString(
int entry, std::string_view value, int64_t timestamp);
389 : m_buf{new uint8_t[alloc]}, m_maxLen{alloc} {}
396 : m_buf{oth.m_buf}, m_len{oth.m_len}, m_maxLen{oth.m_maxLen} {
408 m_maxLen = oth.m_maxLen;
417 uint8_t* rv = m_buf + m_len;
428 std::span<uint8_t>
GetData() {
return {m_buf, m_len}; }
429 std::span<const uint8_t>
GetData()
const {
return {m_buf, m_len}; }
445 :
m_msglog{msglog}, m_extraHeader{extraHeader} {}
490 static constexpr size_t kMaxBufferCount = 1024 * 1024 /
kBlockSize;
491 static constexpr size_t kMaxFreeCount = 256 * 1024 /
kBlockSize;
494 int StartImpl(std::string_view name, std::string_view type,
495 std::string_view metadata, int64_t timestamp);
496 uint8_t* StartRecord(uint32_t entry, uint64_t timestamp, uint32_t payloadSize,
498 uint8_t* Reserve(
size_t size);
499 void AppendImpl(std::span<const uint8_t> data);
500 void AppendStringImpl(std::string_view str);
501 void AppendStartRecord(
int id, std::string_view name, std::string_view type,
502 std::string_view metadata, int64_t timestamp);
503 void DoReleaseBufs(std::vector<Buffer>* bufs);
510 bool m_active =
false;
511 bool m_paused =
false;
512 std::string m_extraHeader;
513 std::vector<Buffer> m_free;
514 std::vector<Buffer> m_outgoing;
517 std::vector<uint8_t> schemaData;
522 std::string metadata;
536 std::string_view metadata = {}, int64_t timestamp = 0)
537 :
m_log{&log},
m_entry{log.Start(name, type, metadata, timestamp)} {}
556 explicit operator bool()
const {
return m_log !=
nullptr; }
564 void SetMetadata(std::string_view metadata, int64_t timestamp = 0) {
585 std::string_view type, std::string_view metadata = {},
586 int64_t timestamp = 0)
592 std::scoped_lock lock{rhs.m_mutex};
597 std::scoped_lock lock{
m_mutex, rhs.m_mutex};
621 std::scoped_lock lock{
m_mutex};
641 int64_t timestamp = 0)
642 :
RawLogEntry{log, name, metadata, kDataType, timestamp} {}
644 std::string_view type, int64_t timestamp = 0)
653 void Append(std::span<const uint8_t> data, int64_t timestamp = 0) {
654 m_log->AppendRaw(m_entry, data, timestamp);
667 void Update(std::span<const uint8_t> data, int64_t timestamp = 0);
675 static constexpr std::string_view kDataType =
"boolean";
681 std::string_view metadata, int64_t timestamp = 0)
690 void Append(
bool value, int64_t timestamp = 0) {
691 m_log->AppendBoolean(m_entry, value, timestamp);
704 void Update(
bool value, int64_t timestamp = 0) {
705 std::scoped_lock lock{m_mutex};
706 if (m_lastValue != value) {
708 Append(value, timestamp);
718 static constexpr std::string_view kDataType =
"int64";
724 std::string_view metadata, int64_t timestamp = 0)
733 void Append(int64_t value, int64_t timestamp = 0) {
734 m_log->AppendInteger(m_entry, value, timestamp);
747 void Update(int64_t value, int64_t timestamp = 0) {
748 std::scoped_lock lock{m_mutex};
749 if (m_lastValue != value) {
751 Append(value, timestamp);
761 static constexpr std::string_view kDataType =
"float";
767 int64_t timestamp = 0)
776 void Append(
float value, int64_t timestamp = 0) {
777 m_log->AppendFloat(m_entry, value, timestamp);
790 void Update(
float value, int64_t timestamp = 0) {
791 std::scoped_lock lock{m_mutex};
792 if (m_lastValue != value) {
794 Append(value, timestamp);
804 static constexpr std::string_view kDataType =
"double";
810 int64_t timestamp = 0)
819 void Append(
double value, int64_t timestamp = 0) {
820 m_log->AppendDouble(m_entry, value, timestamp);
833 void Update(
double value, int64_t timestamp = 0) {
834 std::scoped_lock lock{m_mutex};
835 if (m_lastValue != value) {
837 Append(value, timestamp);
847 static constexpr const char* kDataType =
"string";
853 int64_t timestamp = 0)
856 std::string_view type, int64_t timestamp = 0)
865 void Append(std::string_view value, int64_t timestamp = 0) {
866 m_log->AppendString(m_entry, value, timestamp);
879 void Update(std::string_view value, int64_t timestamp = 0) {
880 std::scoped_lock lock{m_mutex};
881 if (m_lastValue != value) {
883 Append(value, timestamp);
893 static constexpr const char* kDataType =
"boolean[]";
897 int64_t timestamp = 0)
900 std::string_view metadata, int64_t timestamp = 0)
910 void Append(std::span<const bool> arr, int64_t timestamp = 0) {
911 m_log->AppendBooleanArray(m_entry, arr, timestamp);
920 void Append(std::initializer_list<bool> arr, int64_t timestamp = 0) {
921 Append(std::span{arr.begin(), arr.end()}, timestamp);
930 void Append(std::span<const int> arr, int64_t timestamp = 0) {
931 m_log->AppendBooleanArray(m_entry, arr, timestamp);
940 void Append(std::initializer_list<int> arr, int64_t timestamp = 0) {
941 Append(std::span{arr.begin(), arr.end()}, timestamp);
950 void Append(std::span<const uint8_t> arr, int64_t timestamp = 0) {
951 m_log->AppendBooleanArray(m_entry, arr, timestamp);
964 void Update(std::span<const bool> arr, int64_t timestamp = 0);
976 void Update(std::initializer_list<bool> arr, int64_t timestamp = 0) {
977 Update(std::span{arr.begin(), arr.end()}, timestamp);
990 void Update(std::span<const int> arr, int64_t timestamp = 0);
1002 void Update(std::initializer_list<int> arr, int64_t timestamp = 0) {
1003 Update(std::span{arr.begin(), arr.end()}, timestamp);
1016 void Update(std::span<const uint8_t> arr, int64_t timestamp = 0);
1025 static constexpr const char* kDataType =
"int64[]";
1029 int64_t timestamp = 0)
1032 std::string_view metadata, int64_t timestamp = 0)
1041 void Append(std::span<const int64_t> arr, int64_t timestamp = 0) {
1042 m_log->AppendIntegerArray(m_entry, arr, timestamp);
1051 void Append(std::initializer_list<int64_t> arr, int64_t timestamp = 0) {
1052 Append({arr.begin(), arr.end()}, timestamp);
1065 void Update(std::span<const int64_t> arr, int64_t timestamp = 0);
1077 void Update(std::initializer_list<int64_t> arr, int64_t timestamp = 0) {
1078 Update({arr.begin(), arr.end()}, timestamp);
1087 static constexpr const char* kDataType =
"float[]";
1093 std::string_view metadata, int64_t timestamp = 0)
1102 void Append(std::span<const float> arr, int64_t timestamp = 0) {
1103 m_log->AppendFloatArray(m_entry, arr, timestamp);
1112 void Append(std::initializer_list<float> arr, int64_t timestamp = 0) {
1113 Append({arr.begin(), arr.end()}, timestamp);
1126 void Update(std::span<const float> arr, int64_t timestamp = 0);
1138 void Update(std::initializer_list<float> arr, int64_t timestamp = 0) {
1139 Update({arr.begin(), arr.end()}, timestamp);
1148 static constexpr const char* kDataType =
"double[]";
1152 int64_t timestamp = 0)
1155 std::string_view metadata, int64_t timestamp = 0)
1164 void Append(std::span<const double> arr, int64_t timestamp = 0) {
1165 m_log->AppendDoubleArray(m_entry, arr, timestamp);
1174 void Append(std::initializer_list<double> arr, int64_t timestamp = 0) {
1175 Append({arr.begin(), arr.end()}, timestamp);
1188 void Update(std::span<const double> arr, int64_t timestamp = 0);
1200 void Update(std::initializer_list<double> arr, int64_t timestamp = 0) {
1201 Update({arr.begin(), arr.end()}, timestamp);
1211 static constexpr const char* kDataType =
"string[]";
1215 int64_t timestamp = 0)
1218 std::string_view metadata, int64_t timestamp = 0)
1227 void Append(std::span<const std::string> arr, int64_t timestamp = 0) {
1228 m_log->AppendStringArray(m_entry, arr, timestamp);
1237 void Append(std::span<const std::string_view> arr, int64_t timestamp = 0) {
1238 m_log->AppendStringArray(m_entry, arr, timestamp);
1247 void Append(std::initializer_list<std::string_view> arr,
1248 int64_t timestamp = 0) {
1249 Append(std::span<const std::string_view>{arr.begin(), arr.end()},
1263 void Update(std::span<const std::string> arr, int64_t timestamp = 0);
1275 void Update(std::span<const std::string_view> arr, int64_t timestamp = 0);
1287 void Update(std::initializer_list<std::string_view> arr,
1288 int64_t timestamp = 0) {
1289 Update(std::span<const std::string_view>{arr.begin(), arr.end()},
1297template <
typename T,
typename... I>
1305 int64_t timestamp = 0)
1306 :
StructLogEntry{log, name, {}, std::move(info)..., timestamp} {}
1308 I... info, int64_t timestamp = 0)
1309 : m_info{
std::move(info)...} {
1311 log.AddStructSchema<T, I...>(info..., timestamp);
1313 log.Start(name, GetStructTypeString<T>(info...), metadata, timestamp);
1318 std::scoped_lock lock{rhs.m_mutex};
1319 m_lastValue = std::move(rhs.m_lastValue);
1322 DataLogEntry::operator=(std::move(rhs));
1323 m_info = std::move(rhs.m_info);
1324 std::scoped_lock lock{m_mutex, rhs.m_mutex};
1325 m_lastValue = std::move(rhs.m_lastValue);
1335 void Append(
const T& data, int64_t timestamp = 0) {
1336 if constexpr (
sizeof...(I) == 0) {
1338 uint8_t buf[S::GetSize()];
1340 m_log->AppendRaw(m_entry, buf, timestamp);
1346 std::apply([&](
const I&... info) { S::Pack(buf, data, info...); }, m_info);
1347 m_log->AppendRaw(m_entry, buf, timestamp);
1360 void Update(
const T& data, int64_t timestamp = 0) {
1361 if constexpr (
sizeof...(I) == 0) {
1363 uint8_t buf[S::GetSize()];
1365 std::scoped_lock lock{m_mutex};
1366 if (m_lastValue.empty() ||
1367 !std::equal(buf, buf + S::GetSize(), m_lastValue.begin(),
1368 m_lastValue.end())) {
1369 m_lastValue.assign(buf, buf + S::GetSize());
1370 m_log->AppendRaw(m_entry, buf, timestamp);
1377 std::apply([&](
const I&... info) { S::Pack(buf, data, info...); }, m_info);
1378 std::scoped_lock lock{m_mutex};
1379 if (m_lastValue.empty() ||
1380 !std::equal(buf.
begin(), buf.
end(), m_lastValue.begin(),
1381 m_lastValue.end())) {
1382 m_lastValue.assign(buf.
begin(), buf.
end());
1383 m_log->AppendRaw(m_entry, buf, timestamp);
1406 std::scoped_lock lock{m_mutex};
1407 if (m_lastValue.empty()) {
1408 return std::nullopt;
1411 [&](
const I&... info) {
return S::Unpack(m_lastValue, info...); },
1417 std::vector<uint8_t> m_lastValue;
1418 [[no_unique_address]]
1419 std::tuple<I...> m_info;
1425template <
typename T,
typename... I>
1433 int64_t timestamp = 0)
1436 std::string_view metadata, I... info,
1437 int64_t timestamp = 0)
1438 : m_info{
std::move(info)...} {
1440 log.AddStructSchema<T, I...>(info..., timestamp);
1441 m_entry = log.Start(
1442 name, MakeStructArrayTypeString<T, std::dynamic_extent>(info...),
1443 metadata, timestamp);
1448 m_buf{
std::move(rhs.m_buf)},
1449 m_info{
std::move(rhs.m_info)} {
1450 std::scoped_lock lock{rhs.m_mutex};
1451 m_lastValue = std::move(rhs.m_lastValue);
1454 DataLogEntry::operator=(std::move(rhs));
1455 m_buf = std::move(rhs.m_buf);
1456 m_info = std::move(rhs.m_info);
1457 std::scoped_lock lock{m_mutex, rhs.m_mutex};
1458 m_lastValue = std::move(rhs.m_lastValue);
1468 template <
typename U>
1469#if __cpp_lib_ranges >= 201911L
1470 requires std::ranges::range<U> &&
1471 std::convertible_to<std::ranges::range_value_t<U>, T>
1473 void Append(U&& data, int64_t timestamp = 0) {
1475 [&](
const I&... info) {
1477 std::forward<U>(data),
1478 [&](
auto bytes) { m_log->AppendRaw(m_entry,
bytes, timestamp); },
1490 void Append(std::span<const T> data, int64_t timestamp = 0) {
1492 [&](
const I&... info) {
1495 [&](
auto bytes) { m_log->AppendRaw(m_entry,
bytes, timestamp); },
1511 void Update(std::span<const T> data, int64_t timestamp = 0) {
1513 [&](
const I&... info) {
1517 std::scoped_lock lock{m_mutex};
1518 if (!m_lastValue.has_value()) {
1519 m_lastValue = std::vector(
bytes.begin(),
bytes.end());
1520 m_log->AppendRaw(m_entry,
bytes, timestamp);
1521 }
else if (!std::equal(
bytes.begin(),
bytes.end(),
1522 m_lastValue->begin(),
1523 m_lastValue->end())) {
1524 m_lastValue->assign(
bytes.begin(),
bytes.end());
1525 m_log->AppendRaw(m_entry,
bytes, timestamp);
1552 std::scoped_lock lock{m_mutex};
1553 if (!m_lastValue.has_value()) {
1554 return std::nullopt;
1556 auto& lastValue = m_lastValue.value();
1557 size_t size = std::apply(S::GetSize, m_info);
1559 rv.reserve(lastValue.size() / size);
1560 for (
auto in = lastValue.begin(), end = lastValue.end(); in < end;
1563 [&](
const I&... info) {
1564 rv.emplace_back(S::Unpack(
1565 std::span<const uint8_t>{std::to_address(in), size}, info...));
1575 std::optional<std::vector<uint8_t>> m_lastValue;
1576 [[no_unique_address]]
1577 std::tuple<I...> m_info;
1583template <ProtobufSerializable T>
1592 std::string_view metadata, int64_t timestamp = 0) {
1594 log.AddProtobufSchema<T>(m_msg, timestamp);
1595 m_entry = log.Start(name, m_msg.GetTypeString(), metadata, timestamp);
1604 void Append(
const T& data, int64_t timestamp = 0) {
1607 std::scoped_lock lock{m_mutex};
1608 m_msg.Pack(buf, data);
1610 m_log->AppendRaw(m_entry, buf, timestamp);
1623 void Update(
const T& data, int64_t timestamp = 0) {
1624 std::scoped_lock lock{m_mutex};
1626 m_msg.Pack(buf, data);
1627 if (!m_lastValue.has_value()) {
1628 m_lastValue = std::vector(buf.
begin(), buf.
end());
1629 m_log->AppendRaw(m_entry, buf, timestamp);
1630 }
else if (!std::equal(buf.
begin(), buf.
end(), m_lastValue->begin(),
1631 m_lastValue->end())) {
1632 m_lastValue->assign(buf.
begin(), buf.
end());
1633 m_log->AppendRaw(m_entry, buf, timestamp);
1656 std::scoped_lock lock{m_mutex};
1657 if (!m_lastValue.has_value()) {
1658 return std::nullopt;
1660 return m_msg.Unpack(m_lastValue);
1666 std::optional<std::vector<uint8_t>> m_lastValue;
This file defines the DenseMap class.
This file defines the SmallVector class.
Definition DenseMap.h:759
Ease of use wrapper to make nanopb streams more opaque to the user.
Definition Protobuf.h:307
void ForEachProtobufDescriptor(function_ref< bool(std::string_view filename)> exists, function_ref< void(std::string_view filename, std::span< const uint8_t > descriptor)> fn)
Loops over all protobuf descriptors including nested/referenced descriptors.
Definition Protobuf.h:383
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition SmallVector.h:1212
void resize_for_overwrite(size_type N)
Like resize, but T is POD, the new values won't be initialized.
Definition SmallVector.h:657
iterator begin()
Definition SmallVector.h:283
iterator end()
Definition SmallVector.h:285
StringMap is a sorted associative container that contains key-value pairs with unique string keys.
Definition StringMap.h:26
Log array of boolean values.
Definition DataLog.h:891
void Append(std::span< const uint8_t > arr, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:950
void Append(std::initializer_list< bool > arr, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:920
void Update(std::initializer_list< bool > arr, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
Definition DataLog.h:976
void Update(std::span< const bool > arr, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
BooleanArrayLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition DataLog.h:896
void Append(std::initializer_list< int > arr, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:940
void Append(std::span< const int > arr, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:930
void Append(std::span< const bool > arr, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:910
BooleanArrayLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition DataLog.h:899
void Update(std::initializer_list< int > arr, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
Definition DataLog.h:1002
void Update(std::span< const uint8_t > arr, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
BooleanArrayLogEntry()=default
void Update(std::span< const int > arr, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
Log boolean values.
Definition DataLog.h:673
BooleanLogEntry()=default
BooleanLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition DataLog.h:680
void Append(bool value, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:690
BooleanLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition DataLog.h:678
void Update(bool value, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
Definition DataLog.h:704
std::span< uint8_t > GetData()
Definition DataLog.h:428
Buffer(size_t alloc=kBlockSize)
Definition DataLog.h:388
Buffer(Buffer &&oth)
Definition DataLog.h:395
Buffer & operator=(Buffer &&oth)
Definition DataLog.h:402
~Buffer()
Definition DataLog.h:390
std::span< const uint8_t > GetData() const
Definition DataLog.h:429
void Clear()
Definition DataLog.h:424
Buffer(const Buffer &)=delete
size_t GetRemaining() const
Definition DataLog.h:426
void Unreserve(size_t size)
Definition DataLog.h:422
Buffer & operator=(const Buffer &)=delete
uint8_t * Reserve(size_t size)
Definition DataLog.h:415
Log entry base class.
Definition DataLog.h:532
DataLogEntry(DataLogEntry &&rhs)
Definition DataLog.h:543
DataLogEntry(const DataLogEntry &)=delete
void Finish(int64_t timestamp=0)
Finishes the entry.
Definition DataLog.h:573
DataLog * m_log
Definition DataLog.h:576
DataLogEntry(DataLog &log, std::string_view name, std::string_view type, std::string_view metadata={}, int64_t timestamp=0)
Definition DataLog.h:535
DataLogEntry & operator=(const DataLogEntry &)=delete
int m_entry
Definition DataLog.h:577
DataLogEntry & operator=(DataLogEntry &&rhs)
Definition DataLog.h:546
void SetMetadata(std::string_view metadata, int64_t timestamp=0)
Updates the metadata for the entry.
Definition DataLog.h:564
A data log for high-speed writing of data values.
Definition DataLog.h:70
void AppendBooleanArray(int entry, std::span< const bool > arr, int64_t timestamp)
Appends a boolean array record to the log.
void AppendBooleanArray(int entry, std::span< const int > arr, int64_t timestamp)
Appends a boolean array record to the log.
void SetMetadata(int entry, std::string_view metadata, int64_t timestamp=0)
Updates the metadata for an entry.
void AppendStringArray(int entry, std::span< const std::string > arr, int64_t timestamp)
Appends a string array record to the log.
virtual void Stop()
Stops appending start/metadata/schema records to the log.
int Start(std::string_view name, std::string_view type, std::string_view metadata={}, int64_t timestamp=0)
Start an entry.
DataLog & operator=(const DataLog &)=delete
void AppendRaw(int entry, std::span< const uint8_t > data, int64_t timestamp)
Appends a raw record to the log.
void AppendIntegerArray(int entry, std::span< const int64_t > arr, int64_t timestamp)
Appends an integer array record to the log.
void AddStructSchema(const I &... info, int64_t timestamp=0)
Registers a struct schema.
Definition DataLog.h:183
DataLog(const DataLog &)=delete
void ReleaseBufs(std::vector< Buffer > *bufs)
Releases memory for a set of buffers back to the internal buffer pool.
DataLog(wpi::Logger &msglog, std::string_view extraHeader="")
Constructs the log.
Definition DataLog.h:444
void AppendStringArray(int entry, std::span< const struct WPI_String > arr, int64_t timestamp)
Appends a string array record to the log.
static wpi::Logger s_defaultMessageLog
Definition DataLog.h:384
void AddSchema(std::string_view name, std::string_view type, std::string_view schema, int64_t timestamp=0)
Registers a data schema.
Definition DataLog.h:144
void AppendBooleanArray(int entry, std::span< const uint8_t > arr, int64_t timestamp)
Appends a boolean array record to the log.
void AppendDouble(int entry, double value, int64_t timestamp)
Appends a double record to the log.
void AppendFloat(int entry, float value, int64_t timestamp)
Appends a float record to the log.
DataLog & operator=(const DataLog &&)=delete
wpi::Logger & m_msglog
Definition DataLog.h:506
void AppendFloatArray(int entry, std::span< const float > arr, int64_t timestamp)
Appends a float array record to the log.
virtual void Resume()
Resumes appending of data records to the log.
void AppendString(int entry, std::string_view value, int64_t timestamp)
Appends a string record to the log.
void AddSchema(std::string_view name, std::string_view type, std::span< const uint8_t > schema, int64_t timestamp=0)
Registers a data schema.
DataLog(DataLog &&)=delete
virtual ~DataLog()=default
static constexpr size_t kBlockSize
Definition DataLog.h:383
virtual void Pause()
Pauses appending of data records to the log.
void AppendStringArray(int entry, std::span< const std::string_view > arr, int64_t timestamp)
Appends a string array record to the log.
bool HasSchema(std::string_view name) const
Returns whether there is a data schema already registered with the given name.
virtual bool BufferFull()=0
Called when internal buffers reach the maximum count.
void StartFile()
Starts the log.
void AppendRaw2(int entry, std::span< const std::span< const uint8_t > > data, int64_t timestamp)
Appends a raw record to the log.
void Finish(int entry, int64_t timestamp=0)
Finish an entry.
void AppendDoubleArray(int entry, std::span< const double > arr, int64_t timestamp)
Appends a double array record to the log.
virtual void Flush()=0
Explicitly flushes the log data to disk.
void AppendInteger(int entry, int64_t value, int64_t timestamp)
Appends an integer record to the log.
void FlushBufs(std::vector< Buffer > *writeBufs)
Provides complete set of all buffers that need to be written.
virtual void BufferHalfFull()
Called when internal buffers are half the maximum count.
void AddProtobufSchema(ProtobufMessage< T > &msg, int64_t timestamp=0)
Registers a protobuf schema.
Definition DataLog.h:162
void AppendBoolean(int entry, bool value, int64_t timestamp)
Appends a boolean record to the log.
wpi::mutex m_mutex
Definition DataLog.h:626
std::optional< T > m_lastValue
Definition DataLog.h:627
DataLogValueEntryImpl()=default
std::optional< T > GetLastValue() const
Gets the last value.
Definition DataLog.h:620
DataLogValueEntryImpl & operator=(DataLogValueEntryImpl &&rhs)
Definition DataLog.h:595
DataLogValueEntryImpl(DataLog &log, std::string_view name, std::string_view type, std::string_view metadata={}, int64_t timestamp=0)
Definition DataLog.h:584
bool HasLastValue() const
Gets whether there is a last value.
Definition DataLog.h:610
DataLogValueEntryImpl(DataLogValueEntryImpl &&rhs)
Definition DataLog.h:590
Log array of double values.
Definition DataLog.h:1146
DoubleArrayLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition DataLog.h:1151
void Append(std::span< const double > arr, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:1164
void Append(std::initializer_list< double > arr, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:1174
void Update(std::span< const double > arr, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
DoubleArrayLogEntry()=default
void Update(std::initializer_list< double > arr, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
Definition DataLog.h:1200
DoubleArrayLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition DataLog.h:1154
Log double values.
Definition DataLog.h:802
DoubleLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition DataLog.h:809
void Append(double value, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:819
DoubleLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition DataLog.h:807
void Update(double value, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
Definition DataLog.h:833
Log array of float values.
Definition DataLog.h:1085
void Update(std::initializer_list< float > arr, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
Definition DataLog.h:1138
void Update(std::span< const float > arr, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
FloatArrayLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition DataLog.h:1092
void Append(std::span< const float > arr, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:1102
void Append(std::initializer_list< float > arr, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:1112
FloatArrayLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition DataLog.h:1090
FloatArrayLogEntry()=default
Log float values.
Definition DataLog.h:759
FloatLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition DataLog.h:764
FloatLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition DataLog.h:766
void Update(float value, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
Definition DataLog.h:790
void Append(float value, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:776
Log array of integer values.
Definition DataLog.h:1023
IntegerArrayLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition DataLog.h:1031
void Update(std::initializer_list< int64_t > arr, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
Definition DataLog.h:1077
void Append(std::span< const int64_t > arr, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:1041
IntegerArrayLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition DataLog.h:1028
void Append(std::initializer_list< int64_t > arr, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:1051
void Update(std::span< const int64_t > arr, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
IntegerArrayLogEntry()=default
Log integer values.
Definition DataLog.h:716
IntegerLogEntry()=default
IntegerLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition DataLog.h:723
void Update(int64_t value, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
Definition DataLog.h:747
IntegerLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition DataLog.h:721
void Append(int64_t value, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:733
Log protobuf serializable objects.
Definition DataLog.h:1584
void Update(const T &data, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
Definition DataLog.h:1623
std::optional< T > GetLastValue() const
Gets the last value.
Definition DataLog.h:1655
ProtobufLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition DataLog.h:1589
void Append(const T &data, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:1604
ProtobufLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition DataLog.h:1591
bool HasLastValue() const
Gets whether there is a last value.
Definition DataLog.h:1645
ProtobufLogEntry()=default
Log arbitrary byte data.
Definition DataLog.h:633
RawLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition DataLog.h:640
RawLogEntry(DataLog &log, std::string_view name, std::string_view metadata, std::string_view type, int64_t timestamp=0)
Definition DataLog.h:643
static constexpr std::string_view kDataType
Definition DataLog.h:635
void Append(std::span< const uint8_t > data, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:653
RawLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition DataLog.h:638
void Update(std::span< const uint8_t > data, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
Log array of string values.
Definition DataLog.h:1209
void Update(std::span< const std::string_view > arr, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
void Update(std::span< const std::string > arr, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
void Append(std::initializer_list< std::string_view > arr, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:1247
StringArrayLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition DataLog.h:1217
void Append(std::span< const std::string > arr, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:1227
void Append(std::span< const std::string_view > arr, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:1237
StringArrayLogEntry()=default
void Update(std::initializer_list< std::string_view > arr, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
Definition DataLog.h:1287
StringArrayLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition DataLog.h:1214
Log string values.
Definition DataLog.h:845
StringLogEntry(DataLog &log, std::string_view name, std::string_view metadata, int64_t timestamp=0)
Definition DataLog.h:852
void Append(std::string_view value, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:865
StringLogEntry(DataLog &log, std::string_view name, std::string_view metadata, std::string_view type, int64_t timestamp=0)
Definition DataLog.h:855
void Update(std::string_view value, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
Definition DataLog.h:879
StringLogEntry(DataLog &log, std::string_view name, int64_t timestamp=0)
Definition DataLog.h:850
Log raw struct serializable array of objects.
Definition DataLog.h:1427
bool HasLastValue() const
Gets whether there is a last value.
Definition DataLog.h:1541
StructArrayLogEntry(DataLog &log, std::string_view name, I... info, int64_t timestamp=0)
Definition DataLog.h:1432
void Append(U &&data, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:1473
StructArrayLogEntry()=default
void Update(std::span< const T > data, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
Definition DataLog.h:1511
StructArrayLogEntry & operator=(StructArrayLogEntry &&rhs)
Definition DataLog.h:1453
void Append(std::span< const T > data, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:1490
StructArrayLogEntry(StructArrayLogEntry &&rhs)
Definition DataLog.h:1446
StructArrayLogEntry(DataLog &log, std::string_view name, std::string_view metadata, I... info, int64_t timestamp=0)
Definition DataLog.h:1435
std::optional< std::vector< T > > GetLastValue() const
Gets the last value.
Definition DataLog.h:1551
Log raw struct serializable objects.
Definition DataLog.h:1299
std::optional< T > GetLastValue() const
Gets the last value.
Definition DataLog.h:1405
StructLogEntry & operator=(StructLogEntry &&rhs)
Definition DataLog.h:1321
bool HasLastValue() const
Gets whether there is a last value.
Definition DataLog.h:1395
StructLogEntry(StructLogEntry &&rhs)
Definition DataLog.h:1316
void Update(const T &data, int64_t timestamp=0)
Updates the last value and appends a record to the log if it has changed.
Definition DataLog.h:1360
StructLogEntry(DataLog &log, std::string_view name, I... info, int64_t timestamp=0)
Definition DataLog.h:1304
void Append(const T &data, int64_t timestamp=0)
Appends a record to the log.
Definition DataLog.h:1335
StructLogEntry(DataLog &log, std::string_view name, std::string_view metadata, I... info, int64_t timestamp=0)
Definition DataLog.h:1307
Specifies that a type is capable of raw struct serialization and deserialization.
Definition Struct.h:69
Implement std::hash so that hash_code can be used in STL containers.
Definition PointerIntPair.h:280
ControlRecordType
Definition DataLog.h:40
@ kControlFinish
Definition DataLog.h:42
@ kControlStart
Definition DataLog.h:41
@ kControlSetMetadata
Definition DataLog.h:43
Definition ntcore_cpp.h:31
Foonathan namespace.
Definition ntcore_cpp.h:26
void ForEachStructSchema(std::invocable< std::string_view, std::string_view > auto fn, const I &... info)
Definition Struct.h:424
constexpr bool is_constexpr(Lambda)
Definition type_traits.h:81
::std::mutex mutex
Definition mutex.h:17
uint64_t Now()
Return a value representing the current time in microseconds.
Protobuf serialization template.
Definition Protobuf.h:36
Struct serialization template.
Definition Struct.h:39