class MQTT::V5::Publish

Overview

MQTT-3.3. Same as 3.1.1 with a property section between the packet identifier and the payload

Defined in:

mqtt/v5/publish.cr

Constant Summary

AFTER_DESERIALIZE = [] of Nil

MQTT-3.3. Same as 3.1.1 with a property section between the packet identifier and the payload

ALLOWED_PROPERTIES = [PropertyId::PayloadFormatIndicator, PropertyId::MessageExpiryInterval, PropertyId::TopicAlias, PropertyId::ResponseTopic, PropertyId::CorrelationData, PropertyId::UserProperty, PropertyId::SubscriptionIdentifier, PropertyId::ContentType]
BEFORE_SERIALIZE = [] of Nil

MQTT-3.3. Same as 3.1.1 with a property section between the packet identifier and the payload

ENDIAN = ["big"]

MQTT-3.3. Same as 3.1.1 with a property section between the packet identifier and the payload

KLASS_NAME = [MQTT::V5::Publish]

MQTT-3.3. Same as 3.1.1 with a property section between the packet identifier and the payload

PARTS = [{type: "basic", name: topic_size, cls: UInt16, onlyif: nil, verify: nil, value: -> do topic.bytesize end, endian: nil}, {type: "string", name: topic, cls: String, onlyif: nil, verify: nil, length: -> do topic_size end, value: nil, encoding: nil}, {type: "basic", name: message_id, cls: UInt16, onlyif: -> do qos? end, verify: nil, value: nil, endian: nil}, {type: "basic", name: properties, cls: MQTT::V5::Properties, onlyif: nil, verify: nil, value: nil}, {type: "bytes", name: payload, cls: Slice(UInt8), onlyif: nil, verify: nil, length: -> do overhead = (topic.bytesize + 2) + properties.total_size if qos? overhead = overhead + 2 end len = packet_length.to_i64 - overhead if len < 0 raise(MQTT::ProtocolError.new("publish packet length #{packet_length} is too small for its topic and properties")) end len end, value: nil}] of Nil

MQTT-3.3. Same as 3.1.1 with a property section between the packet identifier and the payload

REMAINING = [] of Nil

MQTT-3.3. Same as 3.1.1 with a property section between the packet identifier and the payload

Class Method Summary

Instance Method Summary

Instance methods inherited from class MQTT::Header

__format__ : IO::ByteFormat __format__, duplicate : Bool duplicate, duplicate=(duplicate : UInt8)
duplicate=(value : Bool)
duplicate=
, fixed_header_size : Int32 fixed_header_size, id : MQTT::RequestType id, id=(id : UInt8)
id=(value : MQTT::RequestType)
id=
, packet_length : UInt32 packet_length, packet_length=(size : UInt32) : UInt32 packet_length=, qos : MQTT::QoS qos, qos=(qos : UInt8)
qos=(value : MQTT::QoS)
qos=
, qos? qos?, retain : Bool retain, retain=(retain : UInt8)
retain=(value : Bool)
retain=
, variable_length1 : UInt8 variable_length1, variable_length1=(value : UInt8) : UInt8 variable_length1=, variable_length2 : UInt8 variable_length2, variable_length2=(value : UInt8) : UInt8 variable_length2=, variable_length3 : UInt8 variable_length3, variable_length3=(value : UInt8) : UInt8 variable_length3=, variable_length4 : UInt8 variable_length4, variable_length4=(value : UInt8) : UInt8 variable_length4=

Class methods inherited from class MQTT::Header

bit_fields bit_fields

Class Method Detail

def self.bit_fields #

MQTT-3.3. Same as 3.1.1 with a property section between the packet identifier and the payload


[View source]

Instance Method Detail

def __format__ : IO::ByteFormat #

A group or bit_field captures the endianness at its declaration point, so declaring endian after one would silently leave it system-endian. Fail loudly.


[View source]
def add_subscription_identifier(value : UInt32) : Nil #

[View source]
def add_user_property(key : String, value : String) : Nil #

[View source]
def calculate_length : UInt32 #

[View source]
def content_type : String | Nil #

[View source]
def content_type=(value : String | Nil) #

[View source]
def correlation_data : Bytes | Nil #

[View source]
def correlation_data=(value : Bytes | Nil) #

[View source]
def message_expiry_interval : UInt32 | Nil #

[View source]
def message_expiry_interval=(value : UInt32 | Nil) #

[View source]
def message_id : UInt16 #

def message_id=(message_id : UInt16) #

def payload : Bytes #

NOTE : the arithmetic is signed on purpose. A malformed packet can advertise a remaining length smaller than the fields preceding the payload, which underflows UInt32 into a ~4GB allocation


def payload=(payload : Bytes) #

NOTE : the arithmetic is signed on purpose. A malformed packet can advertise a remaining length smaller than the fields preceding the payload, which underflows UInt32 into a ~4GB allocation


def payload=(message) #

[View source]
def payload_format_indicator : UInt8 | Nil #

0 for arbitrary bytes, 1 for UTF-8. MQTT-3.3.2.3.2


[View source]
def payload_format_indicator=(value : UInt8 | Nil) #

[View source]
def properties : Properties #

def properties=(properties : Properties) #

def response_topic : String | Nil #

The request/response pattern, MQTT-3.3.2.3.5


[View source]
def response_topic=(value : String | Nil) #

[View source]
def subscription_identifiers : Array(UInt32) #

Which subscriptions caused the broker to send us this message. Repeatable, because one message can match several subscriptions


[View source]
def topic : String #

def topic=(topic : String) #

def topic_alias : UInt16 | Nil #

Replaces the topic string for the rest of the connection. Zero is not a valid alias, MQTT-3.3.2.3.4


[View source]
def topic_alias=(value : UInt16 | Nil) #

[View source]
def topic_size : UInt16 #

def topic_size=(topic_size : UInt16) #

def user_properties : Array(Tuple(String, String)) #

[View source]
def utf8_payload? : Bool #

[View source]
def validate! : self #

[View source]