Beekeeper

 view release on metacpan or  search on metacpan

lib/Beekeeper/MQTT.pm  view on Meta::CPAN

use constant MQTT_SUBACK      => 0x09;
use constant MQTT_UNSUBSCRIBE => 0x0A;
use constant MQTT_UNSUBACK    => 0x0B;
use constant MQTT_PINGREQ     => 0x0C;
use constant MQTT_PINGRESP    => 0x0D;
use constant MQTT_DISCONNECT  => 0x0E;
use constant MQTT_AUTH        => 0x0F;

# 2.2.2.2  Properties

use constant MQTT_PAYLOAD_FORMAT_INDICATOR           => 0x01;  # byte           PUBLISH, Will Properties
use constant MQTT_MESSAGE_EXPIRY_INTERVAL            => 0x02;  # long int       PUBLISH, Will Properties
use constant MQTT_CONTENT_TYPE                       => 0x03;  # utf8 string    PUBLISH, Will Properties
use constant MQTT_RESPONSE_TOPIC                     => 0x08;  # utf8 string    PUBLISH, Will Properties
use constant MQTT_CORRELATION_DATA                   => 0x09;  # binary data    PUBLISH, Will Properties
use constant MQTT_SUBSCRIPTION_IDENTIFIER            => 0x0B;  # variable int   PUBLISH, SUBSCRIBE
use constant MQTT_SESSION_EXPIRY_INTERVAL            => 0x11;  # long int       CONNECT, CONNACK, DISCONNECT
use constant MQTT_ASSIGNED_CLIENT_IDENTIFIER         => 0x12;  # utf8 string    CONNACK
use constant MQTT_SERVER_KEEP_ALIVE                  => 0x13;  # short int      CONNACK
use constant MQTT_AUTHENTICATION_METHOD              => 0x15;  # utf8 string    CONNECT, CONNACK, AUTH
use constant MQTT_AUTHENTICATION_DATA                => 0x16;  # binary data    CONNECT, CONNACK, AUTH
use constant MQTT_REQUEST_PROBLEM_INFORMATION        => 0x17;  # byte           CONNECT
use constant MQTT_WILL_DELAY_INTERVAL                => 0x18;  # long int       Will Properties
use constant MQTT_REQUEST_RESPONSE_INFORMATION       => 0x19;  # byte           CONNECT
use constant MQTT_RESPONSE_INFORMATION               => 0x1A;  # utf8 string    CONNACK
use constant MQTT_SERVER_REFERENCE                   => 0x1C;  # utf8 string    CONNACK, DISCONNECT
use constant MQTT_REASON_STRING                      => 0x1F;  # utf8 string    CONNACK, PUBACK, PUBREC, PUBREL, PUBCOMP, SUBACK, UNSUBACK, DISCONNECT, AUTH
use constant MQTT_RECEIVE_MAXIMUM                    => 0x21;  # short int      CONNECT, CONNACK
use constant MQTT_TOPIC_ALIAS_MAXIMUM                => 0x22;  # short int      CONNECT, CONNACK
use constant MQTT_TOPIC_ALIAS                        => 0x23;  # short int      PUBLISH
use constant MQTT_MAXIMUM_QOS                        => 0x24;  # byte           CONNACK
use constant MQTT_RETAIN_AVAILABLE                   => 0x25;  # byte           CONNACK
use constant MQTT_USER_PROPERTY                      => 0x26;  # utf8 pair      CONNECT, CONNACK, PUBLISH, Will Properties, PUBACK, PUBREC, PUBREL, PUBCOMP, SUBSCRIBE, SUBACK, UNSUBSCRIBE, UNSUBACK, DISCONNECT, AUTH
use constant MQTT_MAXIMUM_PACKET_SIZE                => 0x27;  # long int       CONNECT, CONNACK
use constant MQTT_WILDCARD_SUBSCRIPTION_AVAILABLE    => 0x28;  # byte           CONNACK
use constant MQTT_SUBSCRIPTION_IDENTIFIER_AVAILABLE  => 0x29;  # byte           CONNACK
use constant MQTT_SHARED_SUBSCRIPTION_AVAILABLE      => 0x2A;  # byte           CONNACK   

# 2.4  Reason Code

