lib/vertica/messages/message.rb in vertica-0.7.4 vs lib/vertica/messages/message.rb in vertica-0.8.1

- old
+ new

@@ -1,85 +1,54 @@ module Vertica module Messages + class Message - LENGTH_SIZE = 4 + def self.message_id(message_id) + self.send(:define_method, :message_id) { message_id } + end - class << self - - def message_id(message_id) - self.const_set(:MESSAGE_ID, message_id) - class_eval "def message_id; MESSAGE_ID end" + def message_string(msg) + msg = msg.join if msg.is_a?(Array) + size = (0.to_network_int32.size + msg.size).to_network_int32 + m_id = ''.to_byte #in 1.9 it seems to write out message ids as numbers, handle this here + if (message_id) + m_id = message_id.chr end - + "#{m_id}#{size}#{msg}" end end class BackendMessage < Message MessageIdMap = {} attr_reader :size - class << self - def message_id(message_id) - super - MessageIdMap[message_id.chr] = self + def self.factory(type, stream, size) + #puts "factory reading message #{type} #{size} #{type.class}" + if klass = MessageIdMap[type.chr] #explicitly use the char value, for 1.9 compat + klass.new stream, size + else + Messages::Unknown.new stream, size end + end - def read(stream) - type = stream.read_byte - size = stream.read_network_int32 + def self.message_id(message_id) + super + MessageIdMap[message_id.chr] = self #explicitly use the char value, for 1.9 compat + end - raise Vertica::Error::MessageError.new("Bad message size: #{size}") unless size >= 4 - - message_klass = MessageIdMap[type.chr] - if message_klass.nil? - Messages::Unknown.new(type) - else - message_klass.new(stream, size) - end - end - + def self.read(stream) end def initialize(stream, size) @size = size end - end class FrontendMessage < Message + def to_bytes + message_string '' + end end end end - -require 'vertica/messages/unknown' -require 'vertica/messages/error_response' -require 'vertica/messages/startup' -require 'vertica/messages/authentication' -require 'vertica/messages/password' -require 'vertica/messages/parameter_status' -require 'vertica/messages/backend_key_data' -require 'vertica/messages/ready_for_query' -require 'vertica/messages/terminate' -require 'vertica/messages/notification_response' -require 'vertica/messages/query' -require 'vertica/messages/notice_response' -require 'vertica/messages/row_description' -require 'vertica/messages/command_complete' -require 'vertica/messages/data_row' -require 'vertica/messages/empty_query_response' -require 'vertica/messages/sync' -require 'vertica/messages/ssl_request' -require 'vertica/messages/parse' -require 'vertica/messages/parse_complete' -require 'vertica/messages/bind' -require 'vertica/messages/bind_complete' -require 'vertica/messages/describe' -require 'vertica/messages/flush' -require 'vertica/messages/parameter_description' -require 'vertica/messages/no_data' -require 'vertica/messages/execute' -require 'vertica/messages/close' -require 'vertica/messages/close_complete' -require 'vertica/messages/portal_suspended' -require 'vertica/messages/cancel_request'