bindata-contrib 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bindata-contrib/version.rb +5 -0
- data/lib/bool.rb +1 -1
- data/lib/ipv6_address.rb +2 -2
- data/spec/bool_spec.rb +19 -0
- data/spec/enum_spec.rb +39 -0
- data/spec/flags_spec.rb +38 -0
- data/spec/ipv4_address_spec.rb +16 -0
- data/spec/ipv6_address_spec.rb +25 -0
- data/spec/mac_address_spec.rb +16 -0
- data/spec/spec_helper.rb +1 -0
- metadata +33 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ffa7d572716ebd2fdb76833b6c35a338da122e7
|
4
|
+
data.tar.gz: cccd0027c6c9edc49244bd34337619542e9e4c35
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 490f62be5c3d49db8a77475bf81d9a6bcc0cd8435a3033af68e2e97ab3606dcb6c695d7c60961def6c2e66df0b81efd1af468bfe433d5251e794f585e786b397
|
7
|
+
data.tar.gz: a34ab5f2a69f2494a31c0c5011a1a86951503ddbdeed63426791d80eba08a7ab250ed24b1b705b052d4a5ae63a364143b7f83d46c9178fc3b35355bac663641e
|
data/lib/bool.rb
CHANGED
data/lib/ipv6_address.rb
CHANGED
@@ -2,10 +2,10 @@ require 'bindata'
|
|
2
2
|
|
3
3
|
class Ipv6Address < BinData::Primitive
|
4
4
|
endian :big
|
5
|
-
array :octets, type: :
|
5
|
+
array :octets, type: :uint16, initial_length: 8
|
6
6
|
|
7
7
|
def get
|
8
|
-
octets.map { |o| o.to_s(16) }.join(':')
|
8
|
+
octets.map { |o| o.to_i.to_s(16) }.join(':')
|
9
9
|
end
|
10
10
|
|
11
11
|
def set(value)
|
data/spec/bool_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Bool do
|
4
|
+
it 'should read binary' do
|
5
|
+
bool = Bool.read [0x80].pack('C*')
|
6
|
+
expect(bool).to eq(true)
|
7
|
+
|
8
|
+
bool = Bool.read [0].pack('C*')
|
9
|
+
expect(bool).to eq(false)
|
10
|
+
end
|
11
|
+
it 'should initialize with default values' do
|
12
|
+
bool = Bool.new
|
13
|
+
expect(bool).to eq(false)
|
14
|
+
end
|
15
|
+
it 'should initialize with some values' do
|
16
|
+
bool = Bool.new(true)
|
17
|
+
expect(bool).to eq(true)
|
18
|
+
end
|
19
|
+
end
|
data/spec/enum_spec.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Enum8, Enum16, Enum32' do
|
4
|
+
before(:all) do
|
5
|
+
class MyClass < BinData::Record
|
6
|
+
endian :big
|
7
|
+
enum8 :enum8, list: {default: 0, a: 1, b: 2, c: 3}
|
8
|
+
enum16 :enum16, list: {default: 0, d: 0x0101, e: 0x0202, f: 0x0303}
|
9
|
+
enum32 :enum32, list: {g: 0x01010101, h: 0x02020202, i: 0x03030303}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should read binary' do
|
14
|
+
cls = MyClass.read [
|
15
|
+
1,
|
16
|
+
2, 2,
|
17
|
+
3, 3, 3, 3
|
18
|
+
].pack('C*')
|
19
|
+
expect(cls.enum8).to eq(:a)
|
20
|
+
expect(cls.enum16).to eq(:e)
|
21
|
+
expect(cls.enum32).to eq(:i)
|
22
|
+
end
|
23
|
+
it 'should initialize with default values' do
|
24
|
+
cls = MyClass.new
|
25
|
+
expect(cls.enum8).to eq(:default)
|
26
|
+
expect(cls.enum16).to eq(:default)
|
27
|
+
expect(cls.enum32).to eq(0)
|
28
|
+
end
|
29
|
+
it 'should initialize with some values' do
|
30
|
+
cls = MyClass.new(
|
31
|
+
enum8: :c,
|
32
|
+
enum16: :d,
|
33
|
+
enum32: :h
|
34
|
+
)
|
35
|
+
expect(cls.enum8).to eq(:c)
|
36
|
+
expect(cls.enum16).to eq(:d)
|
37
|
+
expect(cls.enum32).to eq(:h)
|
38
|
+
end
|
39
|
+
end
|
data/spec/flags_spec.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'Flags8, Flags16, Flags32' do
|
4
|
+
before(:all) do
|
5
|
+
class MyClass < BinData::Record
|
6
|
+
endian :big
|
7
|
+
flags8 :flags8, list: [:a, :b, :c]
|
8
|
+
flags16 :flags16, list: [:d, :e, :f]
|
9
|
+
flags32 :flags32, list: [:g, :h, :i]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should read binary' do
|
14
|
+
cls = MyClass.read [
|
15
|
+
3,
|
16
|
+
0, 4,
|
17
|
+
0, 0, 0, 7
|
18
|
+
].pack('C*')
|
19
|
+
expect(cls.flags8).to eq([:a, :b])
|
20
|
+
expect(cls.flags16).to eq([:f])
|
21
|
+
expect(cls.flags32).to eq([:g, :h, :i])
|
22
|
+
end
|
23
|
+
it 'should initialize with default values' do
|
24
|
+
cls = MyClass.new
|
25
|
+
expect(cls.flags8).to be_empty
|
26
|
+
expect(cls.flags16).to be_empty
|
27
|
+
expect(cls.flags32).to be_empty
|
28
|
+
end
|
29
|
+
it 'should initialize with some values' do
|
30
|
+
cls = MyClass.new(
|
31
|
+
flags8: [:c],
|
32
|
+
flags16: [:d, :e]
|
33
|
+
)
|
34
|
+
expect(cls.flags8).to eq([:c])
|
35
|
+
expect(cls.flags16).to eq([:d, :e])
|
36
|
+
expect(cls.flags32).to be_empty
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ipv4Address do
|
4
|
+
it 'should read binary' do
|
5
|
+
addr = Ipv4Address.read [127, 0, 0, 1].pack('C*')
|
6
|
+
expect(addr).to eq('127.0.0.1')
|
7
|
+
end
|
8
|
+
it 'should initialize with default values' do
|
9
|
+
addr = Ipv4Address.new
|
10
|
+
expect(addr).to eq('0.0.0.0')
|
11
|
+
end
|
12
|
+
it 'should initialize with some values' do
|
13
|
+
addr = Ipv4Address.new('192.168.1.2')
|
14
|
+
expect(addr).to eq('192.168.1.2')
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Ipv6Address do
|
4
|
+
it 'should read binary' do
|
5
|
+
addr = Ipv6Address.read [
|
6
|
+
0x20, 0x01,
|
7
|
+
0x0d, 0xb8,
|
8
|
+
0x85, 0xa3,
|
9
|
+
0, 0,
|
10
|
+
0, 0,
|
11
|
+
0x8a, 0x2e,
|
12
|
+
0x03, 0x70,
|
13
|
+
0x73, 0x34
|
14
|
+
].pack('C*')
|
15
|
+
expect(addr).to eq('2001:db8:85a3:0:0:8a2e:370:7334')
|
16
|
+
end
|
17
|
+
it 'should initialize with default values' do
|
18
|
+
addr = Ipv6Address.new
|
19
|
+
expect(addr).to eq('0:0:0:0:0:0:0:0')
|
20
|
+
end
|
21
|
+
it 'should initialize with some values' do
|
22
|
+
addr = Ipv6Address.new('2001:db8:85a3:0:0:8a2e:370:7334')
|
23
|
+
expect(addr).to eq('2001:db8:85a3:0:0:8a2e:370:7334')
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MacAddress do
|
4
|
+
it 'should read binary' do
|
5
|
+
addr = MacAddress.read [0x01, 0x23, 0x45, 0x67, 0x89, 0xab].pack('C*')
|
6
|
+
expect(addr).to eq('01:23:45:67:89:ab')
|
7
|
+
end
|
8
|
+
it 'should initialize with default values' do
|
9
|
+
addr = MacAddress.new
|
10
|
+
expect(addr).to eq('00:00:00:00:00:00')
|
11
|
+
end
|
12
|
+
it 'should initialize with some values' do
|
13
|
+
addr = MacAddress.new('01:23:45:67:89:ab')
|
14
|
+
expect(addr).to eq('01:23:45:67:89:ab')
|
15
|
+
end
|
16
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative '../lib/bindata-contrib'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bindata-contrib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jérémy Pagé
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bindata
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.2'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.2'
|
27
41
|
description: Contribution to BinData.
|
28
42
|
email:
|
29
43
|
- contact@jeremypage.me
|
@@ -32,12 +46,20 @@ extensions: []
|
|
32
46
|
extra_rdoc_files: []
|
33
47
|
files:
|
34
48
|
- lib/bindata-contrib.rb
|
49
|
+
- lib/bindata-contrib/version.rb
|
35
50
|
- lib/bool.rb
|
36
51
|
- lib/enum.rb
|
37
52
|
- lib/flags.rb
|
38
53
|
- lib/ipv4_address.rb
|
39
54
|
- lib/ipv6_address.rb
|
40
55
|
- lib/mac_address.rb
|
56
|
+
- spec/bool_spec.rb
|
57
|
+
- spec/enum_spec.rb
|
58
|
+
- spec/flags_spec.rb
|
59
|
+
- spec/ipv4_address_spec.rb
|
60
|
+
- spec/ipv6_address_spec.rb
|
61
|
+
- spec/mac_address_spec.rb
|
62
|
+
- spec/spec_helper.rb
|
41
63
|
homepage: https://github.com/jejepage/bindata-contrib
|
42
64
|
licenses:
|
43
65
|
- MIT
|
@@ -58,8 +80,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
80
|
version: '0'
|
59
81
|
requirements: []
|
60
82
|
rubyforge_project:
|
61
|
-
rubygems_version: 2.
|
83
|
+
rubygems_version: 2.5.1
|
62
84
|
signing_key:
|
63
85
|
specification_version: 4
|
64
86
|
summary: BinData Contrib
|
65
|
-
test_files:
|
87
|
+
test_files:
|
88
|
+
- spec/bool_spec.rb
|
89
|
+
- spec/enum_spec.rb
|
90
|
+
- spec/flags_spec.rb
|
91
|
+
- spec/ipv4_address_spec.rb
|
92
|
+
- spec/ipv6_address_spec.rb
|
93
|
+
- spec/mac_address_spec.rb
|
94
|
+
- spec/spec_helper.rb
|