mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[wpiutil] DataLog: Move schema info to a separate map (#7626)
This commit is contained in:
@@ -86,10 +86,13 @@ void DataLog::StartFile() {
|
||||
AppendStartRecord(entryInfo.second.id, entryInfo.first,
|
||||
entryInfo.second.type,
|
||||
m_entryIds[entryInfo.second.id].metadata, 0);
|
||||
if (!entryInfo.second.schemaData.empty()) {
|
||||
StartRecord(entryInfo.second.id, 0, entryInfo.second.schemaData.size(),
|
||||
0);
|
||||
AppendImpl(entryInfo.second.schemaData);
|
||||
}
|
||||
|
||||
// Existing schema data records
|
||||
for (auto&& schemaInfo : m_schemas) {
|
||||
if (schemaInfo.second.id != 0) {
|
||||
StartRecord(schemaInfo.second.id, 0, schemaInfo.second.data.size(), 0);
|
||||
AppendImpl(schemaInfo.second.data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,28 +134,26 @@ void DataLog::BufferHalfFull() {}
|
||||
|
||||
bool DataLog::HasSchema(std::string_view name) const {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
wpi::SmallString<128> fullName{"/.schema/"};
|
||||
fullName += name;
|
||||
auto it = m_entries.find(fullName);
|
||||
return it != m_entries.end();
|
||||
return m_schemas.contains(name);
|
||||
}
|
||||
|
||||
void DataLog::AddSchema(std::string_view name, std::string_view type,
|
||||
std::span<const uint8_t> schema, int64_t timestamp) {
|
||||
std::scoped_lock lock{m_mutex};
|
||||
wpi::SmallString<128> fullName{"/.schema/"};
|
||||
fullName += name;
|
||||
auto& entryInfo = m_entries[fullName];
|
||||
if (entryInfo.id != 0) {
|
||||
auto& schemaInfo = m_schemas[name];
|
||||
if (schemaInfo.id != 0) {
|
||||
return; // don't add duplicates
|
||||
}
|
||||
entryInfo.schemaData.assign(schema.begin(), schema.end());
|
||||
schemaInfo.data.assign(schema.begin(), schema.end());
|
||||
wpi::SmallString<128> fullName{"/.schema/"};
|
||||
fullName += name;
|
||||
int entry = StartImpl(fullName, type, {}, timestamp);
|
||||
|
||||
// inline AppendRaw() without releasing lock
|
||||
if (entry <= 0) {
|
||||
[[unlikely]] return; // should never happen, but check anyway
|
||||
}
|
||||
schemaInfo.id = entry;
|
||||
if (!m_active) {
|
||||
[[unlikely]] return;
|
||||
}
|
||||
|
||||
@@ -514,10 +514,14 @@ class DataLog {
|
||||
std::vector<Buffer> m_outgoing;
|
||||
struct EntryInfo {
|
||||
std::string type;
|
||||
std::vector<uint8_t> schemaData; // only set for schema entries
|
||||
int id{0};
|
||||
};
|
||||
wpi::StringMap<EntryInfo> m_entries;
|
||||
struct SchemaInfo {
|
||||
std::vector<uint8_t> data;
|
||||
int id{0};
|
||||
};
|
||||
wpi::StringMap<SchemaInfo> m_schemas;
|
||||
struct EntryInfo2 {
|
||||
std::string metadata;
|
||||
unsigned int count;
|
||||
|
||||
Reference in New Issue
Block a user