binp 3.0.0 → 4.0.0

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
  SHA256:
3
- metadata.gz: 5de1859ad3bbdf310f87399636229f383e4f40dd5e85624d61ae65d6ac52c3ed
4
- data.tar.gz: ac7a4cc8b986aa22022e6b3205d9d11d0c06d83504c2ca30b0788a3f7356993e
3
+ metadata.gz: 737c05ad3f05c0d57238526b2456d36e3a0fb1de14909d64fffa15942bfc76eb
4
+ data.tar.gz: 30c2ad4ec1b7a6cf12b772a85a4a811a5c22da0db93544346761584028fd3ff8
5
5
  SHA512:
6
- metadata.gz: 651c3478c7d470f7e25fcaa7f1ef15a9c508a92ee8835e5c9a05380f2662e211036195172e80499df85d0a6ee61503dbcc22db554207781fda2b1e3769e00b1d
7
- data.tar.gz: 150b67bc6b8a9502bf7a204e63afb3d6260f7c536cd5f4a89dd24090155678fb1d1a1f886c0bb4ba2fd99437e507cfb41e8a16f67ba685268b52e92de8f26816
6
+ metadata.gz: 19085d777a54bd338c9e12868ad3041a57540e568ba7cd36c9c1dae393235187fa5f9240708f5a517ff42e4f9a063ba5121d8a0dd49af4c56404dd6cd4b7a6ce
7
+ data.tar.gz: 6967cd575f2897023570563fc6985981b02b75dc7c62da6b807bafad938166875891f6f333c8270263273ba0a35681887a204b390b6f0c96bfe782dba5631564
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- binp (3.0.0)
4
+ binp (4.0.0)
5
5
  formatador
6
6
 
7
7
  GEM
@@ -59,6 +59,8 @@
59
59
  size: 1
60
60
  type: UINT8
61
61
  endianness: BIG
62
+ value_label:
63
+ 136: one hundred thirty six
62
64
  - name: FLAGS
63
65
  offset: 31
64
66
  type: FLAGS
data/lib/binp.rb CHANGED
@@ -8,7 +8,7 @@ class BinParser
8
8
  if e['type'] == BinParserElement::Type::FLAGS
9
9
  e = BinParserElement.get_flags(uint8_array, e)
10
10
  else
11
- e['value'] = BinParserElement.get_value(uint8_array, e['offset'], e['size'], e['type'], e['endianness'])
11
+ e['value'] = BinParserElement.get_value(uint8_array, e['offset'], e['size'], e['type'], e['endianness'], e['value_label'])
12
12
  end
13
13
  e
14
14
  }
@@ -79,11 +79,15 @@ class BinParserElement
79
79
  'C' * size
80
80
  end
81
81
 
82
- def self.get_value(uint8_array, offset, size, type, endianness)
82
+ def self.get_value(uint8_array, offset, size, type, endianness, value_labels={})
83
83
  target = uint8_array.slice(offset, size)
84
84
  pack_template_string = calculate_pack_template_string(size)
85
85
  unpack_template_string = calculate_unpack_template_string(type, endianness)
86
- target.pack(pack_template_string).unpack(unpack_template_string)[0]
86
+ value = target.pack(pack_template_string).unpack(unpack_template_string)[0]
87
+
88
+ # value_label が設定されている数値であれば、それに置き換える
89
+ value_labels ||= {}
90
+ value_labels.fetch(value, value)
87
91
  end
88
92
 
89
93
  def self.get_flags(uint8_array, config)
data/lib/binp/cli/main.rb CHANGED
@@ -42,10 +42,31 @@ class Main
42
42
  all: false
43
43
  }
44
44
  op = OptionParser.new
45
+ op.banner = 'Usage: binp [options] FILE'
45
46
 
46
47
  op.on('-c VALUE', '--config VALUE', '設定ファイルパス') { |v| options[:config] = v }
47
48
  op.on('-a', '--all', 'name, value 以外のすべての項目(endianness, offset, size, type)を表示する') { |v| options[:all] = true }
48
- op.parse!(argv)
49
+ begin
50
+ op.parse!(argv)
51
+ rescue OptionParser::InvalidOption => e
52
+ STDERR.puts 'ERROR: オプションのパースに失敗しました。'
53
+ STDERR.puts op.to_s
54
+ exit(1);
55
+ end
56
+
57
+ # 必須オプション `-c` のチェック
58
+ unless options[:config]
59
+ STDERR.puts 'ERROR: 必須オプション `-c, --config` が指定されていません。'
60
+ STDERR.puts op.to_s
61
+ exit(1);
62
+ end
63
+
64
+ # ファイル指定があるかのチェック
65
+ if argv.size == 0
66
+ STDERR.puts 'ERROR: FILE が指定されていません。'
67
+ STDERR.puts op.to_s
68
+ exit(1);
69
+ end
49
70
 
50
71
  [options, argv]
51
72
  end
data/lib/binp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Binp
2
- VERSION = "3.0.0"
2
+ VERSION = "4.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: binp
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 4.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mikoto2000
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-30 00:00:00.000000000 Z
11
+ date: 2021-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: formatador
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  - !ruby/object:Gem::Version
101
101
  version: '0'
102
102
  requirements: []
103
- rubygems_version: 3.1.2
103
+ rubygems_version: 3.1.4
104
104
  signing_key:
105
105
  specification_version: 4
106
106
  summary: binary file parser.