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 X-Received: by 2002:a6b:a10:: with SMTP id z16mr3169371ioi.13.1544809809168; Fri, 14 Dec 2018 09:50:09 -0800 (PST) X-Received: by 2002:a9d:24c3:: with SMTP id z61mr70090ota.1.1544809808984; Fri, 14 Dec 2018 09:50:08 -0800 (PST) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!209.85.166.216.MISMATCH!q69no74148itb.0!news-out.google.com!v71ni112ita.0!nntp.google.com!k10no74049itk.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Fri, 14 Dec 2018 09:50:08 -0800 (PST) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=76.77.182.20; posting-account=W2gdXQoAAADxIuhBWhPFjUps3wUp4RhQ NNTP-Posting-Host: 76.77.182.20 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: gnatcol json vs network read From: Stephen Leake Injection-Date: Fri, 14 Dec 2018 17:50:09 +0000 Content-Type: text/plain; charset="UTF-8" Xref: reader01.eternal-september.org comp.lang.ada:55038 Date: 2018-12-14T09:50:08-08:00 List-Id: 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