Sha256: 8f61995117b181481c279f23ac52b526d11fea6d0270ece577365d17ac0b866c

Contents?: true

Size: 847 Bytes

Versions: 16

Compression:

Stored size: 847 Bytes

Contents

# 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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
dalli-3.2.8 lib/dalli/protocol/binary/response_header.rb
dalli-3.2.7 lib/dalli/protocol/binary/response_header.rb
dalli-3.2.6 lib/dalli/protocol/binary/response_header.rb
dalli-3.2.5 lib/dalli/protocol/binary/response_header.rb
dalli-3.2.4 lib/dalli/protocol/binary/response_header.rb
dalli-3.2.3 lib/dalli/protocol/binary/response_header.rb
dalli-3.2.2 lib/dalli/protocol/binary/response_header.rb
dalli-3.2.1 lib/dalli/protocol/binary/response_header.rb
dalli-3.2.0 lib/dalli/protocol/binary/response_header.rb
dalli-3.1.6 lib/dalli/protocol/binary/response_header.rb
dalli-3.1.5 lib/dalli/protocol/binary/response_header.rb
dalli-3.1.4 lib/dalli/protocol/binary/response_header.rb
dalli-3.1.3 lib/dalli/protocol/binary/response_header.rb
dalli-3.1.2 lib/dalli/protocol/binary/response_header.rb
dalli-3.1.1 lib/dalli/protocol/binary/response_header.rb
dalli-3.1.0 lib/dalli/protocol/binary/response_header.rb