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: 103376,57b537327d52e653,start X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!postnews.google.com!e9g2000prf.googlegroups.com!not-for-mail From: shaunpatterson@gmail.com Newsgroups: comp.lang.ada Subject: Byte streams Date: Thu, 02 Aug 2007 12:21:15 -0700 Organization: http://groups.google.com Message-ID: <1186082475.711489.104420@e9g2000prf.googlegroups.com> NNTP-Posting-Host: 155.219.241.10 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1186082476 29088 127.0.0.1 (2 Aug 2007 19:21:16 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 2 Aug 2007 19:21:16 +0000 (UTC) User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.12) Gecko/20060329 Red Hat/1.7.12-1.1.2.3,gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: e9g2000prf.googlegroups.com; posting-host=155.219.241.10; posting-account=ps2QrAMAAAA6_jCuRt2JEIpn5Otqf_w0 Xref: g2news2.google.com comp.lang.ada:1330 Date: 2007-08-02T12:21:15-07:00 List-Id: You guys have been a great help lately. Perhaps a few more of my questions could be answered... I've written a socket functions to send and receive data in C and then created a spec in Ada so I could use those same functions: -- C functions -- unsigned char *readBytes (const unsigned int numBytes); void sendBytes (unsigned char *data, const unsigned int numBytes); --- Ada side type Byte is mod 256; for Byte'Size use 8; type ByteStream is array (Integer range <>) of Byte; function readBytes (numBytes : Integer) return System.Address; pragma import (C, readBytes, "readBytes"); procedure sendBytes (data : ByteStream; numBytes : Integer); pragma import (C, sendBytes, "sendBytes"); ------------- Now I'm not sure if I'm doing the function prototypes correctly in Ada. I've actually gotten receiving to work correctly. I'm having some trouble converting the byte stream to a structure (I actually have this working... although I'm SURE there is a better way) and then converting a structure to a byte stream BYTESTREAM to STRUCTURE: type TestStructure is record value : Integer; end record; -- data is read off the socket successfully function create (data : System.Address) is return TestStructure type IntegerPtr is access all Integer; function to_IntegerPtr is new Unchecked_Conversion (source => System.Address, target => IntegerPtr); testData : IntegerPtr := to_IntegerPtr (data) intValue : Integer := msgData.all; begin return TestStructure'(value => intValue); end; --- this works...and I can do all the conversions I need using an unchecked_conversion However, I cannot seem to figure out how to send data correctly. consider: type AnotherStructure is record a : Integer; b : Integer; c : Integer; end Record; How would I go about converting to a byte stream to send it along to the socket sendBytes function? Again, I'm not sure if I rewrote the spec correctly in Ada. I have tried something like: toByteStream is new Unchecked_Conversion (source => AnotherStructure, Target => ByteStream); however ByteStream is unconstrained... Any suggestions? Thanks so much -- Shaun