Class: Avrocado::Serializer

Inherits:
Object
  • Object
show all
Defined in:
lib/avrocado/serializer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, schema = Schema.parse) ⇒ Serializer

Returns a new instance of Serializer.



5
6
7
8
# File 'lib/avrocado/serializer.rb', line 5

def initialize(message, schema = Schema.parse)
  @message = message
  @schema  = schema
end

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



3
4
5
# File 'lib/avrocado/serializer.rb', line 3

def message
  @message
end

#schemaObject (readonly)

Returns the value of attribute schema.



3
4
5
# File 'lib/avrocado/serializer.rb', line 3

def schema
  @schema
end

Class Method Details

.serialize(message) ⇒ Object



10
11
12
# File 'lib/avrocado/serializer.rb', line 10

def self.serialize(message)
  new(message).serialize
end

Instance Method Details

#serializeObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/avrocado/serializer.rb', line 14

def serialize
  message.each do |field, value|
    record.put(field.to_s, value)
  end

  writer.write(record, encoder)

  encoder.flush

  output.to_byte_array
end