class Tkar::MessageStream::Binary
Translate binary command data to ruby method calls.
Constants
- CMD_DATA
Public Instance Methods
get_cmd()
click to toggle source
# File lib/tkar/stream.rb 217 def get_cmd 218 lendata = @fd_in.recv(4) 219 raise "Session ended" if lendata.empty? 220 221 len = lendata.unpack("N") 222 if len < 4 223 raise ArgumentError, "Input too short: #{len}" 224 end 225 if len > 10000 226 raise ArgumentError, "Input too long: #{len}" 227 end 228 229 msg = "" 230 part = nil 231 while (delta = len - msg.length) > 0 and (part = @fd_in.recv(delta)) 232 if part.length == 0 233 raise \ 234 "Peer closed socket before finishing message --" + 235 " received #{msg.length} of #{len} bytes:\n" + 236 msg[0..99].unpack("H*")[0] + "..." 237 end 238 msg << part 239 end 240 241 raise StreamClosed, "Session ended" if msg.empty? 242 parse_cmd(msg) 243 end
parse_cmd(msg)
click to toggle source
# File lib/tkar/stream.rb 272 def parse_cmd msg 273 cmd = msg[0..1].unpack("n") 274 cmd, fmt = CMD_DATA[cmd] 275 [cmd, *msg[2..-1].unpack(fmt)] 276 end
put_msg(msg)
click to toggle source
# File lib/tkar/stream.rb 278 def put_msg(msg) 279 @fd_out.puts msg ## assume output ascii for now 280 @fd_out.flush 281 end