From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on ip-172-31-65-14.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-2.2 required=3.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM,NICE_REPLY_A,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: magardner2010 Newsgroups: comp.lang.ada Subject: Re: gnat -xdr flag confusion. Date: Thu, 6 Jul 2023 20:32:10 +0300 Organization: A noiseless patient Spider Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: dont-email.me; posting-host="a267ab58be88abdf36d6bce4afe3a1f0"; logging-data="1062531"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+BUbFeXTV3xb9ZXCelwODNbYgGLP1lT/A=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Cancel-Lock: sha1:nz9R4zmzE0EO+KQmUD6nIh98Su4= Content-Language: en-GB In-Reply-To: Xref: news.eternal-september.org comp.lang.ada:65424 List-Id: On 04/07/2023 14:39, Dmitry A. Kazakov wrote: > On 2023-07-04 12:56, magardner2010 wrote: > >> ... > > You never defined the protocol and implemented it in the first place. > You used some code generation tools which, if ever worked, will bite you > in the end. With regards to the code generation tool (which I'm assuming refers to chtGPT, for which I don't have enough creatively insulting backronyms), I spent a good half a day getting the output to actually be accepted by rpcgen. I then rewrote most of it from scratch. With regards to the protocol implementation, I would like to point at the function that begins at https://github.com/smeagolthellama/szakdolgozat-notes/blob/f0b5143855f75354d41509845b0a41f0902d2928/ada/src/network_tree.adb#L29 , which has successfully communicated with other instances of itself, albeit using 'write and 'read to handle anything more complicated than "is the first character of the message a '?', a 'j', or a '>'?". My question was about how to get C to understand the language Ada is talking to itself in, given that that language should be at least related to XDR. > > To summarize the problem. The stream attribute 'Write writes the > constrained object. 'Output adds the constraints. Ada is capable to have > variable length records. C cannot do this. In short, it means that XDR's > discriminated union can be mapped onto Ada's variant record with no > default discriminant, but it cannot be directly mapped onto C's union. I > presume that GNAT implements XDR correctly and the C side does not cope. > I'm not sure I understand what you're saying here. Given that rpcgen (which generates functions for xdr, as well as rpc, a superset thereof) was a part of GNU's libc for a while, and still is on some ubuntu boxes, along with the fact that a number of Linux's favourite protocols (such as NFS) are implemented using it, I don't think the issue is the C side implementing the encoder/decoder in a way that doesn't match my spec. I expect either an Ada issue, a spec issue, or both. > Which is one of thousand reasons not to implement a communication > protocol by deriving representation from some language objects. Cutting > corners will not help you. I suppose there is wisdom in that, especially when attempting to communicate across architectures, but I was working under the assumption that the -xdr flag would remove the issue, as XDR is an architecture-and-programming-language-agnostic data encoding/decoding standard (or whatever an RFC counts as). > > Define the (application level [*]) protocol. Implement it in Ada. > Implement it in C. Done. > > --------------------- > *  XDR or ASN.1 or whatever are not application level! > I wouldn't have called XDR a protocol in the first place, except as a simplification. I would like to use it as a *part* of my protocol, not dissimilar to how NFS does, or programs that use G*ogle's protobuf thingie. Specifically, when a peer receives a query (in the form of a message starting with '?'), it should respond with a lump of data (current idea is the Child_Set type from my previous post, encoded in the XDR format, hence the difficulties) saying how many peers it has (in range 0..2), and who they are (address-port combinations, where address can be IPv4 or 6), so that the querying party can find out if there is space for it on this peer, or if it should look elsewhere. There are a couple of edge cases, but this if you are curious you can look at my code.