Module: Tamashii::RSpec::Helpers
- Defined in:
- lib/tamashii/rspec/helpers.rb
Instance Method Summary collapse
- #tamashii_binary_packet(type, tag, body) ⇒ Object
- #tamashii_packet(type, tag, body) ⇒ Object
- #tamashii_text_packet(type, tag, body) ⇒ Object
- #websocket_mask ⇒ Object
- #websocket_mask_message(mask, *bytes) ⇒ Object
Instance Method Details
#tamashii_binary_packet(type, tag, body) ⇒ Object
22 23 24 25 26 |
# File 'lib/tamashii/rspec/helpers.rb', line 22 def tamashii_binary_packet(type, tag, body) mask = websocket_mask packet = tamashii_packet(type, tag, body) [0x82, 0x80 + packet.size] + mask + (mask, *packet) end |
#tamashii_packet(type, tag, body) ⇒ Object
18 19 20 |
# File 'lib/tamashii/rspec/helpers.rb', line 18 def tamashii_packet(type, tag, body) Tamashii::Packet.new(type, tag, body).dump end |
#tamashii_text_packet(type, tag, body) ⇒ Object
28 29 30 31 32 |
# File 'lib/tamashii/rspec/helpers.rb', line 28 def tamashii_text_packet(type, tag, body) mask = websocket_mask packet = tamashii_packet(type, tag, body) [0x81, 0x80 + packet.size] + mask + (mask, *packet) end |
#websocket_mask ⇒ Object
6 7 8 |
# File 'lib/tamashii/rspec/helpers.rb', line 6 def websocket_mask (1..4).map { rand 255 } end |
#websocket_mask_message(mask, *bytes) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/tamashii/rspec/helpers.rb', line 10 def (mask, *bytes) output = [] bytes.each_with_index do |byte, i| output[i] = byte ^ mask[i % 4] end output end |