| File: | lib/Net/MQTT/Message/SubAck.pm |
| Coverage: | 95.5% |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | 3 3 3 | 3162 20 211 | use strict; | ||||
| 2 | 3 3 3 | 39 14 374 | use warnings; | ||||
| 3 | package Net::MQTT::Message::SubAck; | ||||||
| 4 | |||||||
| 5 | # ABSTRACT: Perl module to represent an MQTT SubAck message | ||||||
| 6 | |||||||
| 7 - 17 | =head1 SYNOPSIS # instantiated by Net::MQTT::Message =head1 DESCRIPTION This module encapsulates a single MQTT Subscription Acknowledgement message. It is a specific subclass used by L<Net::MQTT::Message> and should not need to be instantiated directly. =cut | ||||||
| 18 | |||||||
| 19 | 3 3 3 | 38 15 581 | use base 'Net::MQTT::Message'; | ||||
| 20 | 3 3 3 | 38 15 106 | use Net::MQTT::Constants qw/:all/; | ||||
| 21 | |||||||
| 22 | sub message_type { | ||||||
| 23 | 7 | 183 | 9 | ||||
| 24 | } | ||||||
| 25 | |||||||
| 26 | sub attributes { | ||||||
| 27 | 0 | 0 | (shift->SUPER::attributes, qw/message_id qos_levels/) | ||||
| 28 | } | ||||||
| 29 | |||||||
| 30 | =method C<message_id()> | ||||||
| 31 | |||||||
| 32 | Returns the message id field of the MQTT Subscription Acknowledgement | ||||||
| 33 | message. | ||||||
| 34 | |||||||
| 35 | =cut | ||||||
| 36 | |||||||
| 37 | 4 | 89 | sub message_id { shift->{message_id} } | ||||
| 38 | |||||||
| 39 | =method C<qos_levels()> | ||||||
| 40 | |||||||
| 41 | Returns the list of granted QoS fields of the MQTT Subscription | ||||||
| 42 | Acknowledgement message. | ||||||
| 43 | |||||||
| 44 | =cut | ||||||
| 45 | |||||||
| 46 | 4 | 48 | sub qos_levels { shift->{qos_levels} } | ||||
| 47 | |||||||
| 48 | sub _remaining_string { | ||||||
| 49 | 2 | 22 | my ($self, $prefix) = @_; | ||||
| 50 | 2 | 62 | $self->message_id.'/'. | ||||
| 51 | 2 2 | 23 20 | (join ',', map { qos_string($_) } @{$self->qos_levels}). | ||||
| 52 | ' '.$self->SUPER::_remaining_string($prefix) | ||||||
| 53 | } | ||||||
| 54 | |||||||
| 55 | sub _parse_remaining { | ||||||
| 56 | 1 | 10 | my $self = shift; | ||||
| 57 | 1 | 10 | my $offset = 0; | ||||
| 58 | 1 | 36 | $self->{message_id} = decode_short($self->{remaining}, \$offset); | ||||
| 59 | 1 | 21 | while ($offset < length $self->{remaining}) { | ||||
| 60 | 1 1 | 8 39 | push @{$self->{qos_levels}}, decode_byte($self->{remaining}, \$offset)&0x3; | ||||
| 61 | } | ||||||
| 62 | 1 | 38 | substr $self->{remaining}, 0, $offset, ''; | ||||
| 63 | } | ||||||
| 64 | |||||||
| 65 | sub _remaining_bytes { | ||||||
| 66 | 2 | 18 | my $self = shift; | ||||
| 67 | 2 | 26 | my $o = encode_short($self->message_id); | ||||
| 68 | 2 2 | 16 22 | foreach my $qos (@{$self->qos_levels}) { | ||||
| 69 | 2 | 57 | $o .= encode_byte($qos); | ||||
| 70 | } | ||||||
| 71 | $o | ||||||
| 72 | 2 | 62 | } | ||||
| 73 | |||||||
| 74 | |||||||
| 75 | 1; | ||||||