telemetry_json: Use the PImpl idiom to avoid unnecessary dependency exposure
Users of the web_service library shouldn't need to care about an external library like json.h. However, given it's exposed in our interface, this requires that other libraries publicly link in the JSON library. We can do better. By using the PImpl idiom, we can hide this dependency in the cpp file and remove the need to link that library in altogether.
This commit is contained in:
parent
c422f146ee
commit
a7725d354c
2 changed files with 54 additions and 48 deletions
|
@ -4,10 +4,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <chrono>
|
||||
#include <string>
|
||||
#include <json.hpp>
|
||||
#include "common/telemetry.h"
|
||||
|
||||
namespace WebService {
|
||||
|
@ -39,20 +37,8 @@ public:
|
|||
void Complete() override;
|
||||
|
||||
private:
|
||||
nlohmann::json& TopSection() {
|
||||
return sections[static_cast<u8>(Telemetry::FieldType::None)];
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void Serialize(Telemetry::FieldType type, const std::string& name, T value);
|
||||
|
||||
void SerializeSection(Telemetry::FieldType type, const std::string& name);
|
||||
|
||||
nlohmann::json output;
|
||||
std::array<nlohmann::json, 7> sections;
|
||||
std::string host;
|
||||
std::string username;
|
||||
std::string token;
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> impl;
|
||||
};
|
||||
|
||||
} // namespace WebService
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue