Class: Rubtella::TCPData::Parser

Inherits:
Base
  • Object
show all
Defined in:
lib/rubtella/tcp_data.rb

Constant Summary

Constants included from Config

Config::GUID, Config::IP_ADDRESS, Config::PID_FILE, Config::PORT

Instance Attribute Summary

Attributes inherited from Base

#binary_data, #guid, #hops, #messages, #messages_codes, #payload_lenght, #payload_type, #rest, #ttl

Instance Method Summary collapse

Methods included from Config

generate_guid

Constructor Details

#initialize(data) ⇒ Parser

Returns a new instance of Parser.



124
125
126
127
# File 'lib/rubtella/tcp_data.rb', line 124

def initialize data 
  @binary_data = data
  parse 
end

Instance Method Details

#messageObject



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/rubtella/tcp_data.rb', line 138

def message
  case @payload_type
  when "\000"
    "ping"
  when "\001"
    "pong"
  when "\100"
    "push"
  when "\200"
    "query"
  when "\201"
    "query"
  else
    raise "Unknown Payload Type"
  end
end

#parseObject



129
130
131
132
133
134
135
136
# File 'lib/rubtella/tcp_data.rb', line 129

def parse
  @guid = @binary_data[0..15]
  @payload_type = @binary_data[16..16]
  @ttl = @binary_data[17..17]
  @hops =  @binary_data[18..18]
  @payload_lenght = @binary_data[19..22]
  @payload = @binary_data[23..-1]
end