microavia / messgen

MIT License
9 stars 11 forks source link

Add get_message_name() to cpp generator #47

Closed Roman- closed 2 years ago

Roman- commented 2 years ago

Here's an example of what it looks like in generated code:

namespace msgs {
namespace protocol {

struct ok_reply {
    static constexpr uint8_t TYPE = 15;
    static constexpr size_t STATIC_SIZE = 4;
    static constexpr uint8_t PROTO = PROTO_ID;
    static constexpr bool HAS_DYNAMICS = false;

    uint32_t reply_id;

    static const char* get_message_name() {
        return "ok_reply";
    }

    bool operator== (const radix::msgs::protocol::ok_reply& other) const {
    ...

You can now log every send/receive event in explicit human-readable format:

template<class MESSAGE>
void send(const MESSAGE& message, bool flush = true) {
    _logger->debug("send {} of size {} to '{}'", message.get_message_name(), size, get_name());
    // logs as: send ok_reply of size 9 to 'admin'
}