ione 1.3.0.pre0 → 1.3.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6374a6945473a540ef416dec0eaef9f2c5a23913
4
- data.tar.gz: c4b5defcacf2770af407842ee88edc7f9e172a6b
3
+ metadata.gz: a30c2a01cc8a7803d8709c93735b4e860cbc2744
4
+ data.tar.gz: 4dbba5e04c9c8ae95d3588d377f645bcc8edef7c
5
5
  SHA512:
6
- metadata.gz: 72ee4392985a601b028b4e6aa170accff6e8e50c27fc2cb7674cb9b3dd5b29091e8f92b3b5e26a515f372036fcaf1727bb866e1e8165a0f9567fd1749be91bac
7
- data.tar.gz: 231ee2abbb3d771d56d0fdab4c26b42f0684254b13056bf898dbce22d3ea2031e34aacc096a04dae6ee08a394ca880f03a362d7bbf9a96598becdbaaeec7e84c
6
+ metadata.gz: cef52539a1cc94bf977a83f73417be683cb31c3685f34915176b25ae21fd95e8ed365f5aba48938b257bcf858368e17471a645b8b6dc0a6a08181da3d734fc0e
7
+ data.tar.gz: 374274bee30bf02895b893590e1a33fae294e1763ae959d7f2442519e42617dd65b57d715f7db891875b04e9ee612fef437a838dd40175cc0f4cff1e4d23dcb3
@@ -174,6 +174,18 @@ module Ione
174
174
  b
175
175
  end
176
176
 
177
+ # Return the nt:h byte of the buffer, without removing it, and decode it as a signed or unsigned integer.
178
+ #
179
+ # @param [Integer] the zero-based positive position of the byte to read
180
+ # @return [Integer, nil] the integer interpretation of the byte at the specified position, or nil when beyond buffer size.
181
+ def getbyte(index, signed=false)
182
+ if @offset+index >= @read_buffer.bytesize
183
+ swap_buffers
184
+ end
185
+ b = @read_buffer.getbyte(@offset+index)
186
+ (signed && b >= 0x80) ? b - 0x100 : b
187
+ end
188
+
177
189
  def index(substring, start_index=0)
178
190
  if @offset >= @read_buffer.bytesize
179
191
  swap_buffers
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Ione
4
- VERSION = '1.3.0.pre0'.freeze
4
+ VERSION = '1.3.0.pre1'.freeze
5
5
  end
@@ -332,6 +332,37 @@ module Ione
332
332
  end
333
333
  end
334
334
 
335
+ describe '#getbyte' do
336
+ it 'returns the nth byte interpreted as an int' do
337
+ buffer.append("\x80\x01")
338
+ expect(buffer.getbyte(0)).to eq(0x80)
339
+ expect(buffer.getbyte(1)).to eq(0x01)
340
+ end
341
+
342
+ it 'returns nil if there are no bytes' do
343
+ expect(buffer.getbyte(0)).to be_nil
344
+ end
345
+
346
+ it 'returns nil if the index goes beyond the buffer' do
347
+ buffer.append("\x80\x01")
348
+ expect(buffer.getbyte(2)).to be_nil
349
+ end
350
+
351
+ it 'handles interleaved writes' do
352
+ buffer.append("\x80\x01")
353
+ buffer.read_byte
354
+ buffer.append("\x81\x02")
355
+ expect(buffer.getbyte(0)).to eq(0x01)
356
+ expect(buffer.getbyte(1)).to eq(0x81)
357
+ end
358
+
359
+ it 'can interpret the byte as signed' do
360
+ buffer.append("\x80\x02")
361
+ expect(buffer.getbyte(0, true)).to eq(-128)
362
+ expect(buffer.getbyte(1, true)).to eq(2)
363
+ end
364
+ end
365
+
335
366
  describe '#index' do
336
367
  it 'returns the first index of the specified substring' do
337
368
  buffer.append('fizz buzz')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ione
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0.pre0
4
+ version: 1.3.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Theo Hultberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-12 00:00:00.000000000 Z
11
+ date: 2015-12-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Reactive programming framework for Ruby, painless evented IO, futures
14
14
  and an efficient byte buffer