Class: Mfp::Proto::Ping

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ack:, payload:) ⇒ Ping

Returns a new instance of Ping.



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

def initialize(ack:, payload:)
  @ack = ack
  @payload = payload
end

Instance Attribute Details

#ackObject

Returns the value of attribute ack.



6
7
8
# File 'lib/mfp/proto/ping.rb', line 6

def ack
  @ack
end

#payloadObject

Returns the value of attribute payload.



6
7
8
# File 'lib/mfp/proto/ping.rb', line 6

def payload
  @payload
end

Class Method Details

.read(fr) ⇒ Object



25
26
27
28
29
30
# File 'lib/mfp/proto/ping.rb', line 25

def self.read(fr)
  new(
    ack: fr.flags.allbits?(0x01),
    payload: fr.payload.unpack1("Q>"),
  )
end

Instance Method Details

#encodeObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/mfp/proto/ping.rb', line 13

def encode(*)
  buf = Writer.new
  buf.write_u64(@payload)
  Frame.new(
    stream_id: 0,
    kind: MessageKind::PING,
    flags: @ack ? 0x01 : 0x00,
    length: 8,
    payload: buf.string,
  )
end