comp.lang.ada
 help / color / mirror / Atom feed
From: "David C. Hoos" <david.c.hoos.sr@ada95.com>
To: "comp.lang.ada mail to news gateway" <comp.lang.ada@ada.eu.org>
Subject: Re: Hints for networking
Date: Fri, 31 Jan 2003 15:21:34 -0600
Date: 2003-01-31T15:21:34-06:00	[thread overview]
Message-ID: <mailman.4.1044048101.3911.comp.lang.ada@ada.eu.org> (raw)
In-Reply-To: MPG.18a4c4d14186a6f598968c@News.CIS.DFN.DE

Hi Jano,

I have written many many network protocol representations
using Ada95 streams.  The elegance of Ada Streams, and
the simplicity of their use once you have made the effort to
properly define your types and their stream attributes really
makes the effort worthwhile.  Here are some hints and rules
needed to do this successfully: These rules are based on
the presumption that there is a specific network representation
required by your protocol.

   1,  This rule number 1 is very important.  NEVER base
         any value written to a stream on the standard Ada type
         Integer.  
         You should always define project-specific types that
         do not depend on implementations that are subject to
         variation between compilers or platform types.  For
         example, you can base integer types on those available
         in the package Interfaces -- Integer_16, Unsigned_16, etc.
         That's what the Interface package is for -- i.e. to permit
         writing portable code for interfaces.

    2.  You need to write stream attributes for multi-octet numbers
         that respect the bendiness of your platform.  Even when
         you've been told that "this only has to run on Sparc," sooner
         or later your code will also need to run on Intel, so I've
         always taken the trouble to deal with bendiness.

   3.  All objects written to a stream must have a 'Size that is an
        integer multiple of 8.  So, if you have an octet with two four-bit
        fields, I make them into a record type, and write the stream
        attributes for that record.  I've done things like a record that
        has a 31-bit field, and a 1-bit field.  

Happy streaming!

David Hoos
 
----- Original Message ----- 
From: "Jano" <402450@cepsz.unizar.es>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Friday, January 31, 2003 10:37 AM
Subject: Hints for networking


> Hello everybody.
> 
> I'm about to program a networking package for the first time in Ada and 
> am somewhat undecided the way to go. I'd like to hear some pointers for 
> examples or hints.
> 
> The protocol has some fixed-size packets and others of unknown size (but 
> with known headers which contains the full size). I'm wondering what 
> representation clauses could help me, if any. Also, I've my doubts about 
> streams, because in the past I've tried them to write files and in Gnat 
> I couldn't manage to output exact sized types except uncheckedconverting 
> them into byte arrays. For example an integer subtype with 
> representation clauses for 16 bits was always dumped as its base type, 
> i.e. 32 bits. Frankly, the RM is too dense for me so some beginner 
> documentation would be very useful.
> 
> I've read some tutorials and books from adapower lately but can't find 
> something more on the subject. Clues welcomed.
> 
> TIA,
> 
> -- 
> -------------------------
> Jano
> 402450[at]cepsz.unizar.es
> -------------------------
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
> 



  parent reply	other threads:[~2003-01-31 21:21 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-01-31 16:37 Hints for networking Jano
2003-01-31 18:40 ` tmoran
2003-01-31 21:21 ` David C. Hoos [this message]
2003-02-01 19:29   ` Jano
2003-02-02  7:43     ` Simon Wright
2003-02-01 18:32 ` Alfred Hilscher
replies disabled

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