mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-19 21:18:23 +01:00
add crosslang.rb
This commit is contained in:
parent
98a5e43883
commit
a0071c2f9f
@ -78,7 +78,7 @@ static void usage(const char* prog)
|
||||
" 3. Writes the re-serialized objects into <out-file> (default: stdout)\n"
|
||||
"\n"
|
||||
, prog);
|
||||
exit(0);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
|
81
crosslang.rb
Normal file
81
crosslang.rb
Normal file
@ -0,0 +1,81 @@
|
||||
begin
|
||||
require 'rubygems'
|
||||
rescue LoadError
|
||||
end
|
||||
require 'msgpack'
|
||||
|
||||
def run(inio, outio)
|
||||
pac = MessagePack::Unpacker.new(inio)
|
||||
|
||||
begin
|
||||
pac.each {|obj|
|
||||
outio.write MessagePack.pack(obj)
|
||||
outio.flush
|
||||
}
|
||||
rescue EOFError
|
||||
return 0
|
||||
rescue
|
||||
$stderr.puts $!
|
||||
return 1
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
def usage
|
||||
puts <<EOF
|
||||
Usage: #{$0} [in-file] [out-file]
|
||||
|
||||
This tool is for testing of MessagePack implementation.
|
||||
This does following behavior:
|
||||
|
||||
1. Reads objects serialized by MessagePack from <in-file> (default: stdin)
|
||||
2. Re-serializes the objects using Ruby implementation of MessagePack (Note that Ruby implementation is considered valid)
|
||||
3. Writes the re-serialized objects into <out-file> (default: stdout)
|
||||
|
||||
EOF
|
||||
exit 1
|
||||
end
|
||||
|
||||
inio = $stdin
|
||||
outio = $stdout
|
||||
|
||||
if ARGV.length > 2
|
||||
usage
|
||||
end
|
||||
|
||||
ARGV.each {|str|
|
||||
if str.size > 1 && str[0] == ?-
|
||||
usage
|
||||
end
|
||||
}
|
||||
|
||||
if fname = ARGV[0]
|
||||
unless fname == "-"
|
||||
begin
|
||||
inio = File.open(fname)
|
||||
rescue
|
||||
puts "can't open output file: #{$!}"
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if fname = ARGV[1]
|
||||
unless fname == "-"
|
||||
begin
|
||||
outio = File.open(fname, "w")
|
||||
rescue
|
||||
puts "can't open output file: #{$!}"
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
code = run(inio, outio)
|
||||
|
||||
inio.close
|
||||
outio.close
|
||||
|
||||
exit code
|
||||
|
Loading…
x
Reference in New Issue
Block a user