CBOR::Any test.

any
Karchnu 2020-11-23 12:38:06 +01:00
parent ec1699aa25
commit cc81454013
1 changed files with 30 additions and 0 deletions

30
cbor-any.cr Normal file
View File

@ -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