Class: FCGI::ValuesRecord

Inherits:
Record
  • Object
show all
Defined in:
lib/cgialt/fcgi/core.rb

Direct Known Subclasses

GetValuesRecord, ParamsRecord

Constant Summary collapse

MASK =
((1<<31) - 1)

Constants inherited from Record

Record::HEADER_FORMAT, Record::HEADER_LENGTH, Record::RECORD_CLASS

Instance Attribute Summary collapse

Attributes inherited from Record

#request_id, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Record

class_for, #management_record?, parse_header, #serialize, #version

Constructor Details

#initialize(type, id, values) ⇒ ValuesRecord



468
469
470
471
# File 'lib/cgialt/fcgi/core.rb', line 468

def initialize(type, id, values)
  super type, id
  @values = values   # Hash
end

Instance Attribute Details

#valuesObject (readonly)

Returns the value of attribute values.



473
474
475
# File 'lib/cgialt/fcgi/core.rb', line 473

def values
  @values
end

Class Method Details

.parse(id, body) ⇒ Object



438
439
440
# File 'lib/cgialt/fcgi/core.rb', line 438

def self::parse(id, body)
  new(id, parse_values(body))
end

.parse_values(buf) ⇒ Object



442
443
444
445
446
447
448
449
450
451
452
453
454
# File 'lib/cgialt/fcgi/core.rb', line 442

def self::parse_values(buf)
  result = {}
  until buf.empty?
    #*name, value = *read_pair(buf)
    #*result[name] = value
    name_len = read_length(buf)
    value_len = read_length(buf)
    name = buf.slice!(0, name_len)
    value = buf.slice!(0, value_len)
    result[name] = value
  end
  result
end

.read_length(buf) ⇒ Object



463
464
465
466
# File 'lib/cgialt/fcgi/core.rb', line 463

def self::read_length(buf)
  buf[0] >> 7 == 0 ? buf.slice!(0,1)[0] \
                   : buf.slice!(0,4).unpack('N')[0] & MASK
end

.read_pair(buf) ⇒ Object



456
457
458
459
460
# File 'lib/cgialt/fcgi/core.rb', line 456

def self::read_pair(buf)
  name_len = read_length(buf)
  value_len = read_length(buf)
  return buf.slice!(0, name_len), buf.slice!(0, value_len)
end