Class: Rakie::WebsocketBasicMessage

Inherits:
Object
  • Object
show all
Includes:
Proto
Defined in:
lib/rakie/websocket_proto.rb

Direct Known Subclasses

WebsocketMessage

Constant Summary collapse

FLAG_FIN =
1 << 7
OP_CONTINUE =
0x0
OP_TEXT =
0x1
OP_BIN =
0x2
OP_CLOSE =
0x8
OP_PING =
0x9
OP_PONG =
0xA
FLAG_MASK =
1 << 7
PARSE_OPERATION =
PARSE_BEGIN
PARSE_LEN =
1
PARSE_EXT_LEN =
2
PARSE_MASKING =
3
PARSE_PAYLOAD =
4

Constants included from Proto

Proto::PARSE_BEGIN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Proto

#parse, #parse_offset, #parse_offset=, #parse_state, #parse_state=, #parse_status, #to_s

Constructor Details

#initializeWebsocketBasicMessage

Returns a new instance of WebsocketBasicMessage.



25
26
27
28
29
30
31
32
33
# File 'lib/rakie/websocket_proto.rb', line 25

def initialize
  @fin = false
  @op_code = 0x0
  @mask = false
  @masking = []
  @length = 0
  @long_ext = false
  @payload = ''
end

Instance Attribute Details

#fin=(value) ⇒ Object (writeonly)

Sets the attribute fin

Parameters:

  • value

    the value to set the attribute fin to.



23
24
25
# File 'lib/rakie/websocket_proto.rb', line 23

def fin=(value)
  @fin = value
end

#lengthObject

Returns the value of attribute length.



22
23
24
# File 'lib/rakie/websocket_proto.rb', line 22

def length
  @length
end

#maskObject

Returns the value of attribute mask.



22
23
24
# File 'lib/rakie/websocket_proto.rb', line 22

def mask
  @mask
end

#op_codeObject

Returns the value of attribute op_code.



22
23
24
# File 'lib/rakie/websocket_proto.rb', line 22

def op_code
  @op_code
end

#payloadObject

Returns the value of attribute payload.



22
23
24
# File 'lib/rakie/websocket_proto.rb', line 22

def payload
  @payload
end

Instance Method Details

#deserialize(source) ⇒ Object

Parameters:

  • source (String)


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rakie/websocket_proto.rb', line 40

def deserialize(source)
  current_state = parse_state

  case current_state
  when PARSE_OPERATION
    return parse_source_operation(source)

  when PARSE_LEN
    return parse_source_len(source)

  when PARSE_EXT_LEN
    return parse_source_ext_len(source)

  when PARSE_MASKING
    return parse_source_masking(source)

  when PARSE_PAYLOAD
    return parse_source_payload(source)
  end
end

#fin?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/rakie/websocket_proto.rb', line 35

def fin?
  @fin
end

#serializeObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/rakie/websocket_proto.rb', line 61

def serialize
  data = ''

  data += pack_source_operation
  data += pack_source_len

  if @mask
    data += pack_source_masking
    data += pack_source_masked_payload

    return data
  end

  data += @payload

  return data
end