Class: Warchat::Network::Request
- Inherits:
-
Hash
- Object
- Hash
- Warchat::Network::Request
- Defined in:
- lib/warchat/network/request.rb
Defined Under Namespace
Classes: StringSocket
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(target, *args) ⇒ Request
constructor
A new instance of Request.
- #inspect ⇒ Object
- #stream(socket) ⇒ Object
Constructor Details
#initialize(target, *args) ⇒ Request
Returns a new instance of Request.
24 25 26 27 28 29 30 31 |
# File 'lib/warchat/network/request.rb', line 24 def initialize target,*args @target = target @@request_count ||= -1 @@request_count += 1 @id = @@request_count merge! args.shift if args.first.is_a? Hash super *args end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
22 23 24 |
# File 'lib/warchat/network/request.rb', line 22 def id @id end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
22 23 24 |
# File 'lib/warchat/network/request.rb', line 22 def target @target end |
Instance Method Details
#inspect ⇒ Object
58 59 60 |
# File 'lib/warchat/network/request.rb', line 58 def inspect "<#{self.class.name} id:#{id.inspect} target:#{target.inspect} #{super}>" end |
#stream(socket) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/warchat/network/request.rb', line 33 def stream socket str_socket = StringSocket.new writer = BinaryWriter.new str_socket writer.string(target) writer.int_32(@id) each do |k,v| if [Hash,Array,Warchat::ByteString].none? &v.method(:is_a?) writer.byte 5 writer.string k writer.string v.to_s else writer.byte 4 writer.string k tmp_socket = StringSocket.new tmp = BinaryWriter.new(tmp_socket) tmp.write v writer.int_32(tmp_socket.length) writer.bytes(tmp_socket.value) end writer.byte 0xFF end writer.byte 0xFF socket.print(str_socket.value) end |