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=unavailable autolearn_force=no version=3.4.4 Path: border1.nntp.dca.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!ecngs!feeder2.ecngs.de!217.188.199.168.MISMATCH!takemy.news.telefonica.de!telefonica.de!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Fri, 16 May 2014 14:29:13 +0200 From: "G.B." User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Help with type definition References: <8beec1c1-9ca2-44fc-9d7e-0cd0aa772dcc@googlegroups.com> In-Reply-To: <8beec1c1-9ca2-44fc-9d7e-0cd0aa772dcc@googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <53760499$0$6666$9b4e6d93@newsspool3.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 16 May 2014 14:29:13 CEST NNTP-Posting-Host: 146d7dd4.newsspool3.arcor-online.net X-Trace: DXC=3XhVG^]3UlEWDmlTRbh@=IMcF=Q^Z^V3H4Fo<]lROoRA8kFJLh>_cHTX3jMPi8^GR7^\mA X-Complaints-To: usenet-abuse@arcor.de Xref: number.nntp.dca.giganews.com comp.lang.ada:186442 Date: 2014-05-16T14:29:13+02:00 List-Id: On 16.05.14 09:37, hanslad@gmail.com wrote: > Hello, > I need an advise on how to define a type in my project. > I want to implement a network protocol with the following definition on the type "string": > > "All String values are encoded as a sequence of UTF8 characters without a null terminator and preceded by the length in bytes. > The length in bytes is encoded as Int32. Does Int32 stand for a type that has exactly 32 bits and is signed? Then, Integer is not a suitable candidate on the Ada side, because Integer is implementation defined (and may well be 16 bits on a 32 bits platform). Similarly, predefined type String may not be suitable because String is indexed by Positive, which is a subtype of Integer. If all is well, though, I'd choose Interfaces.Integer_32. Or just define some type if the benefits (and requirements) stated for Interfaces.Integer_32 by the LRM are not that important. type Int32 is range -2^31 .. +2**31-1; for Int32'Size use 32; Do you read octets? Some conversion might be needed in any case, so you might as well try Storage_Array instead of String, and then convert (or re-interpret) as needed. Your pointer-to-string type can be an "access constant" if the strings so allocated do not need any overwrites. Can you reuse a string buffer and pass it to processing routines?