add crosslang.rb

This commit is contained in:
frsyuki 2010-05-31 17:27:51 +09:00
parent 98a5e43883
commit a0071c2f9f
2 changed files with 82 additions and 1 deletions

View File

@ -78,7 +78,7 @@ static void usage(const char* prog)
" 3. Writes the re-serialized objects into <out-file> (default: stdout)\n" " 3. Writes the re-serialized objects into <out-file> (default: stdout)\n"
"\n" "\n"
, prog); , prog);
exit(0); exit(1);
} }
int main(int argc, char* argv[]) int main(int argc, char* argv[])

81
crosslang.rb Normal file
View 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