module Rexpro::Message
Constants
- PROTOCOL_VERSION
- SERIALIZER_JSON
- SERIALIZER_MSGPACK
- TYPE_ERROR
- TYPE_SCRIPT_REQUEST
- TYPE_SCRIPT_RESPONSE
- TYPE_SESSION_REQUEST
- TYPE_SESSION_RESPONSE
- ZERO_UUID
Public Class Methods
generate_uuid()
click to toggle source
# File lib/rexpro/message.rb, line 22 def generate_uuid @uuid ||= UUID.new hex = @uuid.generate(:compact) ints = hex.each_char.each_slice(8).map { |h| Integer(h.join, 16) } ints.pack('NNNN') end
read_from(io)
click to toggle source
# File lib/rexpro/message.rb, line 33 def read_from(io) version = io.readbyte if version != PROTOCOL_VERSION raise RexproException, "Unknown protocol version #{version}" end header = io.read(10) if header.nil? || header.size < 10 raise RexproException, "Unexpected EOF: #{header.inspect}" end serializer_type, reserved, type, size = header.unpack('CNCN') type_class = types[type] unless type_class raise RexproException, "Unknown message type #{type}" end fields = type_class.fields unpacker = MessagePack::Unpacker.new(io) array_size = unpacker.read_array_header if array_size != fields.length raise RexproException, "Expected #{fields.length} fields, got #{array_size}" end attrs = fields.inject({}) do |memo, field| memo[field] = unpacker.read memo end attrs[:serializer_type] = serializer_type type_class.new(attrs) end
types()
click to toggle source
# File lib/rexpro/message.rb, line 29 def types @types ||= {} end