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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: a07f3367d7,7e490a18b9688bd9 X-Google-Attributes: gida07f3367d7,public,usenet X-Google-NewGroupId: yes X-Google-Language: ENGLISH,ASCII Path: g2news2.google.com!postnews.google.com!p37g2000prp.googlegroups.com!not-for-mail From: Alexander Korolev Newsgroups: comp.lang.ada Subject: Re: Stream_Element_Array Date: Wed, 14 Sep 2011 02:09:15 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 96.49.119.210 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1315991355 22263 127.0.0.1 (14 Sep 2011 09:09:15 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Wed, 14 Sep 2011 09:09:15 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: p37g2000prp.googlegroups.com; posting-host=96.49.119.210; posting-account=9aAl4woAAACPkuvNJOQxyBXxG_5lfu_0 User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-Header-Order: HUARLECNK X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; ru-ru) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5,gzip(gfe) Xref: g2news2.google.com comp.lang.ada:21899 Date: 2011-09-14T02:09:15-07:00 List-Id: On Sep 14, 12:31=A0pm, Simon Wright wrote: > Alexander Korolev writes: > > I have a Type > > > type Message_Header is > > =A0 =A0 record > > =A0 =A0 =A0 =A0-- Components =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-- =A0 = 8 bit > > =A0 =A0 =A0 =A0Length =A0 =A0: Unsigned_16; =A0 =A0-- 16 bit =A0(MSB) > > =A0 =A0 =A0 =A0-- other components =A0 =A0 =A0 =A0 =A0-- =A0 8 bit > > =A0 =A0 end record; > > > How I could split the Lenght component on two subsequent > > Stream_Element ( 8-bit)? > > > Command: Stream_Element_Array (1 .. 64); > > I think the best way is using unchecked conversion. Below adds the > complication of converting to network byte order if not already so: > > =A0 =A0subtype Two_Byte_Slice is Ada.Streams.Stream_Element_Array (1 .. 2= ); > > =A0 =A0Big_Endian : constant Boolean > =A0 =A0 =A0:=3D System."=3D" (System.Default_Bit_Order, System.High_Order= _First); > > =A0 =A0function To_Two_Byte_Slice (S : Unsigned_16) return Two_Byte_Slice= is > =A0 =A0 =A0 function Convert is new Ada.Unchecked_Conversion (Unsigned_16= , > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 Two_Byte_Slice); > =A0 =A0 =A0 Tmp : constant Two_Byte_Slice :=3D Convert (S); > =A0 =A0begin > =A0 =A0 =A0 if Big_Endian then > =A0 =A0 =A0 =A0 =A0return Tmp; > =A0 =A0 =A0 else > =A0 =A0 =A0 =A0 =A0return (1 =3D> Tmp (2), > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A02 =3D> Tmp (1)); > =A0 =A0 =A0 end if; > =A0 =A0end To_Two_Byte_Slice; > > =A0 =A0Command (11 .. 12) :=3D To_Two_Byte_Slice (42); Thanks Simon I'll try your code anyway. -- I thought I might made the issue more complex The Unsigned_16 came from transformation of the Header_Type component by Interfaces.Unsigned_16 (Last). It means I have Last: Stream_Element_Count (8 bit) set correctly. -- (Note For Per: I can not send the lenth to target stream because the whole -- message (stream_element_array) assembled needs further computation over + one transformation -- (staffing - something like replace 111 with 444 + 555 if 111 occures in some components of the message including -- the letgh ) after the computation as an external dev requirement