parcel 0.2.2
Wrappable, wire-transferable C++23 value system with JSON serialization
Loading...
Searching...
No Matches
parcel::MemberFieldDescriptor< Payload, FieldT, CellT > Class Template Referencefinal

Concrete payload field descriptor backed by a member pointer. More...

#include <struct.h>

Inheritance diagram for parcel::MemberFieldDescriptor< Payload, FieldT, CellT >:
Collaboration diagram for parcel::MemberFieldDescriptor< Payload, FieldT, CellT >:

Public Member Functions

 MemberFieldDescriptor (FieldT Payload::*member_ptr, std::string key, DisplayInfo info)
 Construct with the member pointer, JSON key, and (initial) display info.
 
std::string_view key () const override
 JSON key under which this field appears in "v".
 
std::string_view kind () const override
 Cell kind id for the field's value type.
 
DisplayInfo display_info () const override
 Display info for this field.
 
bool is_required () const override
 Whether the field must be present on deserialization.
 
json_t to_json () const override
 Serialize the field descriptor itself.
 
DisplayInfomutable_display_info () override
 Mutable access to this field's display info — used by FieldsBuilder.
 
void set_required (const bool r) override
 Override the field's required flag.
 
void to_json_into (json_t &v_obj, Payload const &p) const override
 Serialize this field from p into the value object v_obj.
 
void from_json_into (json_t const &field_json, Payload &p, ParcelRegistry const &reg) const override
 Deserialize this field from field_json into p.
 
std::partial_ordering compare (Payload const &a, Payload const &b) const override
 Three-way compare this field across two payload instances.
 
void to_string_into (std::string &out, Payload const &p) const override
 Append key: value for this field to the rendered string.
 

Detailed Description

template<typename Payload, typename FieldT, CellLike CellT>
class parcel::MemberFieldDescriptor< Payload, FieldT, CellT >

Concrete payload field descriptor backed by a member pointer.

The required flag defaults to false for std::optional<T> fields and true otherwise — matching the natural reading of "optional means may be absent".

The member pointer is held at runtime (not as a non-type template parameter) so it can be a FieldT Base::* implicitly converted to FieldT Payload::*. This keeps FieldsBuilder<Derived>::field<&Base::x> usable for redeclaring/overriding inherited fields after extend<>.

Template Parameters
PayloadThe struct type being described.
FieldTThe type of the member pointed at by member_ptr.
CellTThe cell type used to wrap FieldT on the wire.

Constructor & Destructor Documentation

◆ MemberFieldDescriptor()

template<typename Payload , typename FieldT , CellLike CellT>
parcel::MemberFieldDescriptor< Payload, FieldT, CellT >::MemberFieldDescriptor ( FieldT Payload::*  member_ptr,
std::string  key,
DisplayInfo  info 
)
inline

Construct with the member pointer, JSON key, and (initial) display info.

Parameters
member_ptrPointer-to-member into Payload.
keyJSON key under which this field appears.
infoInitial display info.

Member Function Documentation

◆ compare()

template<typename Payload , typename FieldT , CellLike CellT>
std::partial_ordering parcel::MemberFieldDescriptor< Payload, FieldT, CellT >::compare ( Payload const &  a,
Payload const &  b 
) const
inlineoverridevirtual

Three-way compare this field across two payload instances.

StructCell::compare walks fields in declaration order and short- circuits on the first non-equal result; ignores display info. Optional fields follow std::optional's <=>: absent < present, both absent is equal.

Implements parcel::IPayloadFieldDescriptor< Payload >.

◆ from_json_into()

template<typename Payload , typename FieldT , CellLike CellT>
void parcel::MemberFieldDescriptor< Payload, FieldT, CellT >::from_json_into ( json_t const &  field_json,
Payload &  p,
ParcelRegistry const &  reg 
) const
inlineoverridevirtual

Deserialize this field from field_json into p.

Parameters
field_jsonJSON value for this field (already a wrapped cell).
pPayload instance to write into.
regRegistry forwarded to nested cell deserializers.

Implements parcel::IPayloadFieldDescriptor< Payload >.

◆ to_json()

template<typename Payload , typename FieldT , CellLike CellT>
json_t parcel::MemberFieldDescriptor< Payload, FieldT, CellT >::to_json ( ) const
inlineoverridevirtual

Serialize the field descriptor itself.

Returns
JSON object with key, kind, display_info, required.

Implements parcel::IFieldDescriptor.

◆ to_json_into()

template<typename Payload , typename FieldT , CellLike CellT>
void parcel::MemberFieldDescriptor< Payload, FieldT, CellT >::to_json_into ( json_t v_obj,
Payload const &  p 
) const
inlineoverridevirtual

Serialize this field from p into the value object v_obj.

Parameters
v_objTarget JSON object (the "v" block of the cell).
pPayload instance to read from.

Implements parcel::IPayloadFieldDescriptor< Payload >.

◆ to_string_into()

template<typename Payload , typename FieldT , CellLike CellT>
void parcel::MemberFieldDescriptor< Payload, FieldT, CellT >::to_string_into ( std::string &  out,
Payload const &  p 
) const
inlineoverridevirtual

Append key: value for this field to the rendered string.

Parameters
outString buffer to append to.
pPayload instance to read from.

Implements parcel::IPayloadFieldDescriptor< Payload >.


The documentation for this class was generated from the following file: