class RFlow::Avro

Utility methods for doing Avro encoding/decoding.

Public Class Methods

decode(reader, bytes) click to toggle source

Decode serialized Avro data. @param reader [::Avro::IO::DatumReader] reader preconfigured with schema @param bytes [String] byte string to decode @return decoded object

# File lib/rflow/message.rb, line 17
def self.decode(reader, bytes)
  reader.read ::Avro::IO::BinaryDecoder.new(StringIO.new(bytes.force_encoding('BINARY')))
end
encode(writer, message) click to toggle source

Encode data to serialized Avro. @param writer [::Avro::IO::DatumWriter] writer preconfigured with schema @param message [String] @return [String]

# File lib/rflow/message.rb, line 25
def self.encode(writer, message)
  String.new.force_encoding('BINARY').tap do |result|
    writer.write message, ::Avro::IO::BinaryEncoder.new(StringIO.new(result, 'w'))
  end
end