# # MessagePack format test case # begin require 'rubygems' rescue LoadError end require 'msgpack' require 'json' source = <97} FixMap de 00 01 a1 61 61 # {"a"=>97} map 16 df 00 00 00 01 a1 61 61 # {"a"=>97} map 32 91 90 # [[]] 91 91 a1 61 # [["a"]] EOF source.gsub!(/\#.+$/,'') bytes = source.strip.split(/\s+/).map {|x| x.to_i(16) }.pack('C*') objs = [] compact_bytes = "" pac = MessagePack::Unpacker.new pac.feed(bytes) pac.each {|obj| p obj objs << obj compact_bytes << obj.to_msgpack } json = objs.to_json # self check cpac = MessagePack::Unpacker.new cpac.feed(compact_bytes) cpac.each {|cobj| obj = objs.shift if obj != cobj puts "** SELF CHECK FAILED **" puts "expected: #{obj.inspect}" puts "actual: #{cobj.inspect}" exit 1 end } File.open("cases.mpac","w") {|f| f.write(bytes) } File.open("cases_compact.mpac","w") {|f| f.write(compact_bytes) } File.open("cases.json","w") {|f| f.write(json) }