comp.lang.ada
 help / color / mirror / Atom feed
From: Per Sandberg <per.s.sandberg@bahnhof.se>
Subject: Re: gnatcol json vs network read
Date: Fri, 14 Dec 2018 22:58:03 +0100
Date: 2018-12-14T22:58:03+01:00	[thread overview]
Message-ID: <MHVQD.1364$YO1.266@fx31.am4> (raw)
In-Reply-To: <a57563c9-8f79-47a5-8613-ebd975899fa8@googlegroups.com>

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


  parent reply	other threads:[~2018-12-14 21:58 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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