Module: HubeyeProtocol
- Included in:
- TCPSocket
- Defined in:
- lib/hubeye/shared/hubeye_protocol.rb
Constant Summary collapse
- HEADER_BYTE_SIZE =
4
Instance Method Summary collapse
Instance Method Details
#deliver(body) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/hubeye/shared/hubeye_protocol.rb', line 6 def deliver(body) header = header(body) mesg = header + body self.print mesg self.flush end |
#header(body) ⇒ Object
13 14 15 16 |
# File 'lib/hubeye/shared/hubeye_protocol.rb', line 13 def header(body) body_size = body.bytesize [body_size].pack("N") end |
#read_all ⇒ Object
18 19 20 21 |
# File 'lib/hubeye/shared/hubeye_protocol.rb', line 18 def read_all read_header read(@body_size) end |
#read_header ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/hubeye/shared/hubeye_protocol.rb', line 23 def read_header begin @body_size = read(HEADER_BYTE_SIZE).unpack("N").first.to_i rescue => e STDOUT.puts e. STDOUT.puts e.backtrace exit 1 end end |