Class: BasicSocket

Inherits:
Object show all
Defined in:
lib/doh/core/socket.rb

Instance Method Summary collapse

Instance Method Details

#read_objectObject

it should be noted that in order to use read_object and write_object, the object versions on the client and server side must be identical



17
18
19
# File 'lib/doh/core/socket.rb', line 17

def read_object
  Marshal.load(read_with_amount_header)
end

#read_with_amount_headerObject



4
5
6
7
# File 'lib/doh/core/socket.rb', line 4

def read_with_amount_header
  lenstr = self.read(8)
  self.read(lenstr.to_i)
end

#write_object(obj) ⇒ Object



21
22
23
# File 'lib/doh/core/socket.rb', line 21

def write_object(obj)
  write_with_amount_header(Marshal.dump(obj))
end

#write_with_amount_header(message) ⇒ Object



9
10
11
12
13
# File 'lib/doh/core/socket.rb', line 9

def write_with_amount_header(message)
  lenstr = message.size.to_s.ljust(8)
  self.write(lenstr)
  self.write(message)
end