kdb:c 中的 guid 编码导致无效序列化

kdb: guid encoding in c results in invalid serialization

我正在尝试从 C++ 操作 guid。每当我尝试序列化一个 guid 时,我都会得到一个空指针。

U g={0};
auto k = ku(g);
auto p = ::b9(2, k);

前两行直接来自创建空 guid 的手册。这将导致 p == 0.

我真正想做的是创建一个 guid 列表,然后序列化:

k = ktn(UU, 3)
kU(k)[0] = <an instance of U with the g bytes initialized>
kU(k)[1] = <an instance of U with the g bytes initialized>
kU(k)[2] = <an instance of U with the g bytes initialized>

尝试序列化时无效。

我认为您应该使用 3 作为 b9 的第一个参数。例如:

jmcmurray@homer ~/c $ more test.c
#include"k.h"
K f(K x)
{
  K k = ktn(UU,3);I j=0;
  for(j=0;j<3;j++){
   U g={0};I i=0;
   for(i=j;i<j+16;i++){
    g.g[i] = (unsigned char)i;
   }
   kU(k)[0] = g;
  }
  return b9(3,k);
}
jmcmurray@homer ~/c $ gcc -shared -fPIC -DKXVER=3 test.c -o test.so
jmcmurray@homer ~/c $ q
KDB+ 3.5 2017.11.30 Copyright (C) 1993-2017 Kx Systems
l64/ 8()core 16048MB jmcmurray homer.aquaq.co.uk 192.168.1.57 EXPIRE 2019.06.30 AquaQ #52428

q)f:`:./test 2:(`f;1)
q)f[]
0x010000003e000000020003000000000002030405060708090a0b0c0d0e0f00ae67af727f000..
q)-9!f[]
00000203-0405-0607-0809-0a0b0c0d0e0f 001868af-727f-0000-6062-67af727f0000 a0a..
q)

在这里,我可以 return 来自我的共享对象的序列化 GUID 列表并在 q 端反序列化。当我像你的例子一样尝试使用 2 时,当 运行 函数在 q.

时出现 'type 错误

根据https://code.kx.com/q/interfaces/capiref/#b9-serialize3表示

unenumerate, compress, allow serialization of timespan and timestamp

2没有"compress"也是一样的。所以我猜你必须压缩GUID?