More code. This is the parsing code

<code>

void GetMessagesFromFile(const string& path)

{

    ifstream* stream = new ifstream(path.c_str(), ios::in | ios::binary);

    unsigned int endOfHeaderOffset = 0;

    // read_header_from_file just reads the HeaderPB and computes 
endOfHeaderOffset,

    // via CodedInputStream CurrentPosition once parsing of header size and 
header is done.

    // yes, read_header_from_file uses limits on the coded stream to not 
keep parsing

    HeaderPB* header = read_header_from_file(path, stream, 
endOfHeaderOffset);

    // Loop over the entries in the header

    if ( 0 < header->entry_size() )

    {

        // Loop over all entries

        MyMessagePb* myMessagePB = NULL;

        IFStreamReader* reader = NULL;

        ::google::protobuf::io::CodedInputStream* coded = NULL;


        // Loop from an index of 0 to header->entry_size()

        {

            const HeaderPB::EntryPB& entryProtoBuff = header->entry
(entryIndex);

            ::google::protobuf::uint32 entrySize = entryProtoBuff.entry_
size_bytes();

            ::google::protobuf::uint32 entryOffset = entryProtoBuff.entry
_byte_offset_from_header();

                    

            // Put stream at byte offset and created IFStreamReader and 
CodedInputStream

            // PRINT("BYTE OFFSET ON READING FROM BEGGING OF FILE %d", 
endOfHeaderOffset + entryOffset);

            stream->seekg(endOfHeaderOffset + entryOffset, stream->beg);

            reader = new IFStreamReader(stream);

            coded = new ::google::protobuf::io::CodedInputStream(reader);


            ::google::protobuf::io::CodedInputStream::Limit oldLimit = 
coded->PushLimit(entrySize);

                    

            myMessagePB = new MyMessagePB();

            if ( myMessagePB->ParseFromCodedStream(coded) )

            {

                // Code reaches this point, but all data in myMessagePB is 
null/not available via "has_xxxxx" function

                // .... Do other stuff here......

            }                    

            coded->PopLimit(oldLimit);

                    

            delete coded;

            delete reader;

        }

    }

    delete header;

    delete stream;

}

</code>

-- 
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