comp.lang.ada
 help / color / mirror / Atom feed
* gnatcol json vs network read
@ 2018-12-14 17:50 Stephen Leake
  2018-12-14 18:53 ` Olivier Henley
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Stephen Leake @ 2018-12-14 17:50 UTC (permalink / 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-12-15  9:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-14 17:50 gnatcol json vs network read Stephen Leake
2018-12-14 18:53 ` Olivier Henley
2018-12-14 19:00 ` Stephen Leake
2018-12-14 21:58 ` Per Sandberg
2018-12-15  9:41   ` Stephen Leake

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