my %Reason_code = (
    0x00 => 'Success',                                # CONNACK, PUBACK, PUBREC, PUBREL, PUBCOMP, UNSUBACK, AUTH
  # 0x00 => 'Normal disconnection',                   # DISCONNECT
  # 0x00 => 'Granted QoS 0',                          # SUBACK
  # 0x01 => 'Granted QoS 1',                          # SUBACK
  # 0x02 => 'Granted QoS 2',                          # SUBACK
    0x04 => 'Disconnect with Will Message',           # DISCONNECT
    0x10 => 'No matching subscribers',                # PUBACK, PUBREC
    0x11 => 'No subscription existed',                # UNSUBACK
    0x18 => 'Continue authentication',                # AUTH
    0x19 => 'Re-authenticate',                        # AUTH
    0x80 => 'Unspecified error',                      # CONNACK, PUBACK, PUBREC, SUBACK, UNSUBACK, DISCONNECT
    0x81 => 'Malformed Packet',                       # CONNACK, DISCONNECT
    0x82 => 'Protocol Error',                         # CONNACK, DISCONNECT
    0x83 => 'Implementation specific error',          # CONNACK, PUBACK, PUBREC, SUBACK, UNSUBACK, DISCONNECT
    0x84 => 'Unsupported Protocol Version',           # CONNACK
    0x85 => 'Client Identifier not valid',            # CONNACK
    0x86 => 'Bad User Name or Password',              # CONNACK
    0x87 => 'Not authorized',                         # CONNACK, PUBACK, PUBREC, SUBACK, UNSUBACK, DISCONNECT
    0x88 => 'Server unavailable',                     # CONNACK
    0x89 => 'Server busy',                            # CONNACK, DISCONNECT
    0x8A => 'Banned',                                 # CONNACK
    0x8B => 'Server shutting down',                   # DISCONNECT
    0x8C => 'Bad authentication method',              # CONNACK, DISCONNECT
    0x8D => 'Keep Alive timeout',                     # DISCONNECT
    0x8E => 'Session taken over',                     # DISCONNECT
    0x8F => 'Topic Filter invalid',                   # SUBACK, UNSUBACK, DISCONNECT
    0x90 => 'Topic Name invalid',                     # CONNACK, PUBACK, PUBREC, DISCONNECT
    0x91 => 'Packet Identifier in use',               # PUBACK, PUBREC, SUBACK, UNSUBACK
    0x92 => 'Packet Identifier not found',            # PUBREL, PUBCOMP
    0x93 => 'Receive Maximum exceeded',               # DISCONNECT
    0x94 => 'Topic Alias invalid',                    # DISCONNECT
    0x95 => 'Packet too large',                       # CONNACK, DISCONNECT
    0x96 => 'Message rate too high',                  # DISCONNECT
    0x97 => 'Quota exceeded',                         # CONNACK, PUBACK, PUBREC, SUBACK, DISCONNECT
    0x98 => 'Administrative action',                  # DISCONNECT
    0x99 => 'Payload format invalid',                 # CONNACK, PUBACK, PUBREC, DISCONNECT
    0x9A => 'Retain not supported',                   # CONNACK, DISCONNECT
    0x9B => 'QoS not supported',                      # CONNACK, DISCONNECT
    0x9C => 'Use another server',                     # CONNACK, DISCONNECT
    0x9D => 'Server moved',                           # CONNACK, DISCONNECT
    0x9E => 'Shared Subscriptions not supported',     # SUBACK, DISCONNECT
    0x9F => 'Connection rate exceeded',               # CONNACK, DISCONNECT
    0xA0 => 'Maximum connect time',                   # DISCONNECT
    0xA1 => 'Subscription Identifiers not supported', # SUBACK, DISCONNECT
    0xA2 => 'Wildcard Subscriptions not supported',   # SUBACK, DISCONNECT
);

# 3.9.3  Subscribe Reason Codes

my %Subscribe_reason_code = (
    %Reason_code,
    0x00 => 'Granted QoS 0',
    0x01 => 'Granted QoS 1',
    0x02 => 'Granted QoS 2',
);

# 3.14.2.1  Disconnect Reason Code

my %Disconnect_reason_code = (
    %Reason_code,
    0x00 => 'Normal disconnection',
);

sub _decode_byte {
    my ($packet, $offs) = @_;

    my $byte = unpack("C", substr($$packet, $$offs, 1));
    $$offs += 1;

    return $byte;
}

sub _decode_int_16 {
    my ($packet, $offs) = @_;

    my $int = unpack("n", substr($$packet, $$offs, 2));
    $$offs += 2;

    return $int;
}



( run in 0.853 second using v1.01-cache-2.11-cpan-5735350b133 )