Last active
June 28, 2017 04:32
-
-
Save jcward/106e68eb376db0c0649e to your computer and use it in GitHub Desktop.
RocketAMF can de/serialize AMF serialized byte streams, but it throws (at least, the 0.2.1 version from gem install throws) when it encounters an IExternalizable type in the byte steam. This patch allows it to parsed custom IExternalizable classes properly.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'rocketamf' | |
require 'stringio' | |
# Monkey patch for RocketAMF (0.2.1 gem) that handles IExrternalizable types | |
# in the input, storing their type as "__as3_type" parameter: | |
module RocketAMF | |
module Values #:nodoc: | |
class TypedHash | |
def externalized_data= obj | |
obj.each { |k,v| | |
self[k] = v | |
} | |
self["__as3_type"] = @type | |
end | |
end | |
end | |
end | |
if (ARGV.length==0) then | |
puts "usage: print_amf.rb <infile.amf>" | |
exit | |
end | |
# And a little command-line utility for printing AMF as JSON | |
require 'json' | |
puts JSON.pretty_generate RocketAMF.deserialize(File.read(ARGV[0]), 3) |
This file contains hidden or 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
#!/usr/bin/env ruby | |
# Utility to convert .json or .yaml files to .amf | |
require 'json' | |
require 'yaml' | |
require 'rocketamf' | |
infile = ARGV[0] | |
outfile = ARGV[1] | |
if (infile==nil || outfile==nil) then | |
puts "usage: to_amf.rb <json_or_yaml_file> <outfile.amf>" | |
exit | |
end | |
if (infile.match(/\.yaml$/)) then | |
File.open(outfile, 'wb') { |file| file.write RocketAMF.serialize(YAML.load(IO.read(infile)), 3) } | |
elsif (infile.match(/\.json$/)) then | |
File.open(outfile, 'wb') { |file| file.write RocketAMF.serialize(JSON.parse(IO.read(infile)), 3) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment