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.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.unit0.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!85.12.16.70.MISMATCH!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.am4!peer.am4.highwinds-media.com!news.highwinds-media.com!fx31.am4.POSTED!not-for-mail Subject: Re: gnatcol json vs network read Newsgroups: comp.lang.ada References: From: Per Sandberg User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Message-ID: X-Complaints-To: abuse@usenet.se NNTP-Posting-Date: Fri, 14 Dec 2018 21:58:04 UTC Organization: usenet.se Date: Fri, 14 Dec 2018 22:58:03 +0100 X-Received-Bytes: 2447 X-Received-Body-CRC: 482104632 Xref: reader01.eternal-september.org comp.lang.ada:55041 Date: 2018-12-14T22:58:03+01:00 List-Id: Well this all depends on the definition of Network_String'Input and Network_String'Output. Will Network_String'Output always send the whole string in such a format that Network_String'Input is able to reconstruct it regardless of fragmentation on the transport. /P On 12/14/18 6:50 PM, Stephen Leake wrote: > I'm reading json over a network, with code like: > > function Check_Ack (DB : not null access Database) return > GNATCOLL.JSON.JSON_Value > is > use GNATCOLL.JSON; > Msg : constant String := String (Network_String'Input (DB.Stream)); > begin > if DB.Verbosity > 1 then > Ada.Text_IO.Put_Line ("Remote: " & Msg); > end if; > > declare > Response : constant JSON_Value := Read (Msg); > begin > if Response.Get ("Status") /= Ack_Nack'Image (Ack) then > raise SAL.Invalid_Operation with Response.Get ("Message"); > end if; > return Response.Get ("Data"); > end; > end Check_Ack; > > Occasionally, this will throw INVALID_JSON_STREAM :1:155: empty stream > > Apparently this is because the network is sending a data packet with less then a whole JSON object; in the case I'm currently debugging, it's missing two closing }. > > So I need to check Msg for complete syntax before calling Read. However, GNATCOLL.JSON does not provide a function for that, and event the lower level Read in gnatcol-json.adb raises the exception. > > So I guess I'll write a {} counter, and wait for more data from the network if the first object is not complete. > > Has anyone else dealt with this problem? > > -- Stephe >