<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<tt>Hi Tito,<br>
<br>
A very interesting question. After a bit of research, I can tell
you that $json and $var will behave quite similarly in terms of
performance when using the simple "=" (assign) operator. A
difference between them worth pointing out is that $var uses
only-pkg memory, while $json uses both pkg and system memory
(since it is based on the "json-c" library) - so the more $json's
you fill up, the more "opensipsctl fifo get_statistics pkmem:"
will be incorrect.<br>
<br>
If you really want to optimize something about that _specific_
code:<br>
</tt><tt><span class=""><br>
$json(authbody) :=</span><span class=""> $json(authresponse)</span><span
class="">;</span></tt><br>
<tt><span class=""><span class="">if ($json(authbody/message/AcceptCall)
=</span><span class="">= "false") {<br>
...<br>
}</span></span><br>
<br>
Best regards,<br>
</tt>
<pre class="moz-signature" cols="72">Liviu Chircu
OpenSIPS Developer
<a class="moz-txt-link-freetext" href="http://www.opensips-solutions.com">http://www.opensips-solutions.com</a></pre>
<div class="moz-cite-prefix">On 17.06.2015 02:18, Tito Cumpen wrote:<br>
</div>
<blockquote
cite="mid:CANZPVB4ZyFkdk-DDSdQiMzbwgUzuHbSVob2POdR7agCQp+YRRQ@mail.gmail.com"
type="cite">
<div dir="ltr">Group,
<div><br>
</div>
<div><br>
</div>
<div>Is there a downside to casting responses from a rest
response into a json object rather than a generic $var? Here
is my function it works but I want to be aware if this will
cost a considerable amount of resources.</div>
<div><br>
</div>
<div>
<p class=""><span class=""> if
(!rest_get("http:</span><span class="">//<a
moz-do-not-send="true"
href="http://myauthurl.com/authme/$fU/$rU">myauthurl.com/authme/$fU/$rU</a>",
"$json(authresponse)", "$var(ct)", "$var(rcode)")) {</span></p>
<p class=""><span class=""></span><br>
</p>
<p class=""><span class=""> xlog("Error code
$var(rcode) in HTTP GET!\n")</span><span class="">;</span></p>
<p class=""><span class="">xlog("on account of admittance
error we are sending the call to the AS server for
processing")</span><span class="">;</span><br>
<span class=""></span></p>
<p class=""><span class=""> route(4)</span><span
class="">;</span></p>
<p class=""><span class="">}</span></p>
<p class=""><span class=""></span><br>
</p>
<p class=""><span class=""> xlog("got this body
response from authority on invite $json(authresponse) with
response code $var(rcode)")</span><span class="">;</span></p>
<p class=""><span class=""> xlog("response now casting
to json $json(authresponse) ")</span><span class="">;</span></p>
<p class=""><span class=""> $json(authbody) :=</span><span
class=""> "{}"</span><span class="">;</span></p>
<p class=""><span class=""></span><br>
</p>
<p class=""><span class=""> $json(authbody) :=</span><span
class=""> $json(authresponse)</span><span class="">;</span></p>
<p class=""><span class=""> xlog(" accessing the
message $json(authbody/message)")</span><span class="">;</span></p>
<p class=""><span class=""></span><br>
</p>
<p class=""><span class=""> $json(accept) :=</span><span
class=""> $json(authbody/message)</span><span class="">;</span><br>
</p>
<p class=""><span class=""> xlog(" casted message
$json(accept)")</span><span class="">;</span></p>
<p class=""><span class=""> if($json(accept/AcceptCall)
=</span><span class="">= "false"){ </span><br>
</p>
<p class=""><span class=""> xlog("response equal
false")</span><span class="">;</span></p>
<p class=""><span class="">
route(3)</span><span class="">;</span></p>
<p class=""><span class=""></span><br>
</p>
<p class=""><span class=""></span><br>
</p>
<p class=""><span class=""> }else{</span></p>
<p class=""><span class=""><br>
</span></p>
<p class=""><span class=""><br>
</span></p>
<p class=""><span class="">Notice how the response is casted
from </span><span class="">$json(authresponse) to </span> $json(authbody)
after it is initialized. I came to realize that I had to
initialize a variable because I couldn't access keys in <span
class=""> </span><span class="">$json(authresponse).</span></p>
<p class=""><span class=""><br>
</span></p>
<p class=""><span class=""><br>
</span></p>
<p class=""><span class="">Thanks,</span></p>
<p class=""><span class="">Tito</span></p>
</div>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
Users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Users@lists.opensips.org">Users@lists.opensips.org</a>
<a class="moz-txt-link-freetext" href="http://lists.opensips.org/cgi-bin/mailman/listinfo/users">http://lists.opensips.org/cgi-bin/mailman/listinfo/users</a>
</pre>
</blockquote>
<br>
</body>
</html>