Class: GQTP::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/gqtp/header.rb

Defined Under Namespace

Modules: ContentType, Flag, Protocol, Status

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values = {}) {|_self| ... } ⇒ Header

Returns a new instance of Header.

Yields:

  • (_self)

Yield Parameters:

  • _self (GQTP::Header)

    the object that the method was called on



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/gqtp/header.rb', line 55

def initialize(values={})
  @proto      = values[:proto]      || Protocol::GQTP
  @query_type = values[:query_type] || ContentType::NONE
  @key_length = values[:key_length] || 0
  @level      = values[:level]      || 0
  @flags      = values[:flags]      || 0
  @status     = values[:status]     || Status::SUCCESS
  @size       = values[:size]       || 0
  @opaque     = values[:opaque]     || 0
  @cas        = values[:cas]        || 0
  yield(self) if block_given?
end

Instance Attribute Details

#casObject

Returns the value of attribute cas.



54
55
56
# File 'lib/gqtp/header.rb', line 54

def cas
  @cas
end

#flagsObject

Returns the value of attribute flags.



53
54
55
# File 'lib/gqtp/header.rb', line 53

def flags
  @flags
end

#key_lengthObject

Returns the value of attribute key_length.



53
54
55
# File 'lib/gqtp/header.rb', line 53

def key_length
  @key_length
end

#levelObject

Returns the value of attribute level.



53
54
55
# File 'lib/gqtp/header.rb', line 53

def level
  @level
end

#opaqueObject

Returns the value of attribute opaque.



54
55
56
# File 'lib/gqtp/header.rb', line 54

def opaque
  @opaque
end

#protoObject

Returns the value of attribute proto.



53
54
55
# File 'lib/gqtp/header.rb', line 53

def proto
  @proto
end

#query_typeObject

Returns the value of attribute query_type.



53
54
55
# File 'lib/gqtp/header.rb', line 53

def query_type
  @query_type
end

#sizeObject

Returns the value of attribute size.



54
55
56
# File 'lib/gqtp/header.rb', line 54

def size
  @size
end

#statusObject

Returns the value of attribute status.



54
55
56
# File 'lib/gqtp/header.rb', line 54

def status
  @status
end

Class Method Details

.pack_formatObject



48
49
50
# File 'lib/gqtp/header.rb', line 48

def pack_format
  "CCnCCnNNNN"
end

.parse(chunk) ⇒ Object



34
35
36
37
38
39
40
41
42
# File 'lib/gqtp/header.rb', line 34

def parse(chunk)
  return nil if chunk.bytesize < size
  header = new
  header.proto, header.query_type, header.key_length,
    header.level, header.flags, header.status, header.size,
    header.opaque, cas_high, cas_low = chunk.unpack(pack_format)
  header.cas = cas_high << 32 + cas_low
  header
end

.sizeObject



44
45
46
# File 'lib/gqtp/header.rb', line 44

def size
  24
end

Instance Method Details

#==(other) ⇒ Object



76
77
78
# File 'lib/gqtp/header.rb', line 76

def ==(other)
  other.is_a?(self.class) and to_hash == other.to_hash
end

#packObject



68
69
70
71
72
73
74
# File 'lib/gqtp/header.rb', line 68

def pack
  data = [
    @proto, @query_type, @key_length, @level,
    @flags, @status, @size, @opaque, @cas >> 32, @cas & (2 ** 32),
  ]
  data.pack(self.class.pack_format)
end

#to_hashObject



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/gqtp/header.rb', line 80

def to_hash
  {
    :proto      => @proto,
    :query_type => @query_type,
    :key_length => @key_length,
    :level      => @level,
    :flags      => @flags,
    :status     => @status,
    :size       => @size,
    :opaque     => @opaque,
    :cas        => @cas,
  }
end