Class: Bunny::Framing::IO::Frame

Inherits:
AMQ::Protocol::Frame
  • Object
show all
Defined in:
lib/bunny/framing.rb

Class Method Summary collapse

Class Method Details

.decode(io) ⇒ Object

Raises:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/bunny/framing.rb', line 38

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