Class: Protocol::WebSocket::Extension::Compression::Deflate

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, level: Zlib::DEFAULT_COMPRESSION, memory_level: Zlib::DEF_MEM_LEVEL, strategy: Zlib::DEFAULT_STRATEGY, window_bits: 15, context_takeover: true, **options) ⇒ Deflate

Returns a new instance of Deflate.



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

def initialize(parent, level: Zlib::DEFAULT_COMPRESSION, memory_level: Zlib::DEF_MEM_LEVEL, strategy: Zlib::DEFAULT_STRATEGY, window_bits: 15, context_takeover: true, **options)
	@parent = parent
	
	@deflate = nil
	
	@level = level
	@memory_level = memory_level
	@strategy = strategy

	# 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.



54
55
56
# File 'lib/protocol/websocket/extension/compression/deflate.rb', line 54

def context_takeover
  @context_takeover
end

#window_bitsObject (readonly)

Returns the value of attribute window_bits.



53
54
55
# File 'lib/protocol/websocket/extension/compression/deflate.rb', line 53

def window_bits
  @window_bits
end

Class Method Details

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

Client writing to server.



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

def self.client(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,
		**options
	)
end

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

Server writing to client.



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

def self.server(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,
		**options
	)
end

Instance Method Details

#pack_binary_frame(buffer, compress: false, **options) ⇒ Object



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

def pack_binary_frame(buffer, compress: false, **options)
	buffer = self.deflate(buffer)
	
	frame = @parent.pack_binary_frame(buffer, **options)
	
	frame.flags |= Frame::RSV1
	
	return frame
end

#pack_text_frame(buffer, compress: true, **options) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/protocol/websocket/extension/compression/deflate.rb', line 56

def pack_text_frame(buffer, compress: true, **options)
	buffer = self.deflate(buffer)
	
	frame = @parent.pack_text_frame(buffer, **options)
	
	frame.flags |= Frame::RSV1
	
	return frame
end

#to_sObject



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

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