class RubyEventStore::Protobuf::Mappers::Transformation::ProtobufEncoder

Public Instance Methods

dump(record) click to toggle source
# File lib/ruby_event_store/protobuf/mappers/transformation/protobuf_encoder.rb, line 8
def dump(record)
  Record.new(
    event_id:   record.event_id,
    event_type: record.event_type,
    data:       encode_data(record.data),
    metadata:   record.metadata,
    timestamp:  record.timestamp,
    valid_at:   record.valid_at,
  )
end
load(record) click to toggle source
# File lib/ruby_event_store/protobuf/mappers/transformation/protobuf_encoder.rb, line 19
def load(record)
  Record.new(
    event_id:   record.event_id,
    event_type: record.event_type,
    data:       load_data(record.event_type, record.data),
    metadata:   record.metadata,
    timestamp:  record.timestamp,
    valid_at:   record.valid_at,
  )
end

Private Instance Methods

encode_data(data) click to toggle source
# File lib/ruby_event_store/protobuf/mappers/transformation/protobuf_encoder.rb, line 31
def encode_data(data)
  begin
    data.class.encode(data)
  rescue NoMethodError
    raise ProtobufEncodingFailed
  end
end
load_data(event_type, protobuf_data) click to toggle source
# File lib/ruby_event_store/protobuf/mappers/transformation/protobuf_encoder.rb, line 39
def load_data(event_type, protobuf_data)
  Google::Protobuf::DescriptorPool.generated_pool.lookup(event_type).msgclass.decode(protobuf_data)
end