bytemapper 1.0.25 → 1.0.26
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 +4 -4
- data/lib/bytemapper.rb +1 -0
- data/lib/bytemapper/chunk.rb +2 -0
- data/lib/bytemapper/nameable.rb +2 -2
- data/lib/bytemapper/shape.rb +10 -0
- data/lib/bytemapper/table.rb +11 -23
- data/lib/refinements.rb +24 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 76c2e215cabd7c201c72481a89a032dcd6034512b4242eb821fe097914c7f69f
|
|
4
|
+
data.tar.gz: 31615cfac602b73c2d3d36f1c9a0b4bc9ca55befec6cad72c4fae2fd7f39df80
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4b8d9c242406a8d80d30e901231fe674b2d689c8d0f44310e5e021f305c23f1ea508ee0d9f607ec6c19b187c64d060f40b2b970e3ca7f99ab5ced89a48713d84
|
|
7
|
+
data.tar.gz: ed768686f5c64498d0c382a57ba92e292ef1a6fcf72fe69ded983378805aac32056e3e78e79be51c3d534bd222b448f6c69b193f49033e7775e90ea22177ecb7
|
data/lib/bytemapper.rb
CHANGED
data/lib/bytemapper/chunk.rb
CHANGED
data/lib/bytemapper/nameable.rb
CHANGED
data/lib/bytemapper/shape.rb
CHANGED
|
@@ -20,6 +20,12 @@ module Bytemapper
|
|
|
20
20
|
class Shape < Hash
|
|
21
21
|
include Flattenable
|
|
22
22
|
include Nameable
|
|
23
|
+
attr_accessor :hooks
|
|
24
|
+
|
|
25
|
+
def initialize
|
|
26
|
+
super
|
|
27
|
+
@hooks = []
|
|
28
|
+
end
|
|
23
29
|
|
|
24
30
|
def []=(k,v)
|
|
25
31
|
super
|
|
@@ -27,6 +33,10 @@ module Bytemapper
|
|
|
27
33
|
instance_variable_set("@#{k.to_s}", self[k])
|
|
28
34
|
end
|
|
29
35
|
|
|
36
|
+
def hook(&block)
|
|
37
|
+
@hooks << block if block_given?
|
|
38
|
+
end
|
|
39
|
+
|
|
30
40
|
def size
|
|
31
41
|
flatten.values.map(&:size).reduce(:+)
|
|
32
42
|
end
|
data/lib/bytemapper/table.rb
CHANGED
|
@@ -1,44 +1,32 @@
|
|
|
1
1
|
module Bytemapper
|
|
2
|
-
|
|
3
|
-
refine NilClass do
|
|
4
|
-
def times
|
|
5
|
-
0
|
|
6
|
-
end
|
|
7
|
-
end
|
|
8
|
-
end
|
|
2
|
+
using Refinements
|
|
9
3
|
|
|
10
4
|
class Table < Array
|
|
11
5
|
include Flattenable
|
|
12
6
|
include Nameable
|
|
13
|
-
attr_reader :
|
|
14
|
-
using NilTimes
|
|
7
|
+
attr_reader :bytes, :shape
|
|
15
8
|
|
|
16
9
|
def initialize(shape, rows = nil)
|
|
10
|
+
@bytes = nil
|
|
17
11
|
@shape = Bytemapper.get(shape)
|
|
18
|
-
rows.times { self << @shape }
|
|
19
12
|
end
|
|
20
13
|
|
|
21
14
|
def populate(bytes)
|
|
22
|
-
bytes =
|
|
23
|
-
@bytes = bytes.is_a?(StringIO) ? bytes : StringIO.new(bytes)
|
|
24
|
-
@bytes.string.force_encoding(Encoding::ASCII_8BIT)
|
|
25
|
-
if unbounded?
|
|
26
|
-
(bytes.size / shape.size).times { self << @shape }
|
|
27
|
-
end
|
|
15
|
+
@bytes = StringIO.from(bytes)
|
|
28
16
|
|
|
29
|
-
table = Table.new(shape)
|
|
17
|
+
table = Table.new(shape)
|
|
30
18
|
table.clear
|
|
31
|
-
(bytes.size / shape.size).times { table << Chunk.new(@bytes.read(shape.size), shape, shape.name) }
|
|
32
|
-
table
|
|
33
|
-
end
|
|
34
19
|
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
(bytes.size / shape.size).times do
|
|
21
|
+
table << Chunk.new(@bytes.read(shape.size), shape, shape.name)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
table
|
|
37
25
|
end
|
|
38
26
|
|
|
39
27
|
def size
|
|
40
28
|
empty? ? 0 : map(&:size).reduce(:+)
|
|
41
29
|
end
|
|
30
|
+
|
|
42
31
|
end
|
|
43
32
|
end
|
|
44
|
-
|
data/lib/refinements.rb
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Refinements
|
|
2
|
+
refine StringIO do
|
|
3
|
+
def peek
|
|
4
|
+
string[pos]
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def extract(offset, length)
|
|
8
|
+
prev = pos
|
|
9
|
+
seek(offset)
|
|
10
|
+
bytes = read(length)
|
|
11
|
+
seek(prev)
|
|
12
|
+
bytes
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
refine StringIO.singleton_class do
|
|
17
|
+
def from(obj)
|
|
18
|
+
obj = obj.nil? ? '' : obj
|
|
19
|
+
obj = obj.is_a?(StringIO) ? obj : new(obj)
|
|
20
|
+
obj.string.force_encoding(Encoding::ASCII_8BIT)
|
|
21
|
+
obj
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: bytemapper
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.26
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jefferson Hudson
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-08-
|
|
11
|
+
date: 2020-08-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Model and interact with bytestrings using Ruby objects.
|
|
14
14
|
email: jefferson.hudson@gmail.com
|
|
@@ -25,6 +25,7 @@ files:
|
|
|
25
25
|
- lib/bytemapper/table.rb
|
|
26
26
|
- lib/bytemapper/type.rb
|
|
27
27
|
- lib/bytemapper/typeable.rb
|
|
28
|
+
- lib/refinements.rb
|
|
28
29
|
homepage: https://github.com/l4cr0ss/bytemapper
|
|
29
30
|
licenses:
|
|
30
31
|
- AGPL-3.0-or-later
|