I wanted to build an awesome place for people to discuss module specific issues, but I don't have any more time for this, and there are much better places to discuss Perl-related issues. I'd recommend asking your question on Stack Overflow or on Perl Monks.
If you are looking for a Perl tutorial or Perl-related news, I hope these links will serve you well.
Posted on 2012-07-09 00:48:40.275593-07 by jcm
how to loop through different records from ProtoBuffers
Hello, trying my first steps with this handy lib, got the samples working, but having a hard time to find how to loop through different records ...
see my test code here, what am I doing wrong ?
at decoding/reading it only seems to find the last defined record
Thx a lot in advance for any suggestions
#--------------------------------- use Google::ProtocolBuffers; ##### Read definitions open (PR,"<Person.proto"); @pr=<PR>; $pr=join ' ',@pr; close(PR); #print "**$pr**\n"; ##### Interprete definitions Google::ProtocolBuffers->parse($pr, {create_accessors => 1 }, { generate_code => 'Foo.pm' } ); ##### Serialize Perl structure and print it to file open (PRO, ">person.dat"); binmode PRO; print PRO Person->encode({ name => 'A.U. Thor', id => 123, phone => [ { number => 1234567890 }, { number => 987654321, type=>Person::PhoneType::WORK() }, ], }); print PRO Person->encode({ name => 'JCM', id => 456, phone => [ { number => 234567890 }, { number => 87654321, type=>Person::PhoneType::WORK() }, ], }); close PRO; #### Decode data from serialized form my $person; open (PRO, "<person.dat"); binmode PRO; local $/; $person = Person->decode(<PRO>); #while($person) { print $person->name, "\n"; print $person->id, "\n"; print @{$person->phone}[0]->number, "\n"; #$person = Person->decode(<PRO>); } close PRO;
Direct Responses: Write a response