[omniORB] Octet type

Huw Rogers count0@building2.co.jp
Tue, 10 Apr 2001 23:22:45 +0900


As far as I can envision, it's impossible
to have &seq[0] not be exactly equivalent to
seq.get_buffer() while remaining compliant
with C++ language and the CORBA
language binding. This is for all seq, not
just CORBA::Octet sequences.

As for CORBA::Octet, it pretty much
has to be type defined to char or unsigned char
with CHAR_BIT having to be 8. Could there be
a compliant binding implementation if chars are
16 or 32 bits? (there are apparently some such
curious platforms and ISO C ridiculously permits such
wierdness). It occurs to use an explicitly 8 bit
bitfield wrapped in a struct, but alignment issues
would cause trouble.

    -Huw

Sai-Lai Lo wrote:

> A better (portable) way to get to the buffer is to use get_buffer().
>
> click_router::bytestream_var errors = new click_router::bytestream;
> errors-> length(2000);           // start length of 2000 octets
>
> CORBA::Octet* buffer = errors->get_buffer(); // the buffer is still memory
>                                              // managed by the sequence.
>
> Sai-Lai
>
> >>>>> Huw Rogers writes:
>
> > This is way inefficient. You can directly
> > access &(*errors)[0] to get the start
> > of the 2000 byte buffer, and fill it directly
> > with one read, then set the length. No
> > need for a loop.
>
> >     -Huw
>
> > Brecht Vermeulen wrote:
>
> >> Michel,
> >>
> >> this code does this (bytestream is a sequence of octets) :
> >>
> >>
> >> click_router::bytestream_var errors = new click_router::bytestream;
> >>
> >>
> >> // now read the errors and return them
> >> ifstream errors_file(CLICK_ERRORS);
> errors-> length(2000);           // start length of 2000 octets
> >>
> >> CORBA::Octet ch;
> >> CORBA::ULong i=0;
> >> while(errors_file.get(ch) ) {
> >> if (i>errors->length()-1) errors->length(i+500);
> >> errors[i++] = ch;
> >> };
> >>
> errors-> length(i);
> >>
> >> errors_file.close();
> >>
> >> return errors._retn();
> >>
> >> best regards,
> >> Brecht
> >>
> >> Miguel wrote:
> >> >
> >> > Hi
> >> >
> >> > I have to transmit a texture from a server to a client. It can be in
> >> > different formats (such as .rgb, .jpg, .gif...) so I've decided to
> >> > send all of them as a sequence of octets. The problem is that I don't have
> >> > a good knowledge about using the octet type, so
> >> > I don't know how to read data from the file and convert it to an octet (and
> >> > how to convert an octet to data) (perhaps with
> >> > a simple cast??)
> >> >
> >> > Any suggestion or info about the octet type?
> >> >
> >> > Thank you very much.
> >> >
> >> > Bye.
>
> --
> Sai-Lai Lo                                   S.Lo@uk.research.att.com
> AT&T Laboratories Cambridge           WWW:   http://www.uk.research.att.com
> 24a Trumpington Street                Tel:   +44 1223 343000
> Cambridge CB2 1QA                     Fax:   +44 1223 313542
> ENGLAND