From: Shark8 <OneWingedShark@gmail.com>
Subject: Re: Help with type definition
Date: Sat, 28 Jun 2014 01:26:42 -0600
Date: 2014-06-28T01:26:42-06:00 [thread overview]
Message-ID: <T6urv.167007$Fd3.105735@fx26.iad> (raw)
In-Reply-To: <5b4a031b-b3b3-455f-b491-e161cc24af3d@googlegroups.com>
On 27-Jun-14 16:05, hanslad@gmail.com wrote:
> Is there a type in Ada for unbounded byte arrays similar to the unbounded string?
You could use a vector; but you really don't need it for this problem;
in fact it seems you're better off using a regular array.
> "A ByteString is encoded as sequence of bytes preceded by its
> length in bytes. The length is encoded as a 32-bit signed
> integer as described above. If the length of the byte string
> is -1 then the byte string is 'null'."
So, your from-the-wire reading algorithm would be something like this:
Type Byte_String is Array(Positive range <>) of Interfaces.Unsigned_8;
-- Assuming use of Ada.Streams
Function Read(Stream : not null access Root_Stream_Type'Class) return
Byte_String is
Length : Interfaces.Integer_32:= Interfaces.Integer_32'Input(Stream);
begin
Return Result : Byte_Array(1..Length) do
For Index in Result'Range loop
Result(Index):= Interfaces.Unsigned_8'Input(Stream);
end loop;
end return;
end Read;
prev parent reply other threads:[~2014-06-28 7:26 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-16 7:37 Help with type definition hanslad
2014-05-16 7:54 ` Dmitry A. Kazakov
2014-05-16 10:03 ` G.B.
2014-05-16 11:26 ` Jacob Sparre Andersen
2014-05-16 15:38 ` Shark8
2014-05-16 15:50 ` Simon Wright
2014-05-16 16:30 ` Shark8
2014-05-16 11:29 ` Jacob Sparre Andersen
2014-05-16 12:29 ` G.B.
2014-05-16 17:57 ` Jeffrey Carter
2014-05-21 20:45 ` hanslad
2014-06-27 22:05 ` hanslad
2014-06-28 7:26 ` Shark8 [this message]
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox