Class: Rubtella::TCPData::Builder

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

Direct Known Subclasses

Ping, Pong, Query

Defined Under Namespace

Classes: Ping, Pong, Query

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

#initializeBuilder

Returns a new instance of Builder.



38
39
40
41
42
43
44
45
46
# File 'lib/rubtella/tcp_data.rb', line 38

def initialize       
  #initailze all stuff
    init_messages_codes
    
    @guid = GUID
    @ttl = 5
    @hops = 0
    @payload_length = 0
end

Instance Method Details

#buildObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rubtella/tcp_data.rb', line 48

def build
  @data = Array.new
  @guid = GUID
  
  build_message

  @payload_length = @payload.length
  @data = [@guid, @payload_type, @ttl, @hops, @payload_length, @payload]

  @binary_data = @data.flatten.pack("C*")
  @binary_data
end

#build_messageObject



61
62
63
64
# File 'lib/rubtella/tcp_data.rb', line 61

def build_message
  # this method needs to be implemented by a child class
  @payload = []
end

#init_messages_codesObject



27
28
29
30
31
32
33
34
35
# File 'lib/rubtella/tcp_data.rb', line 27

def init_messages_codes
  @messages_codes = {"ping" => 0,
                     "pong" => 1,
                     "push" => 64,
                     "query" => 128,
                     "query_hit" =>129}

  @messages_codes.default = "Unknown Payload Type"
end