home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.ada
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!saimiri.primate.wisc.edu!ames!nsisrv!robots!nbssal
- From: nbssal@robots (Stephe Leake)
- Subject: Re: Can this data be represented in Ada?
- Message-ID: <4JAN199313495649@robots>
- News-Software: VAX/VMS VNEWS 1.4-b1
- Sender: usenet@nsisrv.gsfc.nasa.gov (Usenet)
- Nntp-Posting-Host: robots.gsfc.nasa.gov
- Organization: NASA Goddard Robotics Lab
- References: <1992Dec31.014719.22174@nosc.mil> <SDL.92Dec31182221@rigel.linus.mitre.org>
- Date: Mon, 4 Jan 1993 18:49:00 GMT
- Lines: 81
-
- In article <1992Dec31.014719.22174@nosc.mil> psm@nosc.mil (Scot Mcintosh) writes:
-
- > I'm implementing a data communications protocol that has some data
- > structural features that don't look possible to implement in Ada.
- > Perhaps someone more experienced can suggest a way to accomplish
- > what I'm trying to do (changing the protocol is not an option).
- >
- > A Transmission Unit looks like:
- >
- > +---------+----------+-----------+------+
- > | Packet | Packet1 | Packet2 | etc |
- > | Length | | | ... |
- > +---------+----------+-----------+------+
- > | |<-------->|<--------->|
- > | ^ ^
- > | | |
- > |__________|__________+
- >
- >
- > Each Packet looks like:
- >
- > +---------+----------+--------------+
- > | Data | Data | Padding |
- > | Length | |(i.e. nothing)|
- > +---------+----------+--------------+
- > | | |<--------> |
- > | | ^ |
- > | | | |
- > | |__________| |
- > | |
- > |<--------------------------------->|
- > Packet Length
- >
- > For a given transmission, the Packet Length is fixed, but can be
- > different in the next transmission. The Data Length within each
- > Packet can be different for each Packet.
-
- In article <SDL.92Dec31182221@rigel.linus.mitre.org>, sdl@linus.mitre.org (Steven D. Litvintchouk) writes...
- >
- >You didn't happen to state how you know when you have read in all the
- >packets for a given Transmission Unit--is there some
- >"end-of-transmission" indicator?
- >
- >You didn't happen to state how "data length" is related to "data".
- >I'll assume that "data" is in the form of a stream of bytes; and
- >that "data length" and "packet length" are two-byte integers giving
- >the number of bytes in Data and Packet, respectively.
- >
- > type BYTE is range 0 .. 255;
- > for BYTE'SIZE use 8;
- > subtype DATA_BYTE is BYTE;
- >
- > type LENGTH is range 0 .. 50000; -- or whatever
- > for LENGTH'SIZE use 16;
- >
- > DATA_LENGTH, PACKET_LENGTH: LENGTH;
- >
- >I suggest it's easier to simply define everything as an
- >undifferentiated stream of bytes, and use UNCHECKED_CONVERSION to
- >extract the more complicated, higher-level structure after you read in
- >the needed bytes.
- > ...
- >So you can read the first two bytes, and then use UNCHECKED_CONVERSION
- >to convert it to the integer type LENGTH. Then that's the Packet
- >Length; you know you must read in that number of bytes for each
- >subsequent packet. So for each subsequent packet, read in a number of
- >bytes given by Packet Length; use UNCHECKED_CONVERSION to convert the
- >first two bytes to an integer (which represents Data Length); then
- >process that number of subsequent bytes as Data, ignoring the rest.
- >
-
- This is a valid way to PROCESS the data, but it is not a way to REPRESENT the
- data structure. I tried a couple approaches involving unconstrained arrays, but
- since the max length of a packet is specified at run time, it cannot be static.
- Thus this structure is not REPRESENTABLE in Ada. As an Ada advocate, my
- reaction to this is twofold; first, there is probably a better data structure
- that is representable. Second, at least Ada can process the data in a
- reasonable way; maybe actually representing the structure is not required.
- There are certainly other applications (complex cross-linked lists) where the
- actual structure is only partly represented by Ada types.
-
-