OpenCyphal-Garage / libcyphal

Portable reference implementation of the Cyphal protocol stack in C++ for embedded systems and Linux.
http://opencyphal.org
MIT License
282 stars 503 forks source link

Reduce duplication around `TransferMetadata` #365

Open pavel-kirienko opened 1 week ago

pavel-kirienko commented 1 week ago

Here:

https://github.com/OpenCyphal-Garage/libcyphal/blob/5e652de5cb6c9172b833fb8426ba619ce99c4963/include/libcyphal/transport/types.hpp#L58-L79

We discussed that inheritance is not a good choice here, so perhaps we should use composition. After some consideration I realized that the current arrangement will require much manual tinkering in the presentation layer and above.

struct TransferMetadata final
{
    TransferId transfer_id{};
    TimePoint  timestamp;
    Priority   priority{};
};

struct MessageTransferMetadata final
{
    TransferMetadata       base;
    cetl::optional<NodeId> publisher_node_id;
};

struct ServiceTransferMetadata final
{
    TransferMetadata base;
    NodeId           remote_node_id{};
};