Module: PostgresPR::NoticeErrorMixin

Included in:
ErrorResponse, NoticeResponse
Defined in:
lib/postgres-pr/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#field_typeObject

Returns the value of attribute field_type


328
329
330
# File 'lib/postgres-pr/message.rb', line 328

def field_type
  @field_type
end

#field_valuesObject

Returns the value of attribute field_values


328
329
330
# File 'lib/postgres-pr/message.rb', line 328

def field_values
  @field_values
end

Instance Method Details

#dumpObject

Raises:

  • (ArgumentError)

335
336
337
338
339
340
341
342
343
344
345
346
347
# File 'lib/postgres-pr/message.rb', line 335

def dump
  raise ArgumentError if @field_type == 0 and not @field_values.empty?

  sz = 1 
  sz += @field_values.inject(1) {|sum, fld| sum + fld.size + 1} unless @field_type == 0 

  super(sz) do |buffer|
    buffer.write_byte(@field_type)
    break if @field_type == 0 
    @field_values.each {|fld| buffer.write_cstring(fld) }
    buffer.write_byte(0)
  end
end

#initialize(field_type = 0, field_values = []) ⇒ Object

Raises:

  • (ArgumentError)

330
331
332
333
# File 'lib/postgres-pr/message.rb', line 330

def initialize(field_type=0, field_values=[])
  raise ArgumentError if field_type == 0 and not field_values.empty?
  @field_type, @field_values = field_type, field_values
end

#parse(buffer) ⇒ Object


349
350
351
352
353
354
355
356
357
358
359
360
# File 'lib/postgres-pr/message.rb', line 349

def parse(buffer)
  super do
    @field_type = buffer.read_byte
    break if @field_type == 0
    @field_values = []
    while buffer.position < buffer.size-1
      @field_values << buffer.read_cstring
    end
    terminator = buffer.read_byte
    raise ParseError unless terminator == 0
  end
end