Re: Using GNAT.Sockets with Streams and Byte Swapping



On Thu, 2005-05-26 at 02:28 -0700, markp wrote:
> Thanks for your reply. I have one question. In order to write my own
> 'Write and 'Read subprograms, would I have to change GNAT.Sockets and
> rebuild the runtime? Or, is there an easier way?

The usual answer is that you should write your own 'Read and 'Write
routines. However recent versions of GNAT support the machine
independent XDR representation, which may be what you want. The
GNAT reference manual says:

13.13.2(17): Stream Oriented Attributes

If a stream element is the same size as a storage element, then the normal in-memory representation should be used by Read and Write for
scalar objects. Otherwise, Read and Write should use the smallest number of stream elements needed to represent all values in the base range
of the scalar type.

Followed. By default, GNAT uses the interpretation suggested by AI-195, which specifies using the size of the first subtype. However, such an
implementation is based on direct binary representations and is therefore target- and endianness-dependent. To address this issue, GNAT also
supplies an alternate implementation of the stream attributes Read and Write, which uses the target-independent XDR standard representation
for scalar types. The XDR implementation is provided as an alternative body of the System.Stream_Attributes package, in the file
`s-strxdr.adb' in the GNAT library. There is no `s-strxdr.ads' file. In order to install the XDR implementation, do the following:
1. Replace the default implementation of the System.Stream_Attributes package with the XDR implementation. For example on a Unix platform
issue the commands:


$ mv s-stratt.adb s-strold.adb
$ mv s-strxdr.adb s-stratt.adb

2. Rebuild the GNAT run-time library as documented in the GNAT User's Guide


.



Relevant Pages

  • Re: Largest size array in Gnat 2005 for the PC?
    ... GNAT executables then you could use up to 3Gb of memory. ... For the case of a pointer to an unconstrained ... array type (where the bounds may vary from one value of the access ... When using this representation, the bounds are right behind the array. ...
    (comp.lang.ada)
  • Re: Largest size array in Gnat 2005 for the PC?
    ... -- With the following info from GNAT Users Guide, ... For the case of a pointer to an unconstrained ... array type (where the bounds may vary from one value of the access ... When using this representation, the bounds are right behind the array. ...
    (comp.lang.ada)