Class: PostgresPR::StartupMessage

Inherits:
Message
  • Object
show all
Defined in:
lib/postgres-pr/message.rb

Constant Summary collapse

PROTO_VERSION =

196608

3 << 16

Constants inherited from Message

Message::MsgTypeMap

Instance Method Summary collapse

Methods inherited from Message

create, dump, #parse, read, register_message_type

Constructor Details

#initialize(params) ⇒ StartupMessage

Returns a new instance of StartupMessage.



282
283
284
# File 'lib/postgres-pr/message.rb', line 282

def initialize(params)
  @params = params
end

Instance Method Details

#dumpObject



286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/postgres-pr/message.rb', line 286

def dump
  params = @params.reject{|k,v| v.nil?}
  sz = params.inject(4 + 4) {|sum, kv| sum + kv[0].size + 1 + kv[1].size + 1} + 1

  buffer = Buffer.of_size(sz)
  buffer.write_int32(sz)
  buffer.write_int32(PROTO_VERSION)
  params.each_pair do |key, value| 
    buffer.write_cstring(key)
    buffer.write_cstring(value)
  end
  buffer.write_byte(0)
  buffer.content
end