Class: GQTP::Header
- Inherits:
-
Object
- Object
- GQTP::Header
- Defined in:
- lib/gqtp/header.rb
Defined Under Namespace
Modules: ContentType, Flag, Protocol, Status
Instance Attribute Summary collapse
-
#cas ⇒ Object
Returns the value of attribute cas.
-
#flags ⇒ Object
Returns the value of attribute flags.
-
#key_length ⇒ Object
Returns the value of attribute key_length.
-
#level ⇒ Object
Returns the value of attribute level.
-
#opaque ⇒ Object
Returns the value of attribute opaque.
-
#proto ⇒ Object
Returns the value of attribute proto.
-
#query_type ⇒ Object
Returns the value of attribute query_type.
-
#size ⇒ Object
Returns the value of attribute size.
-
#status ⇒ Object
Returns the value of attribute status.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(values = {}) {|_self| ... } ⇒ Header
constructor
A new instance of Header.
- #pack ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(values = {}) {|_self| ... } ⇒ Header
Returns a new instance of Header.
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
#cas ⇒ Object
Returns the value of attribute cas.
54 55 56 |
# File 'lib/gqtp/header.rb', line 54 def cas @cas end |
#flags ⇒ Object
Returns the value of attribute flags.
53 54 55 |
# File 'lib/gqtp/header.rb', line 53 def flags @flags end |
#key_length ⇒ Object
Returns the value of attribute key_length.
53 54 55 |
# File 'lib/gqtp/header.rb', line 53 def key_length @key_length end |
#level ⇒ Object
Returns the value of attribute level.
53 54 55 |
# File 'lib/gqtp/header.rb', line 53 def level @level end |
#opaque ⇒ Object
Returns the value of attribute opaque.
54 55 56 |
# File 'lib/gqtp/header.rb', line 54 def opaque @opaque end |
#proto ⇒ Object
Returns the value of attribute proto.
53 54 55 |
# File 'lib/gqtp/header.rb', line 53 def proto @proto end |
#query_type ⇒ Object
Returns the value of attribute query_type.
53 54 55 |
# File 'lib/gqtp/header.rb', line 53 def query_type @query_type end |
#size ⇒ Object
Returns the value of attribute size.
54 55 56 |
# File 'lib/gqtp/header.rb', line 54 def size @size end |
#status ⇒ Object
Returns the value of attribute status.
54 55 56 |
# File 'lib/gqtp/header.rb', line 54 def status @status end |
Class Method Details
.pack_format ⇒ Object
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 |
.size ⇒ Object
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 |
#pack ⇒ Object
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_hash ⇒ Object
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 |