Class: GorgonBunny::Framing::String::Frame

Inherits:
GorgonAMQ::Protocol::Frame show all
Defined in:
lib/gorgon_bunny/lib/gorgon_bunny/framing.rb

Constant Summary

Constants inherited from GorgonAMQ::Protocol::Frame

GorgonAMQ::Protocol::Frame::CHANNEL_RANGE, GorgonAMQ::Protocol::Frame::CLASSES, GorgonAMQ::Protocol::Frame::FINAL_OCTET, GorgonAMQ::Protocol::Frame::TYPES, GorgonAMQ::Protocol::Frame::TYPES_OPTIONS, GorgonAMQ::Protocol::Frame::TYPES_REVERSE

Class Method Summary collapse

Methods inherited from GorgonAMQ::Protocol::Frame

#__new__, decode_header, encode, encode_to_array, encoded_payload, #final?, find_type, new

Class Method Details

.decode(string) ⇒ Object

Raises:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gorgon_bunny/lib/gorgon_bunny/framing.rb', line 12

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(GorgonAMQ::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 != GorgonAMQ::Protocol::Frame::FINAL_OCTET

  self.new(type, payload, channel)
end