Alright, some code incoming..be warned

This is code which creates the file, I'll only paste the important parts

<code>

void WriteEntriesToFile(const string& path, .....other params here......)

{

    ofstream* stream = new ofstream(path.c_str(), ios::out | ios::binary);

    //.... check for stream validity here......

    OFStreamWriter* writer = new OFStreamWriter(stream); // my own class 
which is a copy of OStreamOutputStream

    ::google::protobuf::io::CodedOutputStream* codedOut =  new ::google::
protobuf::io::CodedOutputStream(writer);


    // Create new header

    HeaderPB* headerPB = new HeaderPB();


    unsigned int byteOffset = 0;

    HeaderPB::EntryPB* entryPB = NULL;


    // .... begin looping over instances of "MyMessage" to write to the file

    {

        entryPB = headerPB->add_resource_entry();


        entryPB->set_resource_size_bytes(myMessagePB->ByteSize());

        entryPB->set_resource_byte_offset_from_header(byteOffset);


        byteOffset += myMessagePB->ByteSize();

    }


    // Write out size of header and header

    codedOut->WriteLittleEndian32(headerPB->ByteSize());

    headerPB->SerializeToCodedStream(codedOut);   

    // PRINT("BYTE OFFSET TO END OF HEADER %d", codedOut->ByteCount());


    // Write out all the messages

    // Again, loop over the messages passed in

    {

        // PRINT("CURRENT OFFSET FROM BEGGING OF FILE %d", codedOut->
ByteCount());

        myMessagePB->SerializeToCodedStream(codedOut);

    }


    delete headerPB;

    delete codedOut;

    delete writer;

    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