I need to serialize lots of objects to a file (multiple GBs). We have chosen to use Google's protocol buffers for other things in this project, so I thought I would use that to serialize the objects I receive from the wire. This seems to work:
File.open(file_name, 'ab') do |f|
some_objects.each { |some_object|
some_object.serialize(f)
}
end
The deserializtion is what is giving me issues. I have seen others do one object like this:
File.open(file_name, 'r') do |f|
no = some_object.parse(f)
end
But that only does one. I tried doing this:
File.open(file_name, 'r').each do |f|
no = some_object.parse(f)
end
But that raised this exception:
Uncaught exception: undefined method `<<' for false:FalseClass
I need to get all of them and lazily evaluate them. Any thoughts? Please feel free to give any advice on performace of this code since I'll be doing GBs of info. Thanks for your time.
By the way, I know I need to upgrade my ruby version, but since this is an internal thing I haven't been able to get time from the boss to upgrade it.
I am using ruby-protocol-buffers