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.5 required=5.0 tests=BAYES_00,FROMSPACE, FROM_ADDR_WS,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a883dc07df0d6bb1,start X-Google-Attributes: gid103376,public From: " "@deneb.cygnus.argh.org (Florian Weimer) Subject: Decoding an octet stream Date: 1999/11/28 Message-ID: <877lj2q36g.fsf@deneb.cygnus.argh.org>#1/1 X-Deja-AN: 554045526 Mail-Copies-To: never Content-Type: text/plain; charset=us-ascii X-Complaints-To: abuse@cygnus.argh.org X-Trace: deneb.cygnus.argh.org 943787623 8789 192.168.1.2 (28 Nov 1999 11:13:43 GMT) Organization: Penguin on board Mime-Version: 1.0 User-Agent: Gnus/5.070099 (Pterodactyl Gnus v0.99) Emacs/20.4 NNTP-Posting-Date: 28 Nov 1999 11:13:43 GMT Newsgroups: comp.lang.ada Date: 1999-11-28T11:13:43+00:00 List-Id: What is the best way to decode an octet stream (i.e. a sequence of unsigned eight-bit values) with Ada? The octet stream consists of packet markes (single octets), two-octet integers (stored with the most significant octet first), strings (sequences of octets of a given length) and so on. I don't want to use Ada.Sequential_IO, because it would mean that only one octet can be read at a time, which seems to be quite inefficient. Streams seem to be nice, though. If I specify the necessary representation clauses, I think I'll only have to write a few 'Read and 'Write operations, and composed types will be handled correctly almost automatically. But is this really portable? Are there any targets (except supercomputers, mainframes, and embedded systems) where Stream_Element'Size isn't equal to 8? BTW: I'm currently reading the two-octet integers using a construct like `First_Octet * 2**8 + Second_Octet'. Is it possible to denote the octet ordering using a representation clause? For a target with a matching octet order, more efficient code could be generated.