bindata 2.4.2 → 2.4.3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bindata might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 660228b3b8cdee82618401590015a45820a422fae8e0789d8bf4eceb89df3ee7
4
- data.tar.gz: db1dfef8d5942a56d5a31a25fba27b28a4169433669cb3e910a3fb7236ba8a0f
3
+ metadata.gz: dd9ce2f3336fc2e9f8e3250a278732351d6a1af220603fb62763b3ef83caaf5e
4
+ data.tar.gz: f8f15a3836564c6a51891231a276ed0848cc92bdb4663c5aca6d4eecd0f53ec4
5
5
  SHA512:
6
- metadata.gz: f4ba761be1d6e109d30961cffa4c92774fafd05fad047aa710f335d1cbd25a02c81a252e06e187ccf3864fd0453e49f2c58de4abac3504762fd60db5e32e962f
7
- data.tar.gz: b442381a7d7a04e930edcbad4e42269d88477e8223d26dbd81a57f0620fbe325299445d06ff1ea80e9ebf11a049e99f5e38e75d1a452a68d34ca8708e1b59441
6
+ metadata.gz: 5abcc6829c6b6ea410bc3c542d4b60d40a83e6ac883bb3a4b09dfefdc1e5a4ae1d37307d75e53cbbc1593a17dd327269974835a6f0936f2ab21f66fe69f120ba
7
+ data.tar.gz: ba8d7abcaac0ceb95acb6ffa8b24b7253495241fbd483ef887103a63d5c65c9649954a1998a70289e64823d0fb85bef1ba22a5bfb126b1cae9708a7412658220
@@ -1,5 +1,9 @@
1
1
  = BinData Changelog
2
2
 
3
+ == Version 2.4.3 (2018-03-10)
4
+
5
+ * Add Uint8Arrays. Requested by masarakki.
6
+
3
7
  == Version 2.4.2 (2018-01-31)
4
8
 
5
9
  * Allow boolean values as parameters. Requested by Patrik Wenger.
@@ -26,6 +26,7 @@ require 'bindata/string'
26
26
  require 'bindata/stringz'
27
27
  require 'bindata/struct'
28
28
  require 'bindata/trace'
29
+ require 'bindata/uint8_array'
29
30
  require 'bindata/virtual'
30
31
  require 'bindata/alignment'
31
32
  require 'bindata/warnings'
@@ -0,0 +1,62 @@
1
+ require "bindata/base_primitive"
2
+
3
+ module BinData
4
+ # Uint8Array is a specialised type of array that only contains
5
+ # bytes (Uint8). It is a faster and more memory efficient version
6
+ # of `BinData::Array.new(:type => :uint8)`.
7
+ #
8
+ # require 'bindata'
9
+ #
10
+ # obj = BinData::Uint8Array.new(initial_length: 5)
11
+ # obj.read("abcdefg") #=> [97, 98, 99, 100, 101]
12
+ # obj[2] #=> 99
13
+ # obj.collect { |x| x.chr }.join #=> "abcde"
14
+ #
15
+ # == Parameters
16
+ #
17
+ # Parameters may be provided at initialisation to control the behaviour of
18
+ # an object. These params are:
19
+ #
20
+ # <tt>:initial_length</tt>:: The initial length of the array.
21
+ # <tt>:read_until</tt>:: May only have a value of `:eof`. This parameter
22
+ # instructs the array to read as much data from
23
+ # the stream as possible.
24
+ class Uint8Array < BinData::BasePrimitive
25
+ optional_parameters :initial_length, :read_until
26
+ mutually_exclusive_parameters :initial_length, :read_until
27
+ arg_processor :uint8_array
28
+
29
+ #---------------
30
+ private
31
+
32
+ def value_to_binary_string(val)
33
+ val.pack("C*")
34
+ end
35
+
36
+ def read_and_return_value(io)
37
+ if has_parameter?(:initial_length)
38
+ data = io.readbytes(eval_parameter(:initial_length))
39
+ else
40
+ data = io.read_all_bytes
41
+ end
42
+
43
+ data.unpack("C*")
44
+ end
45
+
46
+ def sensible_default
47
+ []
48
+ end
49
+ end
50
+
51
+ class Uint8ArrayArgProcessor < BaseArgProcessor
52
+ def sanitize_parameters!(obj_class, params) #:nodoc:
53
+ # ensure one of :initial_length and :read_until exists
54
+ unless params.has_at_least_one_of?(:initial_length, :read_until)
55
+ params[:initial_length] = 0
56
+ end
57
+
58
+ msg = "Parameter :read_until must have a value of :eof"
59
+ params.sanitize(:read_until) { |val| raise ArgumentError, msg unless val == :eof }
60
+ end
61
+ end
62
+ end
@@ -1,3 +1,3 @@
1
1
  module BinData
2
- VERSION = "2.4.2"
2
+ VERSION = "2.4.3"
3
3
  end
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require File.expand_path(File.join(File.dirname(__FILE__), "test_helper"))
4
+
5
+ describe BinData::Uint8Array, "when initialising" do
6
+ it "with mutually exclusive parameters :initial_length and :read_until" do
7
+ params = {initial_length: 5, read_until: :eof}
8
+ lambda { BinData::Uint8Array.new(params) }.must_raise ArgumentError
9
+ end
10
+
11
+ it "with :read_until" do
12
+ params = {read_until: :not_eof}
13
+ lambda { BinData::Uint8Array.new(params) }.must_raise ArgumentError
14
+ end
15
+
16
+ it "with no parameters" do
17
+ arr = BinData::Uint8Array.new
18
+ arr.num_bytes.must_equal 0
19
+ end
20
+ end
21
+
22
+ describe BinData::Uint8Array, "with :read_until" do
23
+ it "reads until :eof" do
24
+ arr = BinData::Uint8Array.new(read_until: :eof)
25
+ arr.read("\xff\xfe\xfd\xfc")
26
+ arr.must_equal([255, 254, 253, 252])
27
+ end
28
+ end
29
+
30
+ describe BinData::Uint8Array, "with :initial_length" do
31
+ it "reads" do
32
+ arr = BinData::Uint8Array.new(initial_length: 3)
33
+ arr.read("\xff\xfe\xfd\xfc")
34
+ arr.must_equal([255, 254, 253])
35
+ end
36
+ end
37
+
38
+ describe BinData::Uint8Array, "when assigning" do
39
+ it "copies data" do
40
+ arr = BinData::Uint8Array.new
41
+ arr.assign([1, 2, 3])
42
+ arr.must_equal([1, 2, 3])
43
+ end
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bindata
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.2
4
+ version: 2.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dion Mendel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-31 00:00:00.000000000 Z
11
+ date: 2018-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -111,6 +111,7 @@ files:
111
111
  - lib/bindata/stringz.rb
112
112
  - lib/bindata/struct.rb
113
113
  - lib/bindata/trace.rb
114
+ - lib/bindata/uint8_array.rb
114
115
  - lib/bindata/version.rb
115
116
  - lib/bindata/virtual.rb
116
117
  - lib/bindata/warnings.rb
@@ -139,6 +140,7 @@ files:
139
140
  - test/struct_test.rb
140
141
  - test/system_test.rb
141
142
  - test/test_helper.rb
143
+ - test/uint8_array_test.rb
142
144
  - test/virtual_test.rb
143
145
  - test/warnings_test.rb
144
146
  homepage: http://github.com/dmendel/bindata