xcall JSON opcode 3 & 4
John Andreasen
24 Apr 25 10:10 PM
Hi, I am attempting to use xcall JSON with opcode 4 to unescape a string. I seem to be experiencing an issue which is reproduceable with the below program.
MAP1 response$,s,132
MAP1 sts,f,6
response$ = "t"+CHR(34)+"est"
Trace.Print response$
XCALL JSON, 3, sts, response$
Trace.Print sts, response$
! Process response string.
XCALL JSON, 4, sts, response$
Trace.Print sts, response$
END
Which produces the following traces on 7.0.1770.1 EL7: response$=[t"est] sts=[0], response$=[t\"est] sts=[1], response$=[teest] It appears that the e gets duplicated and the " gets completely removed with opcode 4. Also, shouldn't the status from opcode 3 be 1 instead of 0 since 1 character (the quote) was escaped? Thanks, John Andreasen Diversified Data Software
2
19
Read More
|
|
Re: Receive Headers from xcall HTTP
John Andreasen
22 Apr 25 12:21 AM
Hi Jack, For some reason when I am using this, it seems the headers and response are separated by <LF><CR> instead of <CR><LF>. ![[Linked Image]](https://www.microsabio.net/bbs0719//ubbthreads.php?ubb=download&Number=425&filename=xcallHTTP_lfcr.png) Is this a mistake or is the CR a side effect of something else? I have an example program I can send if needed.
9
80
Read More
|
|
Re: .ISEMPTY() effiecny question
Jack McGregor
21 Apr 25 06:14 PM
Offhand I would say definitely, a built-in function is going to be faster than a user-defined function doing the same thing. Then again, .ISNULL() actually handles a couple of cases that yours doesn't (i.e. the case where the argument equals .NULL and the case where the argument is a string, possibly containing blanks.) But for what it's worth, here's a test program to measure it ...
! test performance of .isempty(x) vs a function
define ISNULL_TRUE = -1
map1 usecs,b,4
map1 x,x,0
map1 i,f
map1 b,b,1
x = fill(chr(0),30)
xcall TIMES,3,usecs
for i = 1 to 1000000
b = fn'isnull(x)
next i
xcall TIMES,3,usecs
? "fn'isnull(x) -- "; usecs/1000000; " usecs per call"
xcall TIMES,3,usecs
for i = 1 to 1000000
b = .isempty(x)
next i
xcall TIMES,3,usecs
? ".isempty(x) -- "; usecs/1000000; " usecs per call"
end
FUNCTION fn'isnull(var as x0:INPUTONLY) as b1
IF (var = fill$(CHR(0),LEN(var))) THEN
fn'isnull = ISNULL_TRUE
ENDIF
ENDFUNCTION
On my laptop, the results are as follows (and it's pretty consistent, within a range of +/- 10%) ...
.run isemptyx
1 million fn'isnull(x) -- 2.35262
1 million .isempty(x) -- 0.465129
So as expected, the built-in function is faster (about 5X), even though it's actually more complex. On the other hand, even the slow poke here is only burning up a couple of microseconds per call (and that's including the overhead of the FOR/NEXT loop and the XCALL to measure the time). Just for kicks I re-arranged the loops so they performed the function call 10 times in line for each loop iteration, instead of once, which in theory should reduce the FOR/NEXT overhead 10 fold, and that shaved about 3 tenths of a microsecond off the above values, i.e.
.run isemptyx2
fn'isnull(x) -- 2.06697 usecs per call
.isempty(x) -- 0.191827 usecs per call So the real differential appears to more like 10X!
2
29
Read More
|
|
.ISEMPTY() effiecny question
Stephen Funkhouser
21 Apr 25 04:56 PM
We have the following function for testing if an xvar is null. I believe this came from the SOSLIB. Would it be more efficient to use .ISEMPTY() for this?
FUNCTION fn'isnull(var as x0:INPUTONLY) as b1
IF (var = fill$(CHR(0),LEN(var))) THEN
fn'isnull = ISNULL_TRUE
ENDIF
ENDFUNCTION
2
29
Read More
|
|
Re: SQLOP_FETCH_ROW into a DYNSTRUCT
Stephen Funkhouser
18 Apr 25 09:35 PM
I just finished testing this, and it works as expected.
Unfortunately, we have a ton of multidimensional arrays nested in DEFSTRUCTS. I think (x, y, z) is the largest dimension. I just looked at the documentation specific to FETCHR_DYNFLDNUM
22
191
Read More
|
|
Re: Receive Headers from xcall HTTP
Jack McGregor
11 Apr 25 03:49 PM
That sounds sensible to me. So we'll define a new flag XHTTPF_HDRRESP (or perhaps use the existing XHTTPF_REQHEAD) which if specified along with XHTTPF_REQPOST, will cause the headers to be prepended to the response with a blank line separating them from the rest of the response. It will just require an update of the ashnet library.
I'll shoot for early next week.
9
80
Read More
|
|
Re: Receive Headers from xcall HTTP
John Andreasen
11 Apr 25 03:35 PM
I think any of those options would work. It seems like in the second option that you would be able to separate them as the headers would be at the beginning of the response and could be separated from the body of the response by a single blank line (as it is in the actual HTTP protocol.)
9
80
Read More
|
|
|
|