Skip to content

Create new classes: properties_view, will_view #248

@jonesmz

Description

@jonesmz

When dealing with wills and mqttv5 properties, currently mqtt_cpp takes the approach of copying the data into either a std::vector of properties, or into the mqtt::will object.

I'd like to instead have mqtt_cpp have two new classes, a properties_view, which provides both an iterator interface, as well as appropriate (but minimal) member functions. The properties_view will internally point to either the raw message received from the network, or some mqtt::properties_collection object which the user of the mqtt_cpp api creates.

Similarly, the mqtt::will_view object will provide a non-owning view into the notion of an mqtt::will, allowing for data received from the network to be referenced directly instead of copied.

Both mqtt::properties_collection and mqtt::will would have member functions to get the "view" version of themselves. Possibly we can make this an explicit conversion operator. (Or implicit, I suppose).

An example of where this would be useful:

There are multiple places in the broker code, where the std::vector of properties is copied to multiple places. do_publish, for example, always involves a copy of the properties that were received in the message being published to each subscriber.

If this were, instead, some kind of mqtt::properties_collection, the publish function could take 1) A mqtt::properties_view, and 2) The shared_ptrmqtt::properties_collection, instead. Saving an allocate and copy on each subscriber.

Retained messages are another example. Each new subscriber gets a full copy of the properties from the message, instead of simply a view to the retained message.

When a will is sent to all subscribers is a third example, not only are the properties copied, but so are the other strings for the message.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions