comp.lang.ada
 help / color / mirror / Atom feed
From: "Steve" <nospam_steved94@attbi.com>
Subject: Re: Access to array slices?
Date: Wed, 15 Jan 2003 14:44:19 GMT
Date: 2003-01-15T14:44:19+00:00	[thread overview]
Message-ID: <7teV9.60727$No.7357@sccrnsc04> (raw)
In-Reply-To: 5ad0dd8a.0301141717.2f1a9685@posting.google.com

"Wojtek Narczynski" <wojtek@power.com.pl> wrote in message
news:5ad0dd8a.0301141717.2f1a9685@posting.google.com...
> Hello,
>
> I am trying to develop a library that reads C structures from socket
> and interpret them.
>
> At some point I have a structure (stream?) on stack that contains
> multiple strings inside. It's something like [name_length,
> value_length, name, value]* mean an unknown number of such name-value
> pairs. I am able to access it as String using the 'Address clause, but
> now I either have to copy the strings out, or obtain (deadly unsafe,
> not portable, nobody knows why) Access'es to slices of this array.
>

The first thing I would do is forget that the data comes from C structures,
since from what you have described that is unimportant.  The code to read
one of these structures would look something like:

   Get( socket, name_length );
   Get( socket, value_length );
   declare
     name : string( 1 .. name_length );
     value : string( 1 .. value_length );
   begin
     Get( socket, name );
     Get( socket, value );
     Do_Something_With_Data( name, value );
   end;

You may have to tweak this depending on whether the strings in your data
stream have null terminators and whether the the lengths include the
terminators.

This assume you have overloaded functions for reading lengths and strings
from a socket, which are easy to create if you don't already have them.  You
could also use Ada streams.

When I look at an interface specification for messages sent using sockets, I
hate to see the specification described in terms of C structures.  I much
prefer a language independent data specification.  Even if communication is
between two C programs, the compiler(s) may do different things depending on
architecture, vendor or compiler switches.  In fact when dealing with a
network I make it a point to put things into network byte order.

I hope this helps,
Steve
(The Duck)





  parent reply	other threads:[~2003-01-15 14:44 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-15  1:17 Access to array slices? Wojtek Narczynski
2003-01-15  3:13 ` tmoran
2003-01-15 16:31   ` sk
2003-01-15 20:48     ` tmoran
2003-01-16  1:00       ` sk
2003-01-16  1:43         ` tmoran
2003-01-19  4:06     ` David Thompson
2003-01-15 14:44 ` Steve [this message]
2003-01-16  2:18   ` Wojtek Narczynski
2003-01-16  3:52     ` tmoran
2003-01-17 18:04     ` Warren W. Gay VE3WWG
2003-01-15 15:06 ` Stephen Leake
2003-01-16  2:02   ` Wojtek Narczynski
2003-01-16 16:18     ` Stephen Leake
2003-01-16 16:48 ` Victor Porton
2003-01-19  4:32 ` sk
2003-01-27  2:59   ` David Thompson
2003-01-24 19:02 ` Wojtek Narczynski
replies disabled

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