0
std::ostringstream oss;
boost::archive::text_oarchive oa(oss); 

I add variable number of content to this oa, like this

    oa & int1;
    oa &int2;
--------------------> insert number of matrices here
    oa & matrix1;
    ..//do some processing
    oa & matrix2; 
    ...//do some more
    ....
    oa & matrixn;

matrix ref - http://robot.kaist.ac.kr/haptics/chai3d-2.0.0_Doc/resources/html/structc_matrix3d.html

Now at the end when I am finished, I want to insert the number of matrices I added to this archive before I started adding matrices before udp sending it. But I also know how many matrices I added, after I added them to the stream

How should I do this?

1 Answers1

0

You cannot do

oa & matrix1.

To do so matrix has to be a simple type (which it is not) or implement the function serialize. You can override matrix implement serialize and then use this.

This is a good ref: http://www.boost.org/doc/libs/1_54_0/libs/serialization/doc/tutorial.html

You can actualy start with oss << (int)0; then after you write everything seekp back to the beginning and rewrite the first 4 bytes with the number of items you added.

madnut
  • 124
  • 5
  • You mean u implemented serialize? – madnut Jul 17 '13 at 07:51
  • I see i guess i don't understand the question then. Can you more clearly explain what you want to insert... why cant you just do oa & numerofthingsuadded; – madnut Jul 17 '13 at 07:56
  • I add n number of objects to this, and I want to add this n before those n objects in the stream, so that when I deserialiye I know how much data to expect –  Jul 17 '13 at 07:57
  • but you don't know n until you have already added them all? If so you can do something hacky like seek the oss back to the beginning and overwrite the data. std::basic_ostream::seekp – madnut Jul 17 '13 at 07:59