Skip to content

so5extra 1.6 Enveloped Msg Just Envelope

Yauheni Akhotnikau edited this page Apr 21, 2023 · 1 revision

Purpose

Helper class so_5::extra::enveloped_msg::just_enveloped_t is intended for simplification of development of custom envelopes. For example, a simple custom envelope written from scratch can looks like:

class my_simple_envelope final : public so_5::enveloped_msg::envelope_t {
    so_5::message_ref_t payload_;
    ... // some specific stuff.
protected:
    so_5::message_mutability_t so5_message_mutability() const noexcept override {
        return message_mutability(payload_);
    }
    void so5_change_mutability(so_5::message_mutability_t new_value) override {
        // Changing of message mutability is prohibited.
        if(new_value != so5_message_mutability())
            throw some_exception(...);
    }
public:
    my_simple_envelope(so_5::message_ref_t payload) : payload_{std::move(payload)} {}
    ~my_simple_envelope() noexcept override = default;
    
    void access_hook(access_context_t context, handler_invoker_t & invoker) noexcept override {
        ... // Some specific code.
    }
};

But with use of so_5::extra::enveloped_msg::just_envelope_t this implementation can be much more compact:

class my_simple_envelope final : public so_5::extra::enveloped_msg::just_envelope_t {
    using base_type = so_5::extra::enveloped_msg::just_envelope_t;
public:
    using base_type::base_type;
    void access_hook(access_context_t context, handler_invoker_t & invoker) noexcept override {
        ... // Some specific code.
    }
};

Header File

The class so_5::extra::enveloped_msg::just_envelope_t is defined in so_5_extra/enveloped_msg/just_envelope.hpp header file. So to use this functionality it is necessary to include that file and so_5/all.hpp file:

#include <so_5_extra/enveloped_msg/just_envelope.hpp>

#include <so_5/all.hpp>

Access To The Payload

The just_envelope_t provides access to the payload via two protected methods:

[[nodiscard]]
so_5::enveloped_msg::payload_info_t whole_payload() const noexcept;

[[nodiscard]]
so_5::message_ref_t & payload() const noexcept;

Method whole_payload() is useful inside access_hook():

void my_envelope::access_hook(access_context_t, handler_invoker_t & invoker) noexcept {
    if(can_access_be_granted())
        invoker.invoke(whole_payload());
}

Mutability

An instance of just_envelope_t inherits mutability from its payload.

The mutability of just_envelope_t can't be changed.

Copyability and Movability

The class so_5::extra::enveloped_msg::just_envelope_t is not Copyable nor Moveable.

Clone this wiki locally