comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos" <david.c.hoos.sr@ada95.com>
To: <comp.lang.ada@ada.eu.org>
Cc: <Vladimir.Bednikov@ebor.com>
Subject: Re: converting floats, ints byte arrays
Date: Fri, 13 Jul 2001 06:34:05 -0500
Date: 2001-07-13T06:34:05-05:00	[thread overview]
Message-ID: <mailman.995024059.4732.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: 9ije24$9kg$1@fang.dsto.defence.gov.au

Hi Vladimir,

Based on your earlier queries about the adasockets package,
I am answering your question in the context of adacokets.

If, after creating the socket and establishing the connection,
you call Sockets.Stream_IO.Initialize, that call will associate
a stream with the connected socket.

Then if your data is placed in an Ada record declared
like this:

type my_type is record
   sampleRate : C.C_Float;
   scalingFactor : C.C_Float;
   numSamples : C.Unsigned;
   numSensors : C.Unsigned;
   positionChanged : C.Unsigned_Char;
   groupBySensors : C.Unsigned_Char;
end record;

My_Object : My_Type;

Then, when my_object is populates with the values you can
simply write

My_Type'Write (Stream, My_Object);

where Stream is the stream object associated with the socket
by calling Initialize.

This will create the TCP packet just as you specified.

This is demonstrated in the adasockets examples directory
in the program stream_sender.adb.

----- Original Message -----
From: "Vladimir Bednikov" <Vladimir.Bednikov@ebor.com>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Thursday, July 12, 2001 12:46 AM
Subject: converting floats, ints byte arrays


> Hi all,
>
> I have a bunch of values I want to send via tcp, instead of converting
> each to a string and sending it out, I want to store all the values into
> a byte array, ie:
> type byte is mod 256;
> type byte_array is array(integer range <>) of byte;
>
> The values are for example,
>
> sampleRate : C.C_Float;
> scalingFactor : C.C_Float;
> numSamples : C.Unsigned;
> numSensors : C.Unsigned;
> positionChanged : C.Unsigned_Char;
> groupBySensors : C.Unsigned_Char;
>
> What I want is an array where the first C.C_Float'size bytes is the sample
> rate,
> the next C.C_Float'size bytes is the scaling factor, the next
> C.Unsigned'size bytes
> is the number of samples etc and finally send the byte array out via tcp.
>
> Does anybody out there know of a way to do this.
>
> All help is appreciated,
> Thanks in advance
>
>
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>




      parent reply	other threads:[~2001-07-13 11:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-12  5:46 converting floats, ints byte arrays Vladimir Bednikov
2001-07-12  6:45 ` tmoran
2001-07-12 16:35 ` Jeffrey Carter
2001-07-13 11:34 ` David C. Hoos [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox