Class: Mfp::Proto::Frame
- Inherits:
-
Object
- Object
- Mfp::Proto::Frame
- Defined in:
- lib/mfp/proto/frame.rb
Overview
Frame is the fundamental unit of the MFP wire protocol. Every message exchanged between endpoints is wrapped in a Frame.
Instance Attribute Summary collapse
-
#call_sign ⇒ Object
Returns the value of attribute call_sign.
-
#flags ⇒ Object
Returns the value of attribute flags.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#length ⇒ Object
Returns the value of attribute length.
-
#payload ⇒ Object
Returns the value of attribute payload.
-
#stream_id ⇒ Object
Returns the value of attribute stream_id.
Class Method Summary collapse
Instance Method Summary collapse
- #encode ⇒ Object
-
#initialize(stream_id:, kind:, flags:, length:, payload:, call_sign: "") ⇒ Frame
constructor
A new instance of Frame.
Constructor Details
#initialize(stream_id:, kind:, flags:, length:, payload:, call_sign: "") ⇒ Frame
Returns a new instance of Frame.
10 11 12 13 14 15 16 17 |
# File 'lib/mfp/proto/frame.rb', line 10 def initialize(stream_id:, kind:, flags:, length:, payload:, call_sign: "") @call_sign = call_sign @stream_id = stream_id @kind = kind @flags = flags @length = length @payload = payload end |
Instance Attribute Details
#call_sign ⇒ Object
Returns the value of attribute call_sign.
8 9 10 |
# File 'lib/mfp/proto/frame.rb', line 8 def call_sign @call_sign end |
#flags ⇒ Object
Returns the value of attribute flags.
8 9 10 |
# File 'lib/mfp/proto/frame.rb', line 8 def flags @flags end |
#kind ⇒ Object
Returns the value of attribute kind.
8 9 10 |
# File 'lib/mfp/proto/frame.rb', line 8 def kind @kind end |
#length ⇒ Object
Returns the value of attribute length.
8 9 10 |
# File 'lib/mfp/proto/frame.rb', line 8 def length @length end |
#payload ⇒ Object
Returns the value of attribute payload.
8 9 10 |
# File 'lib/mfp/proto/frame.rb', line 8 def payload @payload end |
#stream_id ⇒ Object
Returns the value of attribute stream_id.
8 9 10 |
# File 'lib/mfp/proto/frame.rb', line 8 def stream_id @stream_id end |
Class Method Details
.read(io, max_len, call_sign) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/mfp/proto/frame.rb', line 30 def self.read(io, max_len, call_sign) r = Reader.new(io) cs = r.read_n(4) if cs.nil? # This is a clean disconnect before reading the callsign. # Raise ConnectionClosedError instead of an spurious # InvalidCallSignError raise ConnectionClosedError end raise InvalidCallSignError, cs.inspect if cs != call_sign stream_id = r.read_u32 kind = r.read_byte kind = MessageKind::UNKNOWN if kind > MessageKind.max flags = r.read_byte length = r.read_u32 raise PayloadTooLargeError if max_len.positive? && length > max_len payload = length.positive? ? r.read_n(length) : "" new(call_sign:, stream_id:, kind:, flags:, length:, payload:) end |