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

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

Overview

Decompresses incoming WebSocket frames using the DEFLATE algorithm.

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

Initialize a new inflate decompressor.



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/protocol/websocket/extension/compression/inflate.rb', line 36

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.



58
59
60
# File 'lib/protocol/websocket/extension/compression/inflate.rb', line 58

def context_takeover
  @context_takeover
end

#The window size in bits used for decompression.(windowsize) ⇒ Object (readonly)



56
# File 'lib/protocol/websocket/extension/compression/inflate.rb', line 56

attr :window_bits

#window_bitsObject (readonly)

Returns the value of attribute window_bits.



56
57
58
# File 'lib/protocol/websocket/extension/compression/inflate.rb', line 56

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.



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

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.



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

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



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

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

#unpack_frames(frames, **options) ⇒ Object

Unpack and decompress frames into a buffer.



63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/protocol/websocket/extension/compression/inflate.rb', line 63

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

#Whether the decompression context is reused across messages.=(thedecompressioncontextisreusedacrossmessages. = (value)) ⇒ Object



58
# File 'lib/protocol/websocket/extension/compression/inflate.rb', line 58

attr :context_takeover