From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,1757aa928c05e15f X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-09-15 13:26:07 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!nntp-server.caltech.edu!attla2!ip.att.net!attbi_feed3!attbi_feed4!attbi.com!sccrnsc02.POSTED!not-for-mail From: tmoran@acm.org Newsgroups: comp.lang.ada Subject: Re: Handling of unfriendly data structures References: X-Newsreader: Tom's custom newsreader Message-ID: NNTP-Posting-Host: 12.234.13.56 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc02 1032121564 12.234.13.56 (Sun, 15 Sep 2002 20:26:04 GMT) NNTP-Posting-Date: Sun, 15 Sep 2002 20:26:04 GMT Organization: AT&T Broadband Date: Sun, 15 Sep 2002 20:26:04 GMT Xref: archiver1.google.com comp.lang.ada:28995 Date: 2002-09-15T20:26:04+00:00 List-Id: > What would be the "Ada-way" to implement this, considering that That depends somewhat on how to will want to access the data after reading a block. You seem to have declarations for part_? and you could declare type string_access is access string; type block_type is new ada.finalization.limited_controlled with record a : part_a; a_text : string_access; b : part_b; b_text : string_access; ... y : part_y; y_text : string_access; end record; procedure read_a_block(block : out block_type); private procedure finalize(block : in out block_type); -- free allocated ?_text's If your program wants to access things sequentially, ie, the things in a_part, then a_text, then the items in b_part, then b_text, etc, then you might instead want to write a routine that reads a part_a, doing endianness conversion as needed and returning a part_a to its caller, and similar routines for part_b etc. and finally a text reader that uses its output size to read the right number of characters. Using Ada.Streams, for instance, you could then write something like: part_a'read(stream, a); declare a_text : string(1 .. a.size); begin text'read(stream, a_text); -- process the part_a and a_text stuff end; part_b'read(stream, b); declare b_text : string(1 .. b.size); begin text'read(stream, b_text); -- process the part_b and b_text stuff end; ...