home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / ada / 3866 < prev    next >
Encoding:
Text File  |  1993-01-04  |  3.6 KB  |  100 lines

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!gatech!usenet.ins.cwru.edu!agate!linus!linus.mitre.org!linus!sdl
  3. From: sdl@linus.mitre.org (Steven D. Litvintchouk)
  4. Subject: Re: Can this data be represented in Ada?
  5. In-Reply-To: psm@nosc.mil's message of Thu, 31 Dec 1992 01:47:19 GMT
  6. Message-ID: <SDL.92Dec31182221@rigel.linus.mitre.org>
  7. Sender: news@linus.mitre.org (NONUSER)
  8. Nntp-Posting-Host: rigel.mitre.org
  9. Organization: The MITRE Corporation, Bedford, MA
  10. References: <1992Dec31.014719.22174@nosc.mil>
  11. Date: Thu, 31 Dec 1992 23:22:21 GMT
  12. Lines: 86
  13.  
  14.  
  15. In article <1992Dec31.014719.22174@nosc.mil> psm@nosc.mil (Scot Mcintosh) writes:
  16.  
  17. > I'm implementing a data communications protocol that has some data
  18. > structural features that don't look possible to implement in Ada.
  19. > Perhaps someone more experienced can suggest a way to accomplish
  20. > what I'm trying to do (changing the protocol is not an option).
  21. > A Transmission Unit looks like:
  22. > +---------+----------+-----------+------+
  23. > | Packet  |  Packet1 |  Packet2  | etc  |
  24. > | Length  |          |           |  ... |
  25. > +---------+----------+-----------+------+
  26. >     |     |<-------->|<--------->|
  27. >     |          ^          ^
  28. >     |          |          |
  29. >     |__________|__________+
  30. > Each Packet looks like:
  31. > +---------+----------+--------------+
  32. > | Data    |  Data    |  Padding     | 
  33. > | Length  |          |(i.e. nothing)| 
  34. > +---------+----------+--------------+
  35. > |   |     |<-------->               |
  36. > |   |          ^                    |
  37. > |   |          |                    |
  38. > |   |__________|                    |
  39. > |                                   |
  40. > |<--------------------------------->|
  41. >     Packet Length
  42. > For a given transmission, the Packet Length is fixed, but can be
  43. > different in the next transmission. The Data Length within each
  44. > Packet can be different for each Packet. 
  45.  
  46. You didn't happen to state how you know when you have read in all the
  47. packets for a given Transmission Unit--is there some
  48. "end-of-transmission" indicator?
  49.  
  50. You didn't happen to state how "data length" is related to "data".
  51. I'll assume that "data" is in the form of a stream of bytes; and
  52. that "data length" and "packet length" are two-byte integers giving
  53. the number of bytes in Data and Packet, respectively.
  54.  
  55.    type BYTE is range 0 .. 255;
  56.    for BYTE'SIZE use 8;
  57.    subtype DATA_BYTE is BYTE;
  58.  
  59.    type LENGTH is range 0 .. 50000;      -- or whatever
  60.    for LENGTH'SIZE use 16;
  61.  
  62.    DATA_LENGTH, PACKET_LENGTH:  LENGTH;
  63.     
  64. I suggest it's easier to simply define everything as an
  65. undifferentiated stream of bytes, and use UNCHECKED_CONVERSION to
  66. extract the more complicated, higher-level structure after you read in
  67. the needed bytes.
  68.  
  69. The major use of UNCHECKED_CONVERSION, I have found, is to read in
  70. low-level data representations (like bit streams or byte streams), and
  71. then convert them to whatever high-level representation you wish after
  72. you have interrogated them to find out their dynamic structure.
  73.  
  74. So you can read the first two bytes, and then use UNCHECKED_CONVERSION
  75. to convert it to the integer type LENGTH.  Then that's the Packet
  76. Length; you know you must read in that number of bytes for each
  77. subsequent packet.  So for each subsequent packet, read in a number of
  78. bytes given by Packet Length; use UNCHECKED_CONVERSION to convert the
  79. first two bytes to an integer (which represents Data Length); then
  80. process that number of subsequent bytes as Data, ignoring the rest.
  81.  
  82.  
  83.  
  84. --
  85. Steven Litvintchouk
  86. MITRE Corporation
  87. 202 Burlington Road
  88. Bedford, MA  01730
  89.  
  90. Fone:  (617)271-7753
  91. ARPA:  sdl@mitre.org
  92. UUCP:  linus!sdl
  93.     "Where does he get those wonderful toys?"
  94.