Module: MQTTPipe::Types::Type

Extended by:
Type
Included in:
Type
Defined in:
lib/mqtt_pipe/types/type.rb

Instance Method Summary collapse

Instance Method Details

#from_packed(_, raw) ⇒ Object



31
32
33
# File 'lib/mqtt_pipe/types/type.rb', line 31

def from_packed _, raw
  lookup(Packer.read_packed_bytes 1, from: raw)
end

#lookup(type) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mqtt_pipe/types/type.rb', line 14

def lookup type
  case type
  when 0x80..0x9F then Array
  when 0xA0..0xBF then String
  when 0xC0       then Type          
  when 0xC1       then NilClass
  when 0xC2       then FalseClass
  when 0xC3       then TrueClass
  when 0xC7       then Float
  when 0xC8       then Time
  when 0xC9       then Color
  when 0x00..0x7F,
       0xD0..0xFF,
       0xC4..0xC6 then Integer
  end
end

#packer_codeObject



6
7
8
# File 'lib/mqtt_pipe/types/type.rb', line 6

def packer_code
  0xC0
end

#to_packedObject



10
11
12
# File 'lib/mqtt_pipe/types/type.rb', line 10

def to_packed
  [packer_code, packer_code].pack 'C2'
end