CBOR::Any test.
parent
ec1699aa25
commit
cc81454013
|
@ -0,0 +1,30 @@
|
|||
require "json"
|
||||
require "./src/cbor"
|
||||
|
||||
j = JSON.parse(%({"access": [{"name": "mapping", "speed": "fast"}, {"name": "any", "speed": "slow"}]}))
|
||||
# j["access"][1]["name"].as_s # => "any"
|
||||
# j["access"][1]["speed"].as_s # => "slow"
|
||||
|
||||
|
||||
pp! c = CBOR::Any.new JSON.parse(%({"access": [{"name": "mapping", "speed": "fast"}, {"name": "any", "speed": "slow"}]}))
|
||||
pp! c["access"][1]["name"].as_s # => "any"
|
||||
pp! c["access"][1]["speed"].as_s # => "slow"
|
||||
|
||||
hash = {"access" => [
|
||||
{"name" => "mapping",
|
||||
"speed" => "fast"},
|
||||
{"name" => "any",
|
||||
"speed" => "slow"}]}
|
||||
pp! c = CBOR::Any.new hash.to_cbor
|
||||
pp! c["access"][1]["name"].as_s # => "any"
|
||||
pp! c["access"][1]["speed"].as_s # => "slow"
|
||||
|
||||
json_any_to_cbor_file = "#{ARGV[0]}.json.cbor"
|
||||
cbor_any_to_cbor_file = "#{ARGV[0]}.cbor"
|
||||
|
||||
puts "JSON value in file: #{json_any_to_cbor_file}"
|
||||
File.write json_any_to_cbor_file, j.to_cbor
|
||||
|
||||
puts "CBOR value in file: #{cbor_any_to_cbor_file}"
|
||||
File.write cbor_any_to_cbor_file, c.to_cbor
|
||||
|
Loading…
Reference in New Issue