cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with latest 3.2 build: b9/d9/okx vs -8!/-9!

Flying
New Contributor III
Hi,

With the latest q.exe/q.lib released on 3 March, I'm now able to build my project with okx() for validity check on serialized data.

But I encountered one problem -- data serialized by b9(-1, k) are reported as 'badmsg in both q and by okx().

Test code attached below:

============================================test.h=================================================
#define KXVER 3
#include <k.h>
 
#ifdef __cplusplus
extern "C" {
#endif

KDB_API K K_DECL testSerial(K);

#ifdef __cplusplus
}
#endif
============================================test.h=================================================

============================================test.cpp=================================================
#include <iostream>
#include <iomanip>

KDB_API K K_DECL testSerial(K a) {
K k = ktn(0, 1);
kK(k)[0] = kp("000001.SZ");

K s = b9(-1, k);

for (G* i = kG(s); i < kG(s) + s->n; ++i) {
std::cout << std::setiosflags(std::ios::uppercase) << std::setfill('0') << std::setw(2)
<< std::hex << static_cast<int>(*i);
}
std::cout << std::endl;

std::cout << "okx = " << okx(s) << std::endl;

if (a->g) {
r0(s);
return k;
}
else {
r0(k);
return s;
}
}
============================================test.cpp=================================================

============================================test.q=================================================
\c 20 2000
testSerial:(hsym`$"./kdb+")2:(`testSerial;1);
show testSerial;

show testSerial 1b;

show testSerial 0b;

show -8!testSerial 1b; /NOTE -8! output is different from b9 output

show -9!testSerial 0b;
============================================test.q=================================================

The output is as following, note that: (1) -8! output is different from b9 output; (2) b9 output is getting okx() to return 0, and -9! to return 'badmsg.
============================================CONSOLE=================================================
D:\DEV\CHF>q test.q
KDB+ 3.2 2015.03.05 Copyright (C) 1993-2015 Kx Systems
w32/ 4()core 4095MB Think flying-thinkpad 192.168.10.104 NONEXPIRE

Welcome to kdb+ 32bit edition
For support please see http://groups.google.com/d/forum/personal-kdbplus
Tutorials can be found at http://code.kx.com/wiki/Tutorials
To exit, type \\
To remove this startup msg, edit q.q
code
0100000125000000000001000000000000000A0009000000000000003030303030312E535A
okx = 0
"000001.SZ"
0100000125000000000001000000000000000A0009000000000000003030303030312E535A
okx = 0
0x0100000125000000000001000000000000000a0009000000000000003030303030312e535a
0100000125000000000001000000000000000A0009000000000000003030303030312E535A
okx = 0
0x010000001d0000000000010000000a00090000003030303030312e535a
0100000125000000000001000000000000000A0009000000000000003030303030312E535A
okx = 0
k){0N!x y}
'badmsg
@
"q"
"show -9!testSerial 0b;"
q))
============================================CONSOLE=================================================
 
3 REPLIES 3

charlie
New Contributor II
New Contributor II
-8! uses b9(3,x).

-1 is for serializing for use within the same process only, and that data should not be passed through okx (okx doesn't understand the particulars of loopbacked data).

Btw, if you wish to serialize data for use outside of that process, use b9(3,x).

Flying
New Contributor III
I was indeed serializing within the same process.

In fact, I was using this mechanism to invoke a callback function in q main thread from an async thread. Therefore, I serialized the result in the async thread, and send the data over to the main thread configured with sd1().

From the documentation (http://code.kx.com/wiki/Cookbook/InterfacingWithC#Serialization.2FDeserialization), I was supposed to use -1 in kdb 3.0 onwards, since I am implementing a DLL loaded into q process. Based on your descriptions below, though, it seems -1 is not the right argument to use. Could someone please review the documentation and see if there is anything we can do to clarify the values listed there?

BTW, I started using 1 instead of 3, which works smoothly for me, since the description for 1 fits better to my use case above.

charlie
New Contributor II
New Contributor II
if you are looping back in the same process, just use -1 and do not call okx