protocol-websocket 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6dbf808fd6d8859dccb3ce6b8e9578ec62fbb9f2530aa1adc809d0143e16141e
4
- data.tar.gz: d674db6e338b18db74b8a170aa81980d609a9c4ae235921c4a87a188a333654a
3
+ metadata.gz: e079958535576416ddb72c68df979c7d8df7ef808986208917a0511d1ae69a64
4
+ data.tar.gz: 6d6bfa79a21f935a9ca4928e4fbcc9f0942f822e0efed9bfb53387b2b46fad8b
5
5
  SHA512:
6
- metadata.gz: 3fe42aa9dabd6965081a86b9eae2b9deffcff628ef4081c48ed3b53b33854a1782deffde2cb84a91f9ec1d5acd69dc38b2e36c82390cd0ea55b49eac431a0908
7
- data.tar.gz: d60e9344e0f386a158549bc1e8a332a5ef4b3e7adc934ffde273dfed73def85a3fd994f4d58e0bddbcfba42cee2fcb7250aa1b4afe0ba9df29721d9ff5be0285
6
+ metadata.gz: a6fcc1de1d57eec7d08dc692af7dbc75c8758d064f98a47f05f8cc7a084dfcf4333cebe2c3e8dbc9c64a562744eb466e816bf28df07e77fc9a3b855e16cf589e
7
+ data.tar.gz: '095cd95f03d4cb7d3e564725d0ab638917b4ff644ad439316e89700e85f26068b888d425b483be30110c86fca95554c44a5a7f5bd18e84aeac4bbbecd53ac619'
@@ -25,6 +25,10 @@ module Protocol
25
25
  class BinaryFrame < Frame
26
26
  OPCODE = 0x2
27
27
 
28
+ def data?
29
+ true
30
+ end
31
+
28
32
  def apply(connection)
29
33
  connection.receive_binary(self)
30
34
  end
@@ -165,7 +165,30 @@ module Protocol
165
165
  warn "Unhandled frame #{frame.inspect}"
166
166
  end
167
167
 
168
- # @return [Array<Frame>] sequence of frames, the first being either text or binary, optionally followed by a number of continuation frames.
168
+ # @param buffer [String] a unicode or binary string.
169
+ def write(buffer)
170
+ if buffer.encoding == Encoding::UTF_8
171
+ send_text(buffer)
172
+ else
173
+ send_data(buffer)
174
+ end
175
+ end
176
+
177
+ # @return [String] a unicode or binary string.
178
+ def read
179
+ @framer.flush
180
+
181
+ while read_frame
182
+ if @frames.last&.finished?
183
+ buffer = @frames.map(&:unpack).join
184
+ @frames = []
185
+
186
+ return buffer
187
+ end
188
+ end
189
+ end
190
+
191
+ # Deprecated.
169
192
  def next_message
170
193
  @framer.flush
171
194
 
@@ -48,6 +48,10 @@ module Protocol
48
48
  @opcode & 0x8
49
49
  end
50
50
 
51
+ def data?
52
+ false
53
+ end
54
+
51
55
  def finished?
52
56
  @finished == true
53
57
  end
@@ -25,6 +25,10 @@ module Protocol
25
25
  class TextFrame < Frame
26
26
  OPCODE = 0x1
27
27
 
28
+ def data?
29
+ true
30
+ end
31
+
28
32
  def unpack
29
33
  super.force_encoding(Encoding::UTF_8)
30
34
  end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Protocol
22
22
  module WebSocket
23
- VERSION = "0.4.0"
23
+ VERSION = "0.5.0"
24
24
  end
25
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: protocol-websocket
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
140
140
  - !ruby/object:Gem::Version
141
141
  version: '0'
142
142
  requirements: []
143
- rubygems_version: 3.0.2
143
+ rubygems_version: 3.0.3
144
144
  signing_key:
145
145
  specification_version: 4
146
146
  summary: A low level implementation of the WebSocket protocol.