I created some code that puts 10 GPB messages into a file. When I look at
the file with a hex editor all of the messages are in the file.
I now want to read the messages back in, processing them 1 at a time. The
following produces only the last record in the input file. What am I
missing? How do I read each message individually?
Yes I know the below is an infinite loop.
require 'protobuf/message/message'
require 'protobuf/message/enum'
require 'protobuf/message/service'
require 'protobuf/message/extend'
module Test
class Interface < ::Protobuf::Message
defined_in __FILE__
required :string, :name, 1
optional :bool, :deleted, 2
end
class System < ::Protobuf::Message
defined_in __FILE__
required :string, :name, 1
optional :bool, :deleted, 2
end
class Rec < ::Protobuf::Message
defined_in __FILE__
optional :uint32, :timestamp, 1
optional :System, :system, 2
repeated :Interface, :interface, 3
end
end
jrec = Test::Rec.new
counter = 1
file = File.open("test", "r")
while (jrec.parse_from_file(file))
puts "#{jrec.system.name}: #{counter}"
counter = counter + 1
end
file.close
if I do a jrec.display, the last message in the file is what I see.
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.