Sha256: 49ba1bbea12c9df3ccbb9a944ee617fb85df824753a5967fddf5a47eb5dbe73c

Contents?: true

Size: 1.75 KB

Versions: 126

Compression:

Stored size: 1.75 KB

Contents

module Bunny
  # @private
  module Framing
    ENCODINGS_SUPPORTED = defined? Encoding
    HEADER_SLICE = (0..6).freeze
    DATA_SLICE = (7..-1).freeze
    PAYLOAD_SLICE = (0..-2).freeze

    # @private
    module String
      class Frame < AMQ::Protocol::Frame
        def self.decode(string)
          header              = string[HEADER_SLICE]
          type, channel, size = self.decode_header(header)
          data                = string[DATA_SLICE]
          payload             = data[PAYLOAD_SLICE]
          frame_end           = data[-1, 1]

          frame_end.force_encoding(AMQ::Protocol::Frame::FINAL_OCTET.encoding) if ENCODINGS_SUPPORTED

          # 1) the size is miscalculated
          if payload.bytesize != size
            raise BadLengthError.new(size, payload.bytesize)
          end

          # 2) the size is OK, but the string doesn't end with FINAL_OCTET
          raise NoFinalOctetError.new if frame_end != AMQ::Protocol::Frame::FINAL_OCTET

          self.new(type, payload, channel)
        end
      end
    end # String


    # @private
    module IO
      class Frame < AMQ::Protocol::Frame
        def self.decode(io)
          header = io.read(7)
          type, channel, size = self.decode_header(header)
          data = io.read_fully(size + 1)
          payload, frame_end = data[PAYLOAD_SLICE], data[-1, 1]

          # 1) the size is miscalculated
          if payload.bytesize != size
            raise BadLengthError.new(size, payload.bytesize)
          end

          # 2) the size is OK, but the string doesn't end with FINAL_OCTET
          raise NoFinalOctetError.new if frame_end != AMQ::Protocol::Frame::FINAL_OCTET
          self.new(type, payload, channel)
        end # self.from
      end # Frame
    end # IO
  end # Framing
end # Bunny

Version data entries

126 entries across 126 versions & 2 rubygems

Version Path
bunny-1.6.1 lib/bunny/framing.rb
bunny-1.6.0 lib/bunny/framing.rb
bunny-1.5.1 lib/bunny/framing.rb
bunny-1.6.0.rc2 lib/bunny/framing.rb
bunny-1.6.0.rc1 lib/bunny/framing.rb
bunny-1.6.0.pre1 lib/bunny/framing.rb
bunny-1.5.0 lib/bunny/framing.rb
bunny-1.5.0.pre2 lib/bunny/framing.rb
bunny-1.5.0.pre1 lib/bunny/framing.rb
bunny-1.4.1 lib/bunny/framing.rb
bunny-1.4.0 lib/bunny/framing.rb
bunny-1.3.1 lib/bunny/framing.rb
bunny-1.3.0 lib/bunny/framing.rb
bunny-1.2.2 lib/bunny/framing.rb
bunny-1.2.1 lib/bunny/framing.rb
bunny-1.2.0 lib/bunny/framing.rb
bunny-1.1.9 lib/bunny/framing.rb
bunny-1.1.8 lib/bunny/framing.rb
bunny-1.1.7 lib/bunny/framing.rb
bunny-1.1.6 lib/bunny/framing.rb