Class: Protocol::WebSocket::Extension::Compression::Inflate

Inherits:
Object
  • Object
show all
Defined in:
lib/protocol/websocket/extension/compression/inflate.rb

Constant Summary collapse

TRAILER =
[0x00, 0x00, 0xff, 0xff].pack("C*")

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, context_takeover: true, window_bits: 15) ⇒ Inflate

Returns a new instance of Inflate.



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/protocol/websocket/extension/compression/inflate.rb', line 31

def initialize(parent, context_takeover: true, window_bits: 15)
  @parent = parent
  
  @inflate = nil
  
  # This is handled during negotiation:
  # if window_bits < MINIMUM_WINDOW_BITS
  #  window_bits = MINIMUM_WINDOW_BITS
  # end
  
  @window_bits = window_bits
  @context_takeover = context_takeover
end

Instance Attribute Details

#context_takeoverObject (readonly)

Returns the value of attribute context_takeover.



50
51
52
# File 'lib/protocol/websocket/extension/compression/inflate.rb', line 50

def context_takeover
  @context_takeover
end

#window_bitsObject (readonly)

Returns the value of attribute window_bits.



49
50
51
# File 'lib/protocol/websocket/extension/compression/inflate.rb', line 49

def window_bits
  @window_bits
end

Class Method Details

.client(parent, server_max_window_bits: 15, server_no_context_takeover: false, **options) ⇒ Object

Client reading from server.



14
15
16
17
18
19
# File 'lib/protocol/websocket/extension/compression/inflate.rb', line 14

def self.client(parent, server_max_window_bits: 15, server_no_context_takeover: false, **options)
  self.new(parent,
    window_bits: server_max_window_bits,
    context_takeover: !server_no_context_takeover,
  )
end

.server(parent, client_max_window_bits: 15, client_no_context_takeover: false, **options) ⇒ Object

Server reading from client.



22
23
24
25
26
27
# File 'lib/protocol/websocket/extension/compression/inflate.rb', line 22

def self.server(parent, client_max_window_bits: 15, client_no_context_takeover: false, **options)
  self.new(parent,
    window_bits: client_max_window_bits,
    context_takeover: !client_no_context_takeover,
  )
end

Instance Method Details

#to_sObject



45
46
47
# File 'lib/protocol/websocket/extension/compression/inflate.rb', line 45

def to_s
  "#<#{self.class} window_bits=#{@window_bits} context_takeover=#{@context_takeover}>"
end

#unpack_frames(frames, **options) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/protocol/websocket/extension/compression/inflate.rb', line 52

def unpack_frames(frames, **options)
  buffer = @parent.unpack_frames(frames, **options)
  
  frame = frames.first
  
  if frame.flag?(Frame::RSV1)
    buffer = self.inflate(buffer)
    frame.flags &= ~Frame::RSV1
  end
  
  return buffer
end