22#if PARCEL_HAS_EXPECTED
51 const auto j = json_t::parse(
reinterpret_cast<const char*
>(bytes.data()),
52 reinterpret_cast<const char*
>(bytes.data() + bytes.size()));
65 os <<
json_t().dump(indent);
68 os << c->to_json().dump(indent);
71#if PARCEL_HAS_EXPECTED
73[[nodiscard]]
inline std::expected<cell_t, ParcelError>
74try_cell_from_stream(std::istream& is, ParcelRegistry
const& reg) {
78 }
catch (std::exception
const& e) {
81 return std::unexpected(
84 return reg.try_cell_from_json(j);
88[[nodiscard]]
inline std::expected<cell_t, ParcelError>
89try_cell_from_bytes(
const std::span<const std::byte> bytes, ParcelRegistry
const& reg) {
94 j = json_t::parse(
reinterpret_cast<const char*
>(bytes.data()),
95 reinterpret_cast<const char*
>(bytes.data() + bytes.size()));
97 }
catch (std::exception
const& e) {
100 return std::unexpected(
103 return reg.try_cell_from_json(j);
Core ICell interface, cell_t handle, BaseCell CRTP base, and CellLike concept.
std::shared_ptr< ICell > cell_t
Shared handle to any ICell-derived value — the canonical cell pointer.
Definition cell.h:68
Runtime catalog of cell-type descriptors, keyed by wire kind id.
Definition registry.h:115
cell_t cell_from_json(json_t const &j) const
Deserialize any registered cell from JSON, dispatching by "k".
Definition registry.h:266
ParcelError and the non-throwing surface that returns std::expected.
nlohmann::json typedef shared across cell types.
nlohmann::json json_t
Project-wide alias for nlohmann::json.
Definition json.h:19
void cell_to_stream(std::ostream &os, cell_t const &c, const int indent=-1)
Render c as JSON onto os.
Definition json_io.h:63
cell_t cell_from_bytes(const std::span< const std::byte > bytes, ParcelRegistry const ®)
Read raw bytes as JSON and dispatch via reg.
Definition json_io.h:47
cell_t cell_from_stream(std::istream &is, ParcelRegistry const ®)
Read one JSON document from is and dispatch via reg.
Definition json_io.h:35
ParcelRegistry, Definition, and BuiltinsOptions for polymorphic dispatch.
static ParcelError make(const Code c, std::string msg, std::string kind_id={}, std::string fld={})
Construct from code, message, and optional kind/field tags.
Definition error.h:107
@ InvalidJson
Input was not parseable JSON or had wrong shape.