Last active
January 24, 2016 12:23
-
-
Save joker1007/d3a1646a214869a98007 to your computer and use it in GitHub Desktop.
異なるmsgpackのバージョン同士でのdumpとload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'msgpack' | |
data = { | |
"foo" => "bar", | |
"ascii" => "bar".force_encoding(Encoding::ASCII_8BIT), | |
"utf8" => "あいうえお".force_encoding(Encoding::UTF_8), | |
"bad_ascii" => "あいうえお".force_encoding(Encoding::ASCII_8BIT), | |
"binary" => "Ruby".unpack("U*").pack("i*"), | |
"int" => 42, | |
"float" => 2.3, | |
"array" => [ | |
"array1", | |
2, | |
3.0, | |
[4].pack("i*") | |
], | |
"map" => { | |
"hoge" => "fuga", | |
} | |
} | |
p data.to_msgpack | |
File.open("../data.dump", "w") { |f| f.write data.to_msgpack } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'msgpack' | |
require 'test/unit' | |
class TestCase < Test::Unit::TestCase | |
def test_data | |
origin = { | |
"foo" => "bar", | |
"ascii" => "bar", | |
"utf8" => "あいうえお", | |
"bad_ascii" => "あいうえお".force_encoding(Encoding::ASCII_8BIT), | |
"binary" => "Ruby", | |
"int" => 42, | |
"float" => 2.3, | |
"array" => [ | |
"array1", | |
2, | |
3.0, | |
[4] | |
], | |
"map" => { | |
"hoge" => "fuga", | |
} | |
} | |
data = MessagePack.unpack(File.read("../data.dump")) | |
data["binary"] = data["binary"].unpack("i*").pack("U*") | |
data["array"][3] = data["array"][3].unpack("i*") | |
assert { data == origin } | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
v0.5.12 -> v0.5.12: NG | |
v0.5.12 -> v0.6.2: NG | |
v0.5.12 -> v0.7.4: NG | |
v0.6.2 -> v0.5.12: NG | |
v0.6.2 -> v0.6.2: OK | |
v0.6.2 -> v0.7.4: OK | |
v0.7.4 -> v0.5.12: NG | |
v0.7.4 -> v0.6.2: OK | |
v0.7.4 -> v0.7.4: OK | |
0.5系でUTF-8文字列を無理矢理ASCII-8BITにしたものをmsgpack化してunpackするとunpackするUTF-8の文字列として復元される。 | |
0.6系以降でUTF-8文字列を無理矢理ASCII-8BITにしたものをmsgpack化してunpackするとASCII-8BITの文字列として復元される。 | |
0.6系以降でUTF-8文字列を無理矢理ASCII-8BITにしたものをmsgpack化して0.5系でunpackするとUTF-8の文字列として復元される。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% ./test.sh | |
Using msgpack 0.5.12 | |
Using bundler 1.11.2 | |
Bundle complete! 1 Gemfile dependency, 2 gems now installed. | |
Bundled gems are installed into ./.bundle. | |
"\x89\xA3foo\xA3bar\xA5ascii\xA3bar\xA4utf8\xAF\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A\xA9bad_ascii\xAF\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A\xA6binary\xB0R\x00\x00\x00u\x00\x00\x00b\x00\x00\x00y\x00\x00\x00\xA3int*\xA5float\xCB@\x02ffffff\xA5array\x94\xA6array1\x02\xCB@\b\x00\x00\x00\x00\x00\x00\xA4\x04\x00\x00\x00\xA3map\x81\xA4hoge\xA4fuga" | |
0.5 -> 0.5 | |
Using msgpack 0.5.12 | |
Using power_assert 0.2.7 | |
Using bundler 1.11.2 | |
Using test-unit 3.1.7 | |
Bundle complete! 2 Gemfile dependencies, 4 gems now installed. | |
Bundled gems are installed into ./.bundle. | |
Loaded suite load | |
Started | |
F | |
========================================================================================================================================================================================================================== | |
Failure: | |
assert { data == origin } | |
| | | | |
| | {"foo"=>"bar", "ascii"=>"bar", "utf8"=>"あいうえお", "bad_ascii"=>"\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A", "binary"=>"Ruby", "int"=>42, "float"=>2.3, "array"=>["array1", 2, 3.0, [4]], "map"=>{"hoge"=>"fuga"}} | |
| false | |
{"foo"=>"bar", "ascii"=>"bar", "utf8"=>"あいうえお", "bad_ascii"=>"あいうえお", "binary"=>"Ruby", "int"=>42, "float"=>2.3, "array"=>["array1", 2, 3.0, [4]], "map"=>{"hoge"=>"fuga"}} | |
test_data(TestCase) | |
load.rb:30:in `test_data' | |
27: data["binary"] = data["binary"].unpack("i*").pack("U*") | |
28: data["array"][3] = data["array"][3].unpack("i*") | |
29: | |
=> 30: assert { data == origin } | |
31: end | |
32: end | |
========================================================================================================================================================================================================================== | |
Finished in 0.006006 seconds. | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
1 tests, 1 assertions, 1 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications | |
0% passed | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
166.50 tests/s, 166.50 assertions/s | |
0.5 -> 0.6 | |
Using msgpack 0.6.2 | |
Using power_assert 0.2.7 | |
Using bundler 1.11.2 | |
Using test-unit 3.1.7 | |
Bundle complete! 2 Gemfile dependencies, 4 gems now installed. | |
Bundled gems are installed into ./.bundle. | |
Loaded suite load | |
Started | |
F | |
========================================================================================================================================================================================================================== | |
Failure: | |
assert { data == origin } | |
| | | | |
| | {"foo"=>"bar", "ascii"=>"bar", "utf8"=>"あいうえお", "bad_ascii"=>"\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A", "binary"=>"Ruby", "int"=>42, "float"=>2.3, "array"=>["array1", 2, 3.0, [4]], "map"=>{"hoge"=>"fuga"}} | |
| false | |
{"foo"=>"bar", "ascii"=>"bar", "utf8"=>"あいうえお", "bad_ascii"=>"あいうえお", "binary"=>"Ruby", "int"=>42, "float"=>2.3, "array"=>["array1", 2, 3.0, [4]], "map"=>{"hoge"=>"fuga"}} | |
test_data(TestCase) | |
load.rb:30:in `test_data' | |
27: data["binary"] = data["binary"].unpack("i*").pack("U*") | |
28: data["array"][3] = data["array"][3].unpack("i*") | |
29: | |
=> 30: assert { data == origin } | |
31: end | |
32: end | |
========================================================================================================================================================================================================================== | |
Finished in 0.006099 seconds. | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
1 tests, 1 assertions, 1 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications | |
0% passed | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
163.96 tests/s, 163.96 assertions/s | |
0.5 -> 0.7 | |
Using msgpack 0.7.4 | |
Using power_assert 0.2.7 | |
Using bundler 1.11.2 | |
Using test-unit 3.1.7 | |
Bundle complete! 2 Gemfile dependencies, 4 gems now installed. | |
Bundled gems are installed into ./.bundle. | |
Loaded suite load | |
Started | |
F | |
========================================================================================================================================================================================================================== | |
Failure: | |
assert { data == origin } | |
| | | | |
| | {"foo"=>"bar", "ascii"=>"bar", "utf8"=>"あいうえお", "bad_ascii"=>"\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A", "binary"=>"Ruby", "int"=>42, "float"=>2.3, "array"=>["array1", 2, 3.0, [4]], "map"=>{"hoge"=>"fuga"}} | |
| false | |
{"foo"=>"bar", "ascii"=>"bar", "utf8"=>"あいうえお", "bad_ascii"=>"あいうえお", "binary"=>"Ruby", "int"=>42, "float"=>2.3, "array"=>["array1", 2, 3.0, [4]], "map"=>{"hoge"=>"fuga"}} | |
test_data(TestCase) | |
load.rb:30:in `test_data' | |
27: data["binary"] = data["binary"].unpack("i*").pack("U*") | |
28: data["array"][3] = data["array"][3].unpack("i*") | |
29: | |
=> 30: assert { data == origin } | |
31: end | |
32: end | |
========================================================================================================================================================================================================================== | |
Finished in 0.005539 seconds. | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
1 tests, 1 assertions, 1 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications | |
0% passed | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
180.54 tests/s, 180.54 assertions/s | |
Using msgpack 0.6.2 | |
Using bundler 1.11.2 | |
Bundle complete! 1 Gemfile dependency, 2 gems now installed. | |
Bundled gems are installed into ./.bundle. | |
"\x89\xA3foo\xA3bar\xA5ascii\xC4\x03bar\xA4utf8\xAF\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A\xA9bad_ascii\xC4\x0F\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A\xA6binary\xC4\x10R\x00\x00\x00u\x00\x00\x00b\x00\x00\x00y\x00\x00\x00\xA3int*\xA5float\xCB@\x02ffffff\xA5array\x94\xA6array1\x02\xCB@\b\x00\x00\x00\x00\x00\x00\xC4\x04\x04\x00\x00\x00\xA3map\x81\xA4hoge\xA4fuga" | |
0.6 -> 0.5 | |
Using msgpack 0.5.12 | |
Using power_assert 0.2.7 | |
Using bundler 1.11.2 | |
Using test-unit 3.1.7 | |
Bundle complete! 2 Gemfile dependencies, 4 gems now installed. | |
Bundled gems are installed into ./.bundle. | |
Loaded suite load | |
Started | |
F | |
========================================================================================================================================================================================================================== | |
Failure: | |
assert { data == origin } | |
| | | | |
| | {"foo"=>"bar", "ascii"=>"bar", "utf8"=>"あいうえお", "bad_ascii"=>"\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A", "binary"=>"Ruby", "int"=>42, "float"=>2.3, "array"=>["array1", 2, 3.0, [4]], "map"=>{"hoge"=>"fuga"}} | |
| false | |
{"foo"=>"bar", "ascii"=>"bar", "utf8"=>"あいうえお", "bad_ascii"=>"あいうえお", "binary"=>"Ruby", "int"=>42, "float"=>2.3, "array"=>["array1", 2, 3.0, [4]], "map"=>{"hoge"=>"fuga"}} | |
test_data(TestCase) | |
load.rb:30:in `test_data' | |
27: data["binary"] = data["binary"].unpack("i*").pack("U*") | |
28: data["array"][3] = data["array"][3].unpack("i*") | |
29: | |
=> 30: assert { data == origin } | |
31: end | |
32: end | |
========================================================================================================================================================================================================================== | |
Finished in 0.006196 seconds. | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
1 tests, 1 assertions, 1 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications | |
0% passed | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
161.39 tests/s, 161.39 assertions/s | |
0.6 -> 0.6 | |
Using msgpack 0.6.2 | |
Using power_assert 0.2.7 | |
Using bundler 1.11.2 | |
Using test-unit 3.1.7 | |
Bundle complete! 2 Gemfile dependencies, 4 gems now installed. | |
Bundled gems are installed into ./.bundle. | |
Loaded suite load | |
Started | |
. | |
Finished in 0.001391 seconds. | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications | |
100% passed | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
718.91 tests/s, 718.91 assertions/s | |
0.6 -> 0.7 | |
Using msgpack 0.7.4 | |
Using power_assert 0.2.7 | |
Using bundler 1.11.2 | |
Using test-unit 3.1.7 | |
Bundle complete! 2 Gemfile dependencies, 4 gems now installed. | |
Bundled gems are installed into ./.bundle. | |
Loaded suite load | |
Started | |
. | |
Finished in 0.001111 seconds. | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications | |
100% passed | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
900.09 tests/s, 900.09 assertions/s | |
Using msgpack 0.7.4 | |
Using bundler 1.11.2 | |
Bundle complete! 1 Gemfile dependency, 2 gems now installed. | |
Bundled gems are installed into ./.bundle. | |
"\x89\xA3foo\xA3bar\xA5ascii\xC4\x03bar\xA4utf8\xAF\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A\xA9bad_ascii\xC4\x0F\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A\xA6binary\xC4\x10R\x00\x00\x00u\x00\x00\x00b\x00\x00\x00y\x00\x00\x00\xA3int*\xA5float\xCB@\x02ffffff\xA5array\x94\xA6array1\x02\xCB@\b\x00\x00\x00\x00\x00\x00\xC4\x04\x04\x00\x00\x00\xA3map\x81\xA4hoge\xA4fuga" | |
0.7 -> 0.5 | |
Using msgpack 0.5.12 | |
Using power_assert 0.2.7 | |
Using bundler 1.11.2 | |
Using test-unit 3.1.7 | |
Bundle complete! 2 Gemfile dependencies, 4 gems now installed. | |
Bundled gems are installed into ./.bundle. | |
Loaded suite load | |
Started | |
F | |
========================================================================================================================================================================================================================== | |
Failure: | |
assert { data == origin } | |
| | | | |
| | {"foo"=>"bar", "ascii"=>"bar", "utf8"=>"あいうえお", "bad_ascii"=>"\xE3\x81\x82\xE3\x81\x84\xE3\x81\x86\xE3\x81\x88\xE3\x81\x8A", "binary"=>"Ruby", "int"=>42, "float"=>2.3, "array"=>["array1", 2, 3.0, [4]], "map"=>{"hoge"=>"fuga"}} | |
| false | |
{"foo"=>"bar", "ascii"=>"bar", "utf8"=>"あいうえお", "bad_ascii"=>"あいうえお", "binary"=>"Ruby", "int"=>42, "float"=>2.3, "array"=>["array1", 2, 3.0, [4]], "map"=>{"hoge"=>"fuga"}} | |
test_data(TestCase) | |
load.rb:30:in `test_data' | |
27: data["binary"] = data["binary"].unpack("i*").pack("U*") | |
28: data["array"][3] = data["array"][3].unpack("i*") | |
29: | |
=> 30: assert { data == origin } | |
31: end | |
32: end | |
========================================================================================================================================================================================================================== | |
Finished in 0.007517 seconds. | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
1 tests, 1 assertions, 1 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications | |
0% passed | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
133.03 tests/s, 133.03 assertions/s | |
0.7 -> 0.6 | |
Using msgpack 0.6.2 | |
Using power_assert 0.2.7 | |
Using bundler 1.11.2 | |
Using test-unit 3.1.7 | |
Bundle complete! 2 Gemfile dependencies, 4 gems now installed. | |
Bundled gems are installed into ./.bundle. | |
Loaded suite load | |
Started | |
. | |
Finished in 0.001303 seconds. | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications | |
100% passed | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
767.46 tests/s, 767.46 assertions/s | |
0.7 -> 0.7 | |
Using power_assert 0.2.7 | |
Using bundler 1.11.2 | |
Using msgpack 0.7.4 | |
Using test-unit 3.1.7 | |
Bundle complete! 2 Gemfile dependencies, 4 gems now installed. | |
Bundled gems are installed into ./.bundle. | |
Loaded suite load | |
Started | |
. | |
Finished in 0.00117 seconds. | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications | |
100% passed | |
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
854.70 tests/s, 854.70 assertions/s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment