The C++ Middleware Writer (CMW) used to have support for that
but I disabled it a few years ago. I used to pre-calculate
the "marshalling size" of messages. Then I'd marshall that size
followed by the message itself.
What I do now is reserve 4 bytes for the message size,
marshall the message into a buffer, and then calculate
the size of the message and place the size before the
message itself.
Here's an example where the message is just a message id.
inline void Marshal (::cmw::SendBuffer& buf
,messageid_t const& az1
,int32_t max_length=10000){
try{
buf.ReserveBytes(4);
buf.Receive(az1);
buf.FillInSize(max_length);
}catch(...){buf.Rollback();throw;}
}
There are pros and cons to both approaches. One con for
pre-calculating the size is that you have to iterate over
the message elements two times in order to marshal a message.
Another con was users of my software had to add an additional
function prototype, something like CalculateMarshallingSize,
to their classes.
A pro for pre-calculating is if the size of the message
exceeds your maximum for that message, you figure that out
before marshalling potentially a lot of data. I didn't find
that to be very compelling though so moved to the other
approach.
Brian
Ebenezer Enterprises - In G-d we trust.
http://webEbenezer.net