Class: Protocol::WebSocket::TextFrame

Inherits:
Frame
  • Object
show all
Defined in:
lib/protocol/websocket/text_frame.rb

Overview

Implements the text frame for sending and receiving text.

Constant Summary collapse

OPCODE =
0x1

Constants inherited from Frame

Frame::RESERVED, Frame::RSV1, Frame::RSV2, Frame::RSV3

Instance Attribute Summary

Attributes inherited from Frame

#finished, #flags, #length, #mask, #opcode, #payload

Instance Method Summary collapse

Methods inherited from Frame

#<=>, #continued?, #control?, #finished?, #initialize, #pack, parse_header, read, #to_ary, #unpack, #write

Constructor Details

This class inherits a constructor from Protocol::WebSocket::Frame

Instance Method Details

#apply(connection) ⇒ Object

Apply this frame to the specified connection.



33
34
35
# File 'lib/protocol/websocket/text_frame.rb', line 33

def apply(connection)
	connection.receive_text(self)
end

#data?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/protocol/websocket/text_frame.rb', line 16

def data?
	true
end

#read_message(buffer) ⇒ Object

Decode the binary buffer into a suitable text message.



22
23
24
25
26
27
28
29
30
# File 'lib/protocol/websocket/text_frame.rb', line 22

def read_message(buffer)
	buffer.force_encoding(Encoding::UTF_8)
	
	unless buffer.valid_encoding?
		raise ProtocolError, "invalid UTF-8 in text frame!"
	end
	
	return TextMessage.new(buffer)
end