Class: Mosquitto::Message

Inherits:
Object
  • Object
show all
Defined in:
ext/mosquitto/message.c

Instance Method Summary collapse

Instance Method Details

#lengthInteger

The length of the message payload

Examples:

msg.length -> 7

Returns:

  • (Integer)

Returns:

  • (Integer)

    message length



102
103
104
105
106
107
108
# File 'ext/mosquitto/message.c', line 102

static VALUE rb_mosquitto_message_length(VALUE obj)
{
    struct mosquitto_message *msg;
    MosquittoGetMessage(obj);
    msg = message->msg;
    return INT2NUM(msg->payloadlen);
}

#midInteger

Message identifier for this message. Note that although the MQTT protocol doesn’t use message ids for messages with QoS=0, libmosquitto assigns them message ids so they can be tracked with this parameter.

Examples:

msg.mid -> 2

Returns:

  • (Integer)

Returns:

  • (Integer)

    message identifier



45
46
47
48
49
50
51
# File 'ext/mosquitto/message.c', line 45

static VALUE rb_mosquitto_message_mid(VALUE obj)
{
    struct mosquitto_message *msg;
    MosquittoGetMessage(obj);
    msg = message->msg;
    return INT2NUM(msg->mid);
}

#qosInteger

Quality of Service used for the message

Examples:

msg.qos -> Mosquitto::AT_MOST_ONCE

Returns:

  • (Integer)

Returns:

  • (Integer)

    message quality of service

See Also:



125
126
127
128
129
130
131
# File 'ext/mosquitto/message.c', line 125

static VALUE rb_mosquitto_message_qos(VALUE obj)
{
    struct mosquitto_message *msg;
    MosquittoGetMessage(obj);
    msg = message->msg;
    return INT2NUM(msg->qos);
}

#retain?Boolean

Set to true if this message was flagged to retain.

Examples:

msg.retain? -> true

Returns:

  • (Boolean)

Returns:

  • (true, false)

    retention flag



144
145
146
147
148
149
150
# File 'ext/mosquitto/message.c', line 144

static VALUE rb_mosquitto_message_retain_p(VALUE obj)
{
    struct mosquitto_message *msg;
    MosquittoGetMessage(obj);
    msg = message->msg;
    return (msg->retain == true) ? Qtrue : Qfalse;
}

#to_sString

Coerces the Mosquitto::Message payload to a Ruby string.

Examples:

msg.to_s -> "message"

Returns:

  • (String)

Returns:

  • (String)

    message payload



83
84
85
86
87
88
89
# File 'ext/mosquitto/message.c', line 83

static VALUE rb_mosquitto_message_to_s(VALUE obj)
{
    struct mosquitto_message *msg;
    MosquittoGetMessage(obj);
    msg = message->msg;
    return MosquittoEncode(rb_str_new(msg->payload, msg->payloadlen));
}

#topicString

Topic this message was published on.

Examples:

msg.topic -> "test"

Returns:

  • (String)

Returns:

  • (String)

    topic



64
65
66
67
68
69
70
# File 'ext/mosquitto/message.c', line 64

static VALUE rb_mosquitto_message_topic(VALUE obj)
{
    struct mosquitto_message *msg;
    MosquittoGetMessage(obj);
    msg = message->msg;
    return MosquittoEncode(rb_str_new2(msg->topic));
}