class Object

Public Instance Methods

load_records(input, options) click to toggle source
# File bin/avro2json, line 8
def load_records(input, options)
  schema_path = options[:schema_path]
  schema = schema_path && Avro::Schema.parse(File.read(schema_path))
  Avro::DataFile::Reader.new(input, Avro::IO::DatumReader.new(nil, schema))
end
main() click to toggle source
# File bin/avro2json, line 14
def main
  options = {}

  option_parser = OptionParser.new do |opts|
    opts.banner = "Usage: avro2json [options]"

    opts.on("-sSCHEMA", "--schema=SCHEMA", "Use the specified schema file when decoding") do |schema|
      options[:schema_path] = schema
    end

    opts.on("-h", "--help", "Prints this help") do
      puts opts
      exit
    end
  end

  option_parser.parse!

  # Buffer the input in order to allow seeking -- otherwise Avro blows up.
  input = StringIO.new($stdin.read)
  records = load_records(input, options)

  records.each do |record|
    puts JSON.pretty_generate(record)
  end
end