Class: Stenohttp2::Common::Message

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/stenohttp2/common/message.rb

Constant Summary collapse

SLICE_SIZE =

Messages are split into chunks of length 8

8

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, protocol = Stenohttp2::Common::Protocol) ⇒ Message

Returns a new instance of Message.



13
14
15
# File 'lib/stenohttp2/common/message.rb', line 13

def initialize(content, protocol = Stenohttp2::Common::Protocol)
  @encoded = protocol.new.encode(content)
end

Instance Attribute Details

#encodedObject (readonly)

Returns the value of attribute encoded.



27
28
29
# File 'lib/stenohttp2/common/message.rb', line 27

def encoded
  @encoded
end

Instance Method Details

#compress(text) ⇒ Object



23
24
25
# File 'lib/stenohttp2/common/message.rb', line 23

def compress(text)
  text.chars.each_slice(SLICE_SIZE).to_a.map(&:join).map { |r| r.ljust(SLICE_SIZE) }
end

#partsObject



18
19
20
# File 'lib/stenohttp2/common/message.rb', line 18

def parts
  compress(encoded)
end