File: response_header.rb

package info (click to toggle)
ruby-dalli 3.2.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 684 kB
  • sloc: ruby: 6,552; sh: 20; makefile: 4
file content (36 lines) | stat: -rw-r--r-- 847 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# frozen_string_literal: true

module Dalli
  module Protocol
    class Binary
      ##
      # Class that encapsulates data parsed from a memcached response header.
      ##
      class ResponseHeader
        SIZE = 24
        FMT = '@2nCCnNNQ'

        attr_reader :key_len, :extra_len, :data_type, :status, :body_len, :opaque, :cas

        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

        def ok?
          status.zero?
        end

        def not_found?
          status == 1
        end

        NOT_STORED_STATUSES = [2, 5].freeze
        def not_stored?
          NOT_STORED_STATUSES.include?(status)
        end
      end
    end
  end
end