19#include <commons/color.hpp>
20#include <commons/icons.hpp>
22#include <md/object.hpp>
23#include <md/ostream.hpp>
24#include <md/value.hpp>
31#include <parcel/parcel.h>
39class ValueCell :
public parcel::BaseCell<ValueCell, Value> {
40 using base_t = parcel::BaseCell<ValueCell, Value>;
49 using base_t::operator=;
52 static constexpr std::string_view
kind_id =
"md:v";
56 [[nodiscard]] std::string
to_string()
const override {
57 std::ostringstream os;
67 [[maybe_unused]]
static parcel::cell_t
from_json(parcel::json_t
const& j,
68 parcel::ParcelRegistry
const&) {
69 return base_t::from_json_strict(j);
76 std::make_shared<parcel::SimpleCellTypeDescriptor<ValueCell>>(parcel::DisplayInfo{
78 .description =
"Dynamic JSON-shaped value from the metadata library.",
79 .icon = comms::Icons::mdi::variable,
80 .color = comms::Colors::mui::deep_purple[500],
90class ObjectCell :
public parcel::BaseCell<ObjectCell, Object> {
91 using base_t = parcel::BaseCell<ObjectCell, Object>;
97 using base_t::operator=;
106 static constexpr std::string_view
kind_id =
"md:o";
111 std::ostringstream os;
120 [[maybe_unused]]
static parcel::cell_t
from_json(parcel::json_t
const& j,
121 parcel::ParcelRegistry
const&) {
122 return base_t::from_json_strict(j);
127 static const auto d =
128 std::make_shared<parcel::SimpleCellTypeDescriptor<ObjectCell>>(parcel::DisplayInfo{
129 .name =
"md::Object",
130 .description =
"Unordered string-keyed map of md::Value (md::Object/Metadata).",
131 .icon = comms::Icons::mdi::code_braces,
132 .color = comms::Colors::mui::amber[700],
142class ArrayCell :
public parcel::BaseCell<ArrayCell, Array> {
143 using base_t = parcel::BaseCell<ArrayCell, Array>;
147 using base_t::base_t;
149 using base_t::operator=;
156 template <
class T0,
class T1,
class... Rest>
157 requires(std::constructible_from<Value, T0 &&> && std::constructible_from<Value, T1 &&> &&
158 (std::constructible_from<Value, Rest &&> && ...))
160 : base_t(Array{
Value(std::forward<T0>(a)),
161 Value(std::forward<T1>(b)),
162 Value(std::forward<Rest>(rest))...}) {}
165 static constexpr std::string_view
kind_id =
"md:a";
170 std::ostringstream os;
179 [[maybe_unused]]
static parcel::cell_t
from_json(parcel::json_t
const& j,
180 parcel::ParcelRegistry
const&) {
181 return base_t::from_json_strict(j);
186 static const auto d =
187 std::make_shared<parcel::SimpleCellTypeDescriptor<ArrayCell>>(parcel::DisplayInfo{
189 .description =
"Heterogeneous vector of md::Value (md::Array).",
190 .icon = comms::Icons::mdi::code_brackets,
191 .color = comms::Colors::mui::green[600],
217#define METADATA_HAS_PARCEL 1
Parcel cell wrapping an md::Array (std::vector<md::Value>).
Definition parcel.hpp:142
std::string to_string() const override
Compact textual rendering of the wrapped md::Array, identical to streaming via operator<<.
Definition parcel.hpp:169
static constexpr std::string_view kind_id
Wire-stable kind id reported under the "k" slot.
Definition parcel.hpp:165
ArrayCell(T0 &&a, T1 &&b, Rest &&... rest)
Brace-init passthrough so md::ArrayCell{"a", "b", "c"} mirrors md::Array{...}.
Definition parcel.hpp:159
static parcel::cell_type_descriptor_t descriptor()
Registry descriptor for ArrayCell.
Definition parcel.hpp:185
static parcel::cell_t from_json(parcel::json_t const &j, parcel::ParcelRegistry const &)
Parcel deserialization entry point.
Definition parcel.hpp:179
Parcel cell wrapping an md::Object (a.k.a.
Definition parcel.hpp:90
std::string to_string() const override
Compact textual rendering of the wrapped md::Object, identical to streaming via operator<<.
Definition parcel.hpp:110
static constexpr std::string_view kind_id
Wire-stable kind id reported under the "k" slot.
Definition parcel.hpp:106
static parcel::cell_t from_json(parcel::json_t const &j, parcel::ParcelRegistry const &)
Parcel deserialization entry point.
Definition parcel.hpp:120
ObjectCell(std::initializer_list< Object::value_type > il)
Brace-init passthrough so md::ObjectCell{{"k", 1}, {"k2", "v"}} mirrors md::Object{....
Definition parcel.hpp:103
static parcel::cell_type_descriptor_t descriptor()
Registry descriptor for ObjectCell.
Definition parcel.hpp:126
Ordered-by-insertion-time-ish string-keyed map of Values, with transparent string-view lookup and JSO...
Definition object.hpp:21
Parcel cell wrapping an md::Value.
Definition parcel.hpp:39
static parcel::cell_t from_json(parcel::json_t const &j, parcel::ParcelRegistry const &)
Parcel deserialization entry point.
Definition parcel.hpp:67
std::string to_string() const override
Compact textual rendering of the wrapped md::Value, identical to streaming via operator<< (escaped JS...
Definition parcel.hpp:56
static parcel::cell_type_descriptor_t descriptor()
Registry descriptor for ValueCell.
Definition parcel.hpp:74
static constexpr std::string_view kind_id
Wire-stable kind id reported under the "k" slot.
Definition parcel.hpp:52
Discriminated union holding one of the JSON-like alternatives (null, bool, signed/unsigned integer,...
Definition value.hpp:67
void register_cells(parcel::ParcelRegistry ®istry)
Register all three md cells (md:v, md:o, md:a) on registry.
Definition parcel.hpp:203