Class: Mfp::Proto::HelloResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/mfp/proto/hello_response.rb

Overview

HelloResponse is the payload of a MessageKindHelloResponse frame, sent by the server upon successfully accepting a Hello. It confirms the negotiated capabilities and advertises connection limits.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(capabilities:, max_streams:, max_payload:) ⇒ HelloResponse

Returns a new instance of HelloResponse.



11
12
13
14
15
# File 'lib/mfp/proto/hello_response.rb', line 11

def initialize(capabilities:, max_streams:, max_payload:)
  @capabilities = capabilities
  @max_streams = max_streams
  @max_payload = max_payload
end

Instance Attribute Details

#capabilitiesObject

Returns the value of attribute capabilities.



9
10
11
# File 'lib/mfp/proto/hello_response.rb', line 9

def capabilities
  @capabilities
end

#max_payloadObject

Returns the value of attribute max_payload.



9
10
11
# File 'lib/mfp/proto/hello_response.rb', line 9

def max_payload
  @max_payload
end

#max_streamsObject

Returns the value of attribute max_streams.



9
10
11
# File 'lib/mfp/proto/hello_response.rb', line 9

def max_streams
  @max_streams
end

Class Method Details

.read(fr) ⇒ Object

Raises:



31
32
33
34
35
36
37
38
39
40
# File 'lib/mfp/proto/hello_response.rb', line 31

def self.read(fr)
  raise ParserError.new(ErrorKind::FRAME_SIZE_ERROR) if fr.length != 10

  r = Reader.new(StringIO.new(fr.payload))
  capabilities = r.read_u16
  max_streams = r.read_u32
  max_payload = r.read_u32

  new(capabilities:, max_streams:, max_payload:)
end

Instance Method Details

#encode(stream_id) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mfp/proto/hello_response.rb', line 17

def encode(stream_id)
  buf = Writer.new
  buf.write_u16(@capabilities)
  buf.write_u32(@max_streams)
  buf.write_u32(@max_payload)
  Frame.new(
    stream_id:,
    kind: MessageKind::HELLO_RESPONSE,
    flags: 0,
    length: buf.length,
    payload: buf.string,
  )
end