comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: gnatcol json vs network read
Date: Fri, 14 Dec 2018 09:50:08 -0800 (PST)
Date: 2018-12-14T09:50:08-08:00	[thread overview]
Message-ID: <a57563c9-8f79-47a5-8613-ebd975899fa8@googlegroups.com> (raw)

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 <data>: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


             reply	other threads:[~2018-12-14 17:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-14 17:50 Stephen Leake [this message]
2018-12-14 18:53 ` gnatcol json vs network read Olivier Henley
2018-12-14 19:00 ` Stephen Leake
2018-12-14 21:58 ` Per Sandberg
2018-12-15  9:41   ` Stephen Leake
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox