Class: PostgresPR::StartupMessage

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

Constant Summary

Constants inherited from Message

Message::MsgTypeMap

Instance Method Summary collapse

Methods inherited from Message

create, dump, fields, read, register_message_type

Instance Method Details

#dumpObject

Raises:


478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
# File 'lib/postgres-pr/message.rb', line 478

def dump
  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_network(sz)
  buffer.write_int32_network(@proto_version)
  @params.each_pair {|key, value| 
    buffer.write_cstring(key)
    buffer.write_cstring(value)
  }
  buffer.write_byte(0)

  raise DumpError unless buffer.at_end?
  return buffer.content
end

#parse(buffer) ⇒ Object

Raises:


494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
# File 'lib/postgres-pr/message.rb', line 494

def parse(buffer)
  buffer.position = 4

  @proto_version = buffer.read_int32_network
  @params = {}

  while buffer.position < buffer.size-1
    key = buffer.read_cstring
    val = buffer.read_cstring
    @params[key] = val
  end

  nul = buffer.read_byte
  raise ParseError unless nul == 0
  raise ParseError unless buffer.at_end?
end