Class: PostgresPR::RowDescription

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

Defined Under Namespace

Classes: FieldInfo

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


441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
# File 'lib/postgres-pr/message.rb', line 441

def dump
  sz = @fields.inject(2) {|sum, fld| sum + 18 + fld.name.size + 1 }
  super(sz) do |buffer|
    buffer.write_int16_network(@fields.size)
    @fields.each { |f|
      buffer.write_cstring(f.name)
      buffer.write_int32_network(f.oid)
      buffer.write_int16_network(f.attr_nr)
      buffer.write_int32_network(f.type_oid)
      buffer.write_int16_network(f.typlen)
      buffer.write_int32_network(f.atttypmod)
      buffer.write_int16_network(f.formatcode)
    }
  end
end

#parse(buffer) ⇒ Object


457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
# File 'lib/postgres-pr/message.rb', line 457

def parse(buffer)
  super do
    n_fields = buffer.read_int16_network
    @fields = (1..n_fields).collect {
      f = FieldInfo.new
      f.name       = buffer.read_cstring
      f.oid        = buffer.read_int32_network
      f.attr_nr    = buffer.read_int16_network
      f.type_oid   = buffer.read_int32_network
      f.typlen     = buffer.read_int16_network
      f.atttypmod  = buffer.read_int32_network
      f.formatcode = buffer.read_int16_network
      f
    }
  end
end