Class: Dalli::Protocol::Binary::ResponseHeader
- Inherits:
-
Object
- Object
- Dalli::Protocol::Binary::ResponseHeader
- Defined in:
- lib/dalli/protocol/binary/response_header.rb
Overview
Class that encapsulates data parsed from a memcached response header.
Constant Summary collapse
- SIZE =
24
- FMT =
'@2nCCnNNQ'
- NOT_STORED_STATUSES =
[2, 5].freeze
Instance Attribute Summary collapse
-
#body_len ⇒ Object
readonly
Returns the value of attribute body_len.
-
#cas ⇒ Object
readonly
Returns the value of attribute cas.
-
#data_type ⇒ Object
readonly
Returns the value of attribute data_type.
-
#extra_len ⇒ Object
readonly
Returns the value of attribute extra_len.
-
#key_len ⇒ Object
readonly
Returns the value of attribute key_len.
-
#opaque ⇒ Object
readonly
Returns the value of attribute opaque.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(buf) ⇒ ResponseHeader
constructor
A new instance of ResponseHeader.
- #not_found? ⇒ Boolean
- #not_stored? ⇒ Boolean
- #ok? ⇒ Boolean
Constructor Details
#initialize(buf) ⇒ ResponseHeader
Returns a new instance of ResponseHeader.
15 16 17 18 19 |
# File 'lib/dalli/protocol/binary/response_header.rb', line 15 def initialize(buf) raise ArgumentError, "Response buffer must be at least #{SIZE} bytes" unless buf.bytesize >= SIZE @key_len, @extra_len, @data_type, @status, @body_len, @opaque, @cas = buf.unpack(FMT) end |
Instance Attribute Details
#body_len ⇒ Object (readonly)
Returns the value of attribute body_len.
13 14 15 |
# File 'lib/dalli/protocol/binary/response_header.rb', line 13 def body_len @body_len end |
#cas ⇒ Object (readonly)
Returns the value of attribute cas.
13 14 15 |
# File 'lib/dalli/protocol/binary/response_header.rb', line 13 def cas @cas end |
#data_type ⇒ Object (readonly)
Returns the value of attribute data_type.
13 14 15 |
# File 'lib/dalli/protocol/binary/response_header.rb', line 13 def data_type @data_type end |
#extra_len ⇒ Object (readonly)
Returns the value of attribute extra_len.
13 14 15 |
# File 'lib/dalli/protocol/binary/response_header.rb', line 13 def extra_len @extra_len end |
#key_len ⇒ Object (readonly)
Returns the value of attribute key_len.
13 14 15 |
# File 'lib/dalli/protocol/binary/response_header.rb', line 13 def key_len @key_len end |
#opaque ⇒ Object (readonly)
Returns the value of attribute opaque.
13 14 15 |
# File 'lib/dalli/protocol/binary/response_header.rb', line 13 def opaque @opaque end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
13 14 15 |
# File 'lib/dalli/protocol/binary/response_header.rb', line 13 def status @status end |
Instance Method Details
#not_found? ⇒ Boolean
25 26 27 |
# File 'lib/dalli/protocol/binary/response_header.rb', line 25 def not_found? status == 1 end |
#not_stored? ⇒ Boolean
30 31 32 |
# File 'lib/dalli/protocol/binary/response_header.rb', line 30 def not_stored? NOT_STORED_STATUSES.include?(status) end |
#ok? ⇒ Boolean
21 22 23 |
# File 'lib/dalli/protocol/binary/response_header.rb', line 21 def ok? status.zero? end |