parcel 0.2.2
Wrappable, wire-transferable C++23 value system with JSON serialization
Loading...
Searching...
No Matches
ulid.h
Go to the documentation of this file.
1#pragma once
2
17#if !defined(PARCEL_HAS_ULID)
18#if defined(__has_include)
19#if __has_include(<ulid/ulid.h>)
20#define PARCEL_HAS_ULID 1
21#else
22#define PARCEL_HAS_ULID 0
23#endif
24#else
25#define PARCEL_HAS_ULID 0
26#endif
27#endif
28
29#if PARCEL_HAS_ULID
30
31#include <parcel/cell.h>
32#include <parcel/defaults.h>
33#include <parcel/descriptor.h>
34#include <parcel/json.h>
35
36#include <memory>
37#include <string>
38#include <string_view>
39
40#include <ulid/ulid.h>
41
42namespace parcel {
43
53class UlidCell : public BaseCell<UlidCell, ulid::Ulid> {
54 using base_t = BaseCell<UlidCell, ulid::Ulid>;
55
56public:
57 using base_t::base_t;
58 using base_t::operator=;
59
60 static constexpr std::string_view kind_id = "ulid";
61
62 [[nodiscard]] std::string to_string() const override {
63 return this->value.string();
64 }
65
66 static cell_t from_json(json_t const& j, ParcelRegistry const&) {
67 auto v = base_t::cell_from_json<ulid::Ulid>(j, kind_id);
68 auto cell = std::make_shared<UlidCell>(v);
69 base_t::absorb_display_info(j, cell);
70 return cell;
71 }
72
73 static cell_type_descriptor_t descriptor() {
74 static const auto d = std::make_shared<SimpleCellTypeDescriptor<UlidCell>>(DisplayInfo{
75 .name = "ULID", .description = "ULID (26-char Crockford base32 string on the wire)"});
76 return d;
77 }
78};
79
80} // namespace parcel
81
82PARCEL_DEFAULT_CELL(parcel::UlidCell);
83
84#endif // PARCEL_HAS_ULID
Core ICell interface, cell_t handle, BaseCell CRTP base, and CellLike concept.
std::string to_string(cell_t const &c)
Free to_string over cell_t; returns "<null>" for null handles.
Definition cell.h:711
std::shared_ptr< ICellTypeDescriptor > cell_type_descriptor_t
Shared handle to a runtime cell-type descriptor.
Definition cell.h:63
std::shared_ptr< ICell > cell_t
Shared handle to any ICell-derived value — the canonical cell pointer.
Definition cell.h:68
comms::DisplayInfo DisplayInfo
Display info attached to a cell or descriptor — re-exported from comms::DisplayInfo.
Definition common.h:75
The default_cell_for<T> trait that drives FieldsBuilder field-type inference.
#define PARCEL_DEFAULT_CELL(CellT)
Register a cell type as the default wrapper for its payload type.
Definition defaults.h:269
auto cell(T &&v)
Wrap a raw value into its default cell, returning a shared_ptr to the cell.
Definition defaults.h:192
Runtime cell-type descriptors and the schema-graph mix-ins (IHasFields, ISubTypes).
nlohmann::json typedef shared across cell types.