On Thu, 20 Apr 2000, Bruno Robin wrote:
'OMG IDL Syntax and Semantics' says : 'The octet type is an 8-bit
quantity that is guaranteed not to undergo any conversion when
transmitted by the communication system'.
Does it mean that octet type is only suitable for representing data like bit string for example ? If I want to pass integer values in the range [-128..+127], can I safely use an octet type or have I to use a short
type ? Same question if my integer values are only in the range
[0..+127] ?
Strictly speaking, you will have to use a short. If you don't mind living
a risky life, you can use octet. Basically, an octet is a blob of eight uninterpreted bits. If the sender and receiver use the same representation for numbers (two's complement, almost certainly), you can copy a short
into an octet, transmit it, and unpack it again at the other end. For numbers in the range 0..127, that's reasonably safe. A simple cast will do the
right thing.
If you want to transmit numbers in the range -128..127, it gets more complex because the C++ mapping doesn't state whether an octet is a char, unsigned char, or signed char. So, doing the naive thing and simply using a cast
might produce the wrong result because of sign extension.
Of course, these problems are surmountable. However, one of the reasons
for CORBA is precisely that you shouldn't have to worry about those kinds
of problems :-) I'd do what you are contemplating only if you are really desperate to save the bandwidth. (And you'd have to have an awful lot
of these small numbers to make it worthwhile.)
Cheers,
Michi.
--
Michi Henning +61 7 3891 5744
Object Oriented Concepts +61 4 1118 2700 (mobile)
Suite 4, 904 Stanley St +61 7 3891 5009 (fax)
East Brisbane 4169 michi@ooc.com.au
AUSTRALIA http://www.ooc.com.au/staff/michi-henning.html
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 294 |
Nodes: | 16 (2 / 14) |
Uptime: | 245:29:32 |
Calls: | 6,626 |
Calls today: | 2 |
Files: | 12,175 |
Messages: | 5,320,569 |