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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: Help with type definition Date: Fri, 16 May 2014 09:54:18 +0200 Organization: cbb software GmbH Message-ID: <1fg1g0pncjb4l$.1qve7hld7nxqv.dlg@40tude.net> References: <8beec1c1-9ca2-44fc-9d7e-0cd0aa772dcc@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: QTaafVZuunHujkJPndFR7g.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 Xref: news.eternal-september.org comp.lang.ada:19856 Date: 2014-05-16T09:54:18+02:00 List-Id: On Fri, 16 May 2014 00:37:25 -0700 (PDT), hanslad@gmail.com wrote: > 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. A value of -1 is used to indicate > a 'null' string." That is not definition of a type. It is definition of encoding. Though it does not define the way the string length is encoded. Why -1 should indicate null string and not 0 is a mystery. [Usually, unless the network transport has fixed-size blocks (real-time protocols do), for a stream-oriented transport, it is better to encode counts using chained codes. That reduces space required for lesser numbers. E.g. UTF-8 uses chained codes to encode character code points.] > The string is used in different datastructures send on network eg. like > the one implemented in "Node" type below. > Am I on the right track here? No. Internal representation and types have nothing to do with the protocol, except for encoding and decoding stages (presentation layer). You said, it is a string, let it be String, Wide_Wide_String, Unbounded_String. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de