Class: Wildcloud::Logeen::Transport::Raw
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- Wildcloud::Logeen::Transport::Raw
- Defined in:
- lib/wildcloud/logeen/transport/raw.rb
Instance Method Summary collapse
- #decode_message(buffer) ⇒ Object
-
#initialize(engine = nil) ⇒ Raw
constructor
A new instance of Raw.
- #post_init ⇒ Object
- #receive_data(data = '') ⇒ Object
- #receive_message(message) ⇒ Object
- #unbind ⇒ Object
Constructor Details
#initialize(engine = nil) ⇒ Raw
Returns a new instance of Raw.
11 12 13 14 |
# File 'lib/wildcloud/logeen/transport/raw.rb', line 11 def initialize(engine = nil) super @engine = engine end |
Instance Method Details
#decode_message(buffer) ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/wildcloud/logeen/transport/raw.rb', line 64 def (buffer) type = buffer[0].to_s.unpack('B*').first.to_i(2) data = buffer[1..-1] case type # 0 when 48 data # b when 98 (data.unpack('m*').first) # s when 115 (Snappy.inflate(data)) else nil end rescue Exception puts "Exception" end |
#post_init ⇒ Object
16 17 18 19 20 21 |
# File 'lib/wildcloud/logeen/transport/raw.rb', line 16 def post_init @buffer = '' @offset = 0 @length = nil @separator = "\n" end |
#receive_data(data = '') ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/wildcloud/logeen/transport/raw.rb', line 27 def receive_data(data = '') @buffer << data if @length == 0 if mark = @buffer.index("\n\0\n") @length = nil @buffer = "#{mark+2}#{@separator}" + @buffer end end unless @length mark = @buffer.index(@separator) if mark @length = @buffer[0, mark].to_s.to_i @buffer = @buffer[(mark+1)..-1] end end if @length && @length > 0 && @buffer.size >= @length data = @buffer[0..@length] = (data) () @buffer = @buffer[(@length+1)..-1] @buffer ||= '' @length = nil receive_data end end |
#receive_message(message) ⇒ Object
23 24 25 |
# File 'lib/wildcloud/logeen/transport/raw.rb', line 23 def () @engine << if @engine end |
#unbind ⇒ Object
86 87 88 |
# File 'lib/wildcloud/logeen/transport/raw.rb', line 86 def unbind end |