Class: PostgresPR::Message

### Home Classes Methods

### In Files

- lib/postgres-pr/message.rb

### Parent

Object

### Methods

- ::create
- ::dump
- ::fields
- ::read
- ::register_message_type
- #dump
- #parse

### Class/Module Index

Quicksearch

- PostgresPR
- PostgresPR::Authentification
- PostgresPR::AuthentificationClearTextPassword
- PostgresPR::AuthentificationCryptPassword
- PostgresPR::AuthentificationKerberosV4
- PostgresPR::AuthentificationKerberosV5
- PostgresPR::AuthentificationMD5Password
- PostgresPR::AuthentificationOk
- PostgresPR::AuthentificationSCMCredential
- PostgresPR::BackendKeyData
- PostgresPR::CommandComplete
- PostgresPR::Connection
- PostgresPR::Connection::Result
- PostgresPR::CopyInResponse
- PostgresPR::CopyOutResponse
- PostgresPR::DataRow
- PostgresPR::DumpError
- PostgresPR::EmptyQueryResponse
- PostgresPR::ErrorResponse
- PostgresPR::Message
- PostgresPR::NoticeErrorMixin
- PostgresPR::NoticeResponse
- PostgresPR::ParameterStatus
- PostgresPR::Parse
- PostgresPR::ParseComplete
- PostgresPR::ParseError
- PostgresPR::PasswordMessage
- PostgresPR::Query
- PostgresPR::ReadyForQuery
- PostgresPR::RowDescription
- PostgresPR::RowDescription::FieldInfo
- PostgresPR::SSLRequest
- PostgresPR::SaltedAuthentificationMixin
- PostgresPR::StartupMessage
- PostgresPR::Terminate
- PostgresPR::UnknownAuthType
- PostgresPR::UnknownMessageType
- Buffer
- Buffer::EOF
- Buffer::Error
- Postgres
- Postgres::Conversion
- Postgres::Conversion::ConversionError
- BinaryReaderMixin
- BinaryWriterMixin
- ByteOrder
- DatabaseError
- Error
- IO
- PGError
- PGconn
- PGresult
- TC_Conversion

No matching classes.

# PostgresPR::Message

Base class representing a PostgreSQL protocol message

### Constants

MsgTypeMap

  One character message-typecode to class map

### Public Class Methods

create(buffer) click to toggle source

    # File lib/postgres-pr/message.rb, line 61
    def self.create(buffer)
      obj = allocate
      obj.parse(buffer)
      obj
    end

dump(*args) click to toggle source

    # File lib/postgres-pr/message.rb, line 67
    def self.dump(*args)
      new(*args).dump
    end

fields(*attribs) click to toggle source

    # File lib/postgres-pr/message.rb, line 86
    def self.fields(*attribs)
      names = attribs.map {|name, type| name.to_s}
      arg_list = names.join(", ")
      ivar_list = names.map {|name| "@" + name }.join(", ")
      sym_list = names.map {|name| ":" + name }.join(", ")
      class_eval %[
        attr_accessor #{ sym_list }
        def initialize(#{ arg_list })
          #{ ivar_list } = #{ arg_list }
        end
      ]
    end

read(stream, startup=false) click to toggle source

    # File lib/postgres-pr/message.rb, line 46
    def self.read(stream, startup=false)
      type = stream.read_exactly_n_bytes(1) unless startup
      length = stream.read_exactly_n_bytes(4).unpack('N').first  # FIXME: length should be signed, not unsigned

      raise ParseError unless length >= 4

      # initialize buffer
      buffer = Buffer.of_size(startup ? length : 1+length)
      buffer.write(type) unless startup
      buffer.write_int32_network(length)
      buffer.copy_from_stream(stream, length-4)

      (startup ? StartupMessage : MsgTypeMap[type]).create(buffer)
    end

register_message_type(type) click to toggle source

    # File lib/postgres-pr/message.rb, line 37
    def self.register_message_type(type)
      raise "duplicate message type registration" if MsgTypeMap.has_key?(type)

      MsgTypeMap[type] = self

      self.const_set(:MsgType, type)
      class_eval "def message_type; MsgType end"
    end

### Public Instance Methods

dump(body_size=0) click to toggle source

    # File lib/postgres-pr/message.rb, line 71
    def dump(body_size=0)
      buffer = Buffer.of_size(5 +  body_size)
      buffer.write(self.message_type)
      buffer.write_int32_network(4 + body_size)
      yield buffer if block_given?
      raise DumpError  unless buffer.at_end?
      return buffer.content
    end

parse(buffer) click to toggle source

    # File lib/postgres-pr/message.rb, line 80
    def parse(buffer)
      buffer.position = 5
      yield buffer if block_given?
      raise ParseError, buffer.inspect unless buffer.at_end?
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.