I am new to GPB and a bit new to ruby, but the project I am working on 
requires ruby.

I have successful installed the protocol_buffer gem and successfully 
generated a test file with 10 GPB messages in it. I have verified with a 
hex editor that all 10 messages are in the file.

Now I want to read the messages back in and process them. Regardless of how 
I try to read the message file, I always only get the last message. I have 
tried several different ways and I am stuck.

Here is the last snippet and yes I know it's a infinite loop, but at this 
point it doesn't matter. I still only get the last message.

Could someone point me to a example of how to read the messages 1 at time 
until there are no more messages?  if not in ruby, then in python.


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
  class System < ::Protobuf::Message
    defined_in __FILE__
    required :string, :name, 1
  class Rec < ::Protobuf::Message
    defined_in __FILE__
    optional :uint32, :timestamp, 1
    optional :System, :system, 2
    repeated :Interface, :interface, 3

jrec = Test::Rec.new
counter = 1
file = File.open("testdata", "r")
while (jrec.parse_from_file(file))
   puts "#{jrec.system.name}: #{counter}"
   counter = counter + 1

When I do a jrec.display it also only shows the last message from the file.

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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to