msgpack-inspect 0.1.2 → 0.1.3

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: 6e91d7d7767afb363718c4d91b9eb5b3777d1ba6
4
- data.tar.gz: 5ddb504a62ad2ef03baa4fa5f0155ad301c9a769
3
+ metadata.gz: 56c1643fed6f78a15d1504da7a41d211c26d97bd
4
+ data.tar.gz: 5a13789e05e563e1e4591f4bd924873617da314e
5
5
  SHA512:
6
- metadata.gz: ba04b57ddfac50103b15bacf1ed8dd3d82bad41a0cd0b1d6d61136ef0622f01c482fa73e42bfa967e990ece5d3b68e4fc77da7d617a1201f51ce6ab744abddfe
7
- data.tar.gz: 7bdb948ec679f023f568b4b10d9a6f4718e3f402365612e742f4662628be64c4198e05e4188046ff3508857b19f094f9997ee408a831b75b56b32996676ffcd0
6
+ metadata.gz: 27ae13a9338558e17e318a0a220d5bdeb7cc0237bba61c1351fe03e4962898de0e7c1a181e6533dabdc61f4390198206e5809d3075e65eb67e7195211be3e65c
7
+ data.tar.gz: 40f96ca5d376e78a9973ad01ae0a1c885c2b1becf99453ca2bbb2f3f59e917e9e6cbe6562f7c50f248f5e9737b64cf737f99c18830bfe590137e730ca3d356e7
data/README.md CHANGED
@@ -4,17 +4,9 @@ This is a command line tool to inspect/show a data serialized by [MessagePack](h
4
4
 
5
5
  ## Installation
6
6
 
7
- Add this line to your application's Gemfile:
7
+ Executable binary files are available from [releases](https://github.com/tagomoris/msgpack-inspect/releases). Download a file for your platform, and use it.
8
8
 
9
- ```ruby
10
- gem 'msgpack-inspect'
11
- ```
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
9
+ Otherwise, you can install rubygem version on your CRuby runtime:
18
10
 
19
11
  $ gem install msgpack-inspect
20
12
 
@@ -25,11 +17,14 @@ Usage: msgpack-inspect [options] FILE
25
17
 
26
18
  Options:
27
19
 
28
- -f, --format FORMAT output format of inspection result (yaml/json) [default: yaml]
20
+ -f, --format FORMAT output format of inspection result (yaml/json/jsonl) [default: yaml]
29
21
  -r, --require LIB ruby file path to require (to load ext type definitions)
22
+ -v, --version Show version of this software
30
23
  -h, --help Show this message
31
24
  ```
32
25
 
26
+ `-r` option is available oly with rubygem version, and unavailable with mruby binary release.
27
+
33
28
  FILE is a file which msgpack binary stored. Specify `-` to inspect data from STDIN.
34
29
  This command shows the all data contained in specified format (YAML in default).
35
30
 
data/Rakefile CHANGED
@@ -62,7 +62,6 @@ task :release => :compile do
62
62
 
63
63
  Dir.chdir(arch) do
64
64
  arch_release = "#{app_name}-#{arch}"
65
- puts "current dir #{Dir.pwd}"
66
65
  puts "Writing #{release_path}/#{arch_release}.tgz"
67
66
  `tar czf #{release_path}/#{arch_release}.tgz *`
68
67
  end
@@ -13,7 +13,7 @@ module MessagePack
13
13
  opts.separator ""
14
14
  opts.separator "Options:"
15
15
  opts.separator ""
16
- opts.on("-f", "--format FORMAT", "output format of inspection result (yaml/json) [default: yaml]") do |v|
16
+ opts.on("-f", "--format FORMAT", "output format of inspection result (#{MessagePack::Inspect::FORMATS.compact.join('/')}) [default: yaml]") do |v|
17
17
  format = v.to_sym
18
18
  end
19
19
  opts.on("-r", "--require LIB", "ruby file path to require (to load ext type definitions)") do |path|
@@ -3,33 +3,42 @@ module MessagePack
3
3
  class Inspector
4
4
  FORMATS = [:yaml, :json, :jsonl, nil] # nil is for test (without stream dump)
5
5
 
6
- def initialize(io, format = :yaml, opt)
6
+ def initialize(io, format = :yaml, opt={})
7
7
  # return_values: false, output_io: STDOUT
8
8
  @io = io
9
9
  @format = format
10
10
  @streamer = MessagePack::Inspect::Streamer.get(@format)
11
- @return_values = opt.fetch(:return_values, false)
12
- @output_io = opt.fetch(:output_io, STDOUT)
11
+ @return_values = opt[:return_values] || false
12
+ @output_io = opt[:output_io] || STDOUT
13
13
  end
14
14
 
15
15
  def inspect
16
16
  data = []
17
17
  @streamer.objects(@output_io, 0) do
18
18
  i = 0
19
- until @io.eof?
20
- @streamer.object(@output_io, 1, i) do
21
- obj = dig(1)
22
- data << obj if @return_values
19
+ begin
20
+ while true
21
+ first_byte = @io.read(1)
22
+ break if first_byte.nil? && @io.eof?
23
+ # breaking out of @streamer.object before writing object-start bytes into STDOUT
24
+ @streamer.object(@output_io, 1, i) do
25
+ obj = dig(1, true, first_byte)
26
+ data << obj if @return_values
27
+ end
28
+ i += 1
23
29
  end
24
- i += 1
30
+ rescue EOFError
31
+ # end of input
25
32
  end
26
33
  end
27
34
  @return_values ? data : nil
28
35
  end
29
36
 
30
- def dig(depth, heading = true)
31
- header_byte = @io.read(1)
37
+ def dig(depth, heading = true, first_byte = nil)
38
+ header_byte = first_byte || @io.read(1)
32
39
  # TODO: error handling for header_byte:nil or raised exception
40
+ raise EOFError if header_byte.nil? && @io.eof?
41
+
33
42
  header = header_byte.b
34
43
  fmt = parse_header(header)
35
44
  node = MessagePack::Inspect::Node.new(fmt, header)
@@ -149,7 +149,9 @@ module MessagePack
149
149
  v1 = io.read(4)
150
150
  v2 = io.read(4)
151
151
  @data = hex(v1) + hex(v2)
152
- @value = (v1.unpack('N').first << 32) | v2.unpack('N').first
152
+ # mruby doesn't have Bignum, and Float doesn't support #|
153
+ # @value = (v1.unpack('N').first << 32) | v2.unpack('N').first
154
+ @value = (v1.unpack('N').first << 32) + v2.unpack('N').first
153
155
  when :int8
154
156
  v = io.read(1)
155
157
  @data = hex(v)
@@ -176,11 +178,18 @@ module MessagePack
176
178
  v1 = io.read(4)
177
179
  v2 = io.read(4)
178
180
  @data = hex(v1) + hex(v2)
179
- n = (v1.unpack('N').first << 32) | v2.unpack('N').first
180
- @value = if n & 0x8000_0000_0000_0000 > 0 # negative
181
- n - MAX_INT64
182
- else
183
- n
181
+ # mruby doesn't have Bignum, and Float doesn't support #|
182
+ # n = (v1.unpack('N').first << 32) | v2.unpack('N').first
183
+ # @value = if n & 0x8000_0000_0000_0000 > 0 # negative
184
+ # n - MAX_INT64
185
+ # else
186
+ # n
187
+ # end
188
+ upper = v1.unpack('N').first
189
+ @value = if upper & 0x8000_0000 > 0 # negative
190
+ (upper << 32) + v2.unpack('N').first - MAX_INT64
191
+ else # positive
192
+ (upper << 32) + v2.unpack('N').first
184
193
  end
185
194
  else
186
195
  raise "unknown int format #{@format}"
@@ -220,8 +229,8 @@ module MessagePack
220
229
  if [:fixstr, :str8, :str16, :str32].include?(@format)
221
230
  begin
222
231
  @value = v.force_encoding('UTF-8')
223
- rescue
224
- @error = $!.message
232
+ rescue => e
233
+ @error = e.message
225
234
  end
226
235
  else
227
236
  @value = v.b
@@ -1,5 +1,5 @@
1
1
  module MessagePack
2
2
  module Inspect
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
@@ -1,10 +1,19 @@
1
- require_relative 'mrblib/msgpack/inspect/version'
1
+ require_relative 'lib/msgpack/inspect/version' # mrblib/msgpack/inspect/version is symlink to that file
2
2
 
3
3
  spec = MRuby::Gem::Specification.new('msgpack-inspect') do |spec|
4
+ spec.rbfiles = [
5
+ "mrblib/msgpack/inspect/version.rb",
6
+ "mrblib/msgpack/inspect/node.rb",
7
+ "mrblib/msgpack/inspect/streamer.rb",
8
+ "mrblib/msgpack/inspect/inspector.rb",
9
+ "mrblib/msgpack/inspect.rb",
10
+ "mrblib/msgpack-inspect.rb",
11
+ ]
4
12
  spec.bins = ['msgpack-inspect']
5
13
  spec.add_dependency 'mruby-io', mgem: 'mruby-io'
6
- spec.add_dependency 'mruby-print', :core => 'mruby-print'
7
- spec.add_dependency 'mruby-mtest', :mgem => 'mruby-mtest'
14
+ spec.add_dependency 'mruby-pack', mgem: 'mruby-pack'
15
+ spec.add_dependency 'mruby-print', core: 'mruby-print'
16
+ spec.add_dependency 'mruby-mtest', mgem: 'mruby-mtest'
8
17
  end
9
18
 
10
19
  spec.license = 'Apache-2.0'
@@ -1,9 +1,20 @@
1
+ class String
2
+ # It's only for mruby... Encoding of String are defined by MRB_UTF8_STRING (or undef it) on build time.
3
+ # Default is disabled, and this tool is built under that configuration.
4
+ def force_encoding(encoding)
5
+ self
6
+ end
7
+ def b
8
+ self
9
+ end
10
+ end
11
+
1
12
  def show_usage
2
13
  msg = <<-EOL
3
14
  Usage: msgpack-inspect [options] FILE"
4
15
 
5
16
  Options:
6
- -f, --format FORMAT Output format of inspection result (yaml/json) [default: yaml]
17
+ -f, --format FORMAT Output format of inspection result (#{MessagePack::Inspect::FORMATS.reject{|v| v.nil? }.join('/')}) [default: yaml]
7
18
  -r, --require LIB (Not supported in binary executable)
8
19
  -h, --help Show this message
9
20
  -v, --version Show version of this software
@@ -36,7 +47,7 @@ def __main__(argv)
36
47
  arg = argv.shift
37
48
  if arg == '--'
38
49
  parsing_option = false
39
- elsif arg.start_with?('-')
50
+ elsif arg[0] == '-' && arg.length > 1
40
51
  show_usage
41
52
  raise "Unknown option specified: #{arg}"
42
53
  else
@@ -62,5 +73,5 @@ def __main__(argv)
62
73
  show_usage
63
74
  raise "Unsupported format: #{format}"
64
75
  end
65
- puts MessagePack::Inspect.inspect(io).dump(format)
76
+ MessagePack::Inspect.inspect(io, format).inspect
66
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msgpack-inspect
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - TAGOMORI Satoshi