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,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!d4g2000yqa.googlegroups.com!not-for-mail From: Phil Thornley Newsgroups: comp.lang.ada Subject: Re: Choices for modelling binary packet protocol in SPARK Date: Sat, 18 Jul 2009 04:23:23 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 80.177.171.182 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: posting.google.com 1247916203 29053 127.0.0.1 (18 Jul 2009 11:23:23 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sat, 18 Jul 2009 11:23:23 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: d4g2000yqa.googlegroups.com; posting-host=80.177.171.182; posting-account=Fz1-yAoAAACc1SDCr-Py2qBj8xQ-qC2q User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727),gzip(gfe),gzip(gfe) Xref: g2news2.google.com comp.lang.ada:7127 Date: 2009-07-18T04:23:23-07:00 List-Id: On 18 July, 07:46, xorque wrote: > Hello. > > I'm working on a protocol that uses many different binary packet > types. > They all inherit from one basic packet type. > [snip] > I'm not sure, exactly, with a lack of variant records, how I'm > meant to model this in SPARK. > > Am I going to be writing enormous case statements or is there > some clever way to handle this kind of thing? As a rule, SPARK (and high-integrity code generally) avoids programming tricks - because the code becomes more error-prone for the author, reviewer and compiler. If the individual records are fairly small, is an ordinary record acceptable: type P_Type is record Option : P_Option_Type; Timestamp : Integer; P1 : P1_Type; P2 : P2_Type; end record; Alternatively the language supports inheritance via tagged types, but with restrictions (no class-wide programming, only one derived type per package). A different approach would be to use Unchecked_Conversion for the individual record types, defining their layout with representation clauses to get the correct format of the byte array. A tedious but simple method is to use P1_Type and P2_Type as you have them for all the internal processing, but with parallel record types that have representation clauses suitable for UC to a byte array and operations that convert between the two forms (these have to be explicit as derived types aren't supported). Phil Thornley