ReUseX  0.0.5
3D Point Cloud Processing for Building Reuse
Loading...
Searching...
No Matches
format_handler.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 Povl Filip Sonne-Frederiksen
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#pragma once
6
7#include <cstdint>
8#include <filesystem>
9#include <nlohmann/json.hpp>
10#include <string>
11#include <variant>
12#include <vector>
13
14namespace rux::database {
15
19enum class OutputFormat {
20 Binary, // Raw binary data (point clouds, meshes, images)
21 JSON, // JSON object or array
22 Text // Plain text (scalar values)
23};
24
34 std::variant<std::string, std::vector<uint8_t>, nlohmann::json>;
35
43
55void write_output(const DataPayload &payload, bool force_pretty = false);
56
63void write_to_file(const DataPayload &payload,
64 const std::filesystem::path &file_path);
65
72
82std::string json_to_text(const nlohmann::json &j);
83
84} // namespace rux::database
OutputFormat detect_format(const DataPayload &payload)
Detect format from payload type.
bool is_stdout_tty()
Check if stdout is a TTY (for format detection).
void write_to_file(const DataPayload &payload, const std::filesystem::path &file_path)
Write data to a file.
std::variant< std::string, std::vector< uint8_t >, nlohmann::json > DataPayload
Data payload that can be returned by routers.
OutputFormat
Output format types.
std::string json_to_text(const nlohmann::json &j)
Convert JSON to text (for scalar values).
void write_output(const DataPayload &payload, bool force_pretty=false)
Write data to stdout with appropriate formatting.