FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
desktop.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#include <string>
12#include <filesystem>
13
14#include "../std/expected.hpp"
15#include "../macro.hpp"
16#include "reserved.hpp"
17
28{
29
30namespace
31{
32
33namespace fs = std::filesystem;
34
35}
36
44inline Value<void> write(fs::path const& path_file_binary, std::string_view const& json)
45{
46 uint64_t space_available = ns_reserved::FIM_RESERVED_OFFSET_DESKTOP_END - ns_reserved::FIM_RESERVED_OFFSET_DESKTOP_BEGIN;
47 uint64_t space_required = json.size();
48 return_if(space_available <= space_required, Error("E::Not enough space to fit json data"));
49 Pop(ns_reserved::write(path_file_binary
50 , FIM_RESERVED_OFFSET_DESKTOP_BEGIN
51 , FIM_RESERVED_OFFSET_DESKTOP_END
52 , json.data()
53 , json.size()
54 ));
55 return {};
56}
57
64inline Value<std::string> read(fs::path const& path_file_binary)
65{
66 uint64_t offset_begin = ns_reserved::FIM_RESERVED_OFFSET_DESKTOP_BEGIN;
67 uint64_t size = ns_reserved::FIM_RESERVED_OFFSET_DESKTOP_END - offset_begin;
68 auto buffer = std::make_unique<char[]>(size);
69 Pop(ns_reserved::read(path_file_binary, offset_begin, buffer.get(), size));
70 return buffer.get();
71}
72
73} // namespace ns_reserved::ns_desktop
74
75/* vim: set expandtab fdm=marker ts=2 sw=2 tw=100 et :*/
Enhanced error handling framework built on std::expected.
Simplified macros for common control flow patterns with optional logging.
Desktop integration data storage in reserved space.
Value< void > write(fs::path const &path_file_binary, std::string_view const &json)
Writes the desktop json string to the target binary.
Definition desktop.hpp:44
Value< std::string > read(fs::path const &path_file_binary)
Reads the desktop json string from the target binary.
Definition desktop.hpp:64
Value< void > write(fs::path const &path_file_binary, uint64_t offset_begin, uint64_t offset_end, const char *data, uint64_t length) noexcept
Writes data to a file in binary format.
Definition reserved.hpp:142
Value< std::streamsize > read(fs::path const &path_file_binary, uint64_t offset, char *data, uint64_t length) noexcept
Reads data from a file in binary format.
Definition reserved.hpp:172
Manages reserved space.
Enhanced expected type with integrated logging capabilities.
Definition expected.hpp:44