Skip to content

Instantly share code, notes, and snippets.

@jcreixell
Created December 18, 2015 15:42
Show Gist options
  • Save jcreixell/ccfca71da74d02d8d9ff to your computer and use it in GitHub Desktop.
Save jcreixell/ccfca71da74d02d8d9ff to your computer and use it in GitHub Desktop.
require 'avro'
SCHEMA = <<-JSON
{
"namespace": "com.test.avro.schemas",
"name": "MyEvent",
"type": "record",
"doc": "Some doc.",
"fields": [
{
"name": "tags",
"type": {
"type": "array",
"items": "string"
},
"doc": "Something."
}
]
}
JSON
schema = Avro::Schema.parse(SCHEMA)
writer = Avro::IO::DatumWriter.new(SCHEMA)
output = StringIO.new
dw = Avro::DataFile::Writer.new(output, writer, schema)
dw << { 'tags' => ['a', 'b'] }
dw.close
p output.string
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment