[omniORB] Octet type

Sai-Lai Lo S.Lo@uk.research.att.com
29 Mar 2001 10:40:18 +0100


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