[omniORB] Serialize a sequence of ANY

Sai-Lai Lo S.Lo@orl.co.uk
27 Jan 1999 16:01:11 +0000


>>>>> Byrne Matt writes:

>      How can I Serialize a sequence of ANY's in order to save them to a 
>      file without using the MemBufferedStream.  I am new to CORBA so excuse 
>      me if this is not an appropriate question.
     
Now I see where you are coming from! There is nothing in the CORBA core to
allow you to do that. I suppose something like the externalization service
can do it but you do not have the luxury to have one.

A practical solution, which you are already using, is to serialise the
values into a CDR stream (a byte stream that encode all data according to
the rules that are part of GIOP) and then extract the value out again as if
it is a byte stream. The MemBufferedStream class is indeed one such CDR
stream.

See if the following psuedo code works for you:

SeqAny_t val;

MemBufferedStream m;

val >>= m;

CORBA::ULong count = m.unRead();

while (count--) {
  CORBA::Octet v;
  v <<= m;
  StoreOctetToFileAsHex(v);
}

---------------
And the reverse:

MemBufferedStream m;
CORBA::Octet v;

while (ReadOctetFromFile(v)) {
   v >>= m;
}

SeqAny_t val;

val <<= m;


If you have to do this, be careful to isolate this bit of code and
carefully comment this to be omniORB2 specific. (In future versions,
MemBufferedStream will be replaced with a more generic cdr stream
object.)


Regards,


Sai-Lai


     
     
     


-- 
Dr. Sai-Lai Lo                          |       Research Scientist
                                        |
E-mail:         S.Lo@orl.co.uk          |       Olivetti & Oracle Research Lab
                                        |       24a Trumpington Street
Tel:            +44 223 343000          |       Cambridge CB2 1QA
Fax:            +44 223 313542          |       ENGLAND