netSerial

serializer producing compact bitstreams
git clone https://noulin.net/git/netSerial.git
Log | Files | Refs | README | LICENSE

memcheckNetSerial.c (49592B)


      1 #include <stdlib.h>
      2 #include <stdio.h>
      3 #include <string.h>
      4 
      5 #define ck_assert_str_eq(a,b) a;b;
      6 #define ck_assert_str_ne(a,b) a;b;
      7 #define ck_assert_ptr_eq(a,b) a;b;
      8 #define ck_assert_ptr_ne(a,b) a;b;
      9 #define ck_assert_uint_eq(a,b) a;b;
     10 #define ck_assert_uint_ne(a,b) a;b;
     11 #define ck_assert_int_eq(a,b) a;b;
     12 #define ck_assert_int_ne(a,b) a;b;
     13 #define ck_assert(a) a;
     14 
     15 
     16 #include "libsheepyObject.h"
     17 #include "netSerial.h"
     18 
     19 int argc; char **argv;
     20 
     21 /* enable/disable logging */
     22 /* #undef pLog */
     23 /* #define pLog(...) */
     24 
     25 
     26 void topT(void) {
     27 
     28   // STEPS
     29   // init
     30   // init allocate
     31   // terminate
     32   // allocate
     33   // string
     34   // duplicate
     35 
     36   createNetSerial(n);
     37   createNetSerial(ds);
     38   char *s;
     39   smallBytest *B;
     40   createSmallDict(d);
     41   createSmallArray(a);
     42 
     43   // empty smallBytes
     44   initiateG(&B);
     45   pushBufferG(B, NULL, 1);
     46   // store garbage data in empty smallBytes
     47   B->B->data = 0;
     48   ck_assert_ptr_eq(getTopTypeG(&ds), NULL);
     49   deserialG(&ds, B);
     50   // nothing should deserialized
     51   ck_assert_ptr_eq(getTopTypeG(&ds), NULL);
     52   terminateG(B);
     53 
     54   // undefined
     55   undefinedt *oU = allocUndefined();
     56   setTopNFreeG(&n, (baset *)oU);
     57   B = serialG(&n);
     58   s = sToString((smallt *) B->B);
     59   ck_assert_str_eq(s, "[0x00]");
     60   free(s);
     61   deserialG(&ds, B);
     62   s = toStringG(&ds);
     63   ck_assert_str_eq(s, "null");
     64   free(s);
     65   terminateG(B);
     66   freeManyG(&n, &ds);
     67 
     68   // bool
     69   setTopG(&n, TRUE);
     70   B = serialG(&n);
     71   s = sToString((smallt *) B->B);
     72   ck_assert_str_eq(s, "[0x11]");
     73   free(s);
     74   deserialG(&ds, B);
     75   s = toStringG(&ds);
     76   ck_assert_str_eq(s, "true");
     77   free(s);
     78   terminateG(B);
     79   freeManyG(&n, &ds);
     80 
     81   // double
     82   setTopG(&n, 1.2);
     83   B = serialG(&n);
     84   logI("len %u", lenG(B));
     85   logSI("%s", toHexSepS(getValG(B), lenG(B), " "));
     86   s = sToString((smallt *) B->B);
     87   ck_assert_str_eq(s, "[0x03,0x33,0x33,0x33,0x33,0x33,0x33,0xf3,0x3f]");
     88   free(s);
     89   deserialG(&ds, B);
     90   s = toStringG(&ds);
     91   ck_assert_str_eq(s, "1.200000e+00");
     92   free(s);
     93   terminateG(B);
     94   freeManyG(&n, &ds);
     95 
     96   // TODO test with 0x8000000000000000 and 0x7FFFFFFFFFFFFFFF
     97   // 64 bit int test with bit 63 set
     98   setTopG(&n, -8030967404224553996);
     99   B = serialG(&n);
    100   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    101   s = sToString((smallt *) B->B);
    102   ck_assert_str_eq(s, "[0xf4,0x82,0xd2,0x8b,0xc7,0xb7,0xd2,0xbb,0xee,0x1b]");
    103   free(s);
    104   deserialG(&ds, B);
    105   s = toStringG(&ds);
    106   logVarG(s);
    107   ck_assert_str_eq(s, "-8030967404224553996");
    108   free(s);
    109   terminateG(B);
    110   freeManyG(&n, &ds);
    111 
    112   // 64 bit int test large positive value
    113   setTopG(&n, 12000000000UL);
    114   B = serialG(&n);
    115   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    116   s = sToString((smallt *) B->B);
    117   ck_assert_str_eq(s, "[0x84,0x80,0xbc,0xc1,0x96,0x0b]");
    118   free(s);
    119   deserialG(&ds, B);
    120   s = toStringG(&ds);
    121   logVarG(s);
    122   ck_assert_str_eq(s, "12000000000");
    123   free(s);
    124   terminateG(B);
    125   freeManyG(&n, &ds);
    126 
    127   // int
    128   setTopG(&n, 120);
    129   B = serialG(&n);
    130   logI("len %u", lenG(B));
    131   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    132   s = sToString((smallt *) B->B);
    133   ck_assert_str_eq(s, "[0x84,0x1e]");
    134   free(s);
    135   deserialG(&ds, B);
    136   s = toStringG(&ds);
    137   ck_assert_str_eq(s, "120");
    138   free(s);
    139   terminateG(B);
    140   freeManyG(&n, &ds);
    141 
    142   // string
    143   setTopG(&n, "string");
    144   B = serialG(&n);
    145   logI("len %u", lenG(B));
    146   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    147   s = sToString((smallt *) B->B);
    148   ck_assert_str_eq(s, "[0x05,0x73,0x74,0x72,0x69,0x6e,0x67,0x00]");
    149   free(s);
    150   deserialG(&ds, B);
    151   s = toStringG(&ds);
    152   ck_assert_str_eq(s, "string");
    153   free(s);
    154   terminateG(B);
    155   freeManyG(&n, &ds);
    156 
    157   // dict
    158   setG(&d, "k", 4);
    159   setTopG(&n, &d);
    160   B = serialG(&n);
    161   logI("len %u", lenG(B));
    162   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    163   s = sToString((smallt *) B->B);
    164   ck_assert_str_eq(s, "[0x4e,0x01,0x6b,0x00,0x08]");
    165   free(s);
    166   deserialG(&ds, B);
    167   s = toStringG(&ds);
    168   ck_assert_str_eq(s, "{\"k\":4}");
    169   free(s);
    170   terminateG(B);
    171   freeManyG(&n, &ds);
    172 
    173   // array
    174   pushG(&a, "k");
    175   pushG(&a, 4);
    176   setTopG(&n, &a);
    177   B = serialG(&n);
    178   logI("len %u", lenG(B));
    179   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    180   s = sToString((smallt *) B->B);
    181   ck_assert_str_eq(s, "[0x26,0x45,0x6b,0x00,0x08]");
    182   free(s);
    183   deserialG(&ds, B);
    184   s = toStringG(&ds);
    185   ck_assert_str_eq(s, "[\"k\",4]");
    186   free(s);
    187   terminateG(B);
    188   freeManyG(&n, &ds);
    189 
    190 }
    191 
    192 
    193 
    194 void uniformDictT(void) {
    195 
    196   // STEPS
    197   // init
    198   // init allocate
    199   // terminate
    200   // allocate
    201   // string
    202   // duplicate
    203 
    204   createNetSerial(n);
    205   createNetSerial(ds);
    206   char *s;
    207   smallBytest *B;
    208   createSmallDict(d);
    209   createSmallDict(dd);
    210   createSmallArray(a);
    211 
    212   // undefined
    213   undefinedt *oU = allocUndefined();
    214   setG(&d, "0", oU);
    215   setG(&d, "1", oU);
    216   setG(&d, "2", oU);
    217   setG(&d, "3", oU);
    218   setG(&d, "4", oU);
    219   setNFreeG(&d, "5", oU);
    220   setTopG(&n, &d);
    221   B = serialG(&n);
    222   logI("len %u", lenG(B));
    223   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    224   s = sToString((smallt *) B->B);
    225   ck_assert_str_eq(s, "[0x0e,0x06,0x30,0x00,0x31,0x00,0x32,0x00,0x33,0x00,0x34,0x00,0x35,0x00]");
    226   free(s);
    227   deserialG(&ds, B);
    228   s = toStringG(&ds);
    229   ck_assert_str_eq(s, "{\"0\":null,\"1\":null,\"2\":null,\"3\":null,\"4\":null,\"5\":null}");
    230   free(s);
    231   terminateG(B);
    232   freeManyG(&n, &ds);
    233 
    234   // empty dict
    235   initiateG(&d);
    236   setTopG(&n, &d);
    237   B = serialG(&n);
    238   logI("len %u", lenG(B));
    239   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    240   s = sToString((smallt *) B->B);
    241   ck_assert_str_eq(s, "[0x0e,0x00]");
    242   free(s);
    243   deserialG(&ds, B);
    244   s = toStringG(&ds);
    245   ck_assert_str_eq(s, "{}");
    246   free(s);
    247   terminateG(B);
    248   freeManyG(&n, &ds);
    249 
    250   // bool
    251   initiateG(&d);
    252   setG(&d, "0", TRUE);
    253   setG(&d, "1", TRUE);
    254   setG(&d, "2", TRUE);
    255   setG(&d, "3", TRUE);
    256   setTopG(&n, &d);
    257   B = serialG(&n);
    258   logI("len %u", lenG(B));
    259   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    260   s = sToString((smallt *) B->B);
    261   ck_assert_str_eq(s, "[0x1e,0x04,0x30,0x00,0x0f,0x31,0x00,0x32,0x00,0x33,0x00]");
    262   free(s);
    263   deserialG(&ds, B);
    264   s = toStringG(&ds);
    265   ck_assert_str_eq(s, "{\"0\":true,\"1\":true,\"2\":true,\"3\":true}");
    266   free(s);
    267   terminateG(B);
    268   freeManyG(&n, &ds);
    269 
    270   // 9 bools
    271   initiateG(&d);
    272   setG(&d, "0", TRUE);
    273   setG(&d, "1", TRUE);
    274   setG(&d, "2", TRUE);
    275   setG(&d, "3", TRUE);
    276   setG(&d, "4", TRUE);
    277   setG(&d, "5", TRUE);
    278   setG(&d, "6", TRUE);
    279   setG(&d, "7", TRUE);
    280   setG(&d, "8", TRUE);
    281   setTopG(&n, &d);
    282   B = serialG(&n);
    283   logI("len %u", lenG(B));
    284   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    285   s = sToString((smallt *) B->B);
    286   ck_assert_str_eq(s, "[0x1e,0x09,0x30,0x00,0xff,0x31,0x00,0x32,0x00,0x33,0x00,0x34,0x00,0x35,0x00,0x36,0x00,0x37,0x00,0x38,0x00,0x01]");
    287   free(s);
    288   deserialG(&ds, B);
    289   s = toStringG(&ds);
    290   ck_assert_str_eq(s, "{\"0\":true,\"1\":true,\"2\":true,\"3\":true,\"4\":true,\"5\":true,\"6\":true,\"7\":true,\"8\":true}");
    291   free(s);
    292   terminateG(B);
    293   freeManyG(&n, &ds);
    294 
    295 
    296   // double
    297   initiateG(&d);
    298   setG(&d, "0", 1.1);
    299   setG(&d, "1", 2.2);
    300   setG(&d, "2", 3.3);
    301   setTopG(&n, &d);
    302   B = serialG(&n);
    303   logI("len %u", lenG(B));
    304   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    305   s = sToString((smallt *) B->B);
    306   ck_assert_str_eq(s, "[0x3e,0x03,0x30,0x00,0x9a,0x99,0x99,0x99,0x99,0x99,0xf1,0x3f,0x31,0x00,0x9a,0x99,0x99,0x99,0x99,0x99,0x01,0x40,0x32,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x0a,0x40]");
    307   free(s);
    308   deserialG(&ds, B);
    309   s = toStringG(&ds);
    310   ck_assert_str_eq(s, "{\"0\":1.100000e+00,\"1\":2.200000e+00,\"2\":3.300000e+00}");
    311   free(s);
    312   terminateG(B);
    313   freeManyG(&n, &ds);
    314 
    315   // int
    316   initiateG(&d);
    317   setG(&d, "0", 1);
    318   setG(&d, "1", 2);
    319   setTopG(&n, &d);
    320   B = serialG(&n);
    321   logI("len %u", lenG(B));
    322   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    323   s = sToString((smallt *) B->B);
    324   ck_assert_str_eq(s, "[0x4e,0x02,0x30,0x00,0x02,0x31,0x00,0x04]");
    325   free(s);
    326   deserialG(&ds, B);
    327   s = toStringG(&ds);
    328   ck_assert_str_eq(s, "{\"0\":1,\"1\":2}");
    329   free(s);
    330   terminateG(B);
    331   freeManyG(&n, &ds);
    332 
    333   // string
    334   initiateG(&d);
    335   setG(&d, "0", "a");
    336   setG(&d, "1", "A");
    337   setG(&d, "2", "z");
    338   setTopG(&n, &d);
    339   B = serialG(&n);
    340   logI("len %u", lenG(B));
    341   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    342   s = sToString((smallt *) B->B);
    343   ck_assert_str_eq(s, "[0x5e,0x03,0x30,0x00,0x61,0x00,0x31,0x00,0x41,0x00,0x32,0x00,0x7a,0x00]");
    344   free(s);
    345   deserialG(&ds, B);
    346   s = toStringG(&ds);
    347   ck_assert_str_eq(s, "{\"0\":\"a\",\"1\":\"A\",\"2\":\"z\"}");
    348   free(s);
    349   terminateG(B);
    350   freeManyG(&n, &ds);
    351 
    352   // dict
    353   initiateG(&d);
    354   setG(&dd, "9", "z");
    355   setG(&dd, "1", 1);
    356   setG(&d, "0", &dd);
    357   initiateG(&dd);
    358   setG(&dd, "Z", "-");
    359   setG(&dd, "A", 234);
    360   setG(&d, "1", &dd);
    361   setTopG(&n, &d);
    362   logVarG(&n);
    363   B = serialG(&n);
    364   logI("len %u", lenG(B));
    365   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    366   s = sToString((smallt *) B->B);
    367   ck_assert_str_eq(s, "[0x2e,0x02,0x30,0x00,0x02,0x39,0x00,0x45,0x7a,0x00,0x31,0x00,0x02,0x31,0x00,0x02,0x5a,0x00,0x45,0x2d,0x00,0x41,0x00,0xd4,0x03]");
    368   free(s);
    369   deserialG(&ds, B);
    370   s = toStringG(&ds);
    371   ck_assert_str_eq(s, "{\"0\":{\"9\":\"z\",\"1\":1},\"1\":{\"Z\":\"-\",\"A\":234}}");
    372   free(s);
    373   terminateG(B);
    374   freeManyG(&n, &ds);
    375 
    376   // uniform dict
    377   initiateG(&dd);
    378   initiateG(&d);
    379   setG(&dd, "9", 1);
    380   setG(&dd, "1", 2);
    381   setG(&d, "0", &dd);
    382   initiateG(&dd);
    383   setG(&dd, "Z", "-");
    384   setG(&dd, "A", "+");
    385   setG(&d, "1", &dd);
    386   setTopG(&n, &d);
    387   logVarG(&n);
    388   B = serialG(&n);
    389   logI("len %u", lenG(B));
    390   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    391   s = sToString((smallt *) B->B);
    392   ck_assert_str_eq(s, "[0xee,0x02,0x30,0x00,0x24,0x39,0x00,0x02,0x31,0x00,0x04,0x31,0x00,0x25,0x5a,0x00,0x2d,0x00,0x41,0x00,0x2b,0x00]");
    393   free(s);
    394   deserialG(&ds, B);
    395   s = toStringG(&ds);
    396   ck_assert_str_eq(s, "{\"0\":{\"9\":1,\"1\":2},\"1\":{\"Z\":\"-\",\"A\":\"+\"}}");
    397   free(s);
    398   terminateG(B);
    399   freeManyG(&n, &ds);
    400 
    401   // array
    402   initiateG(&d);
    403   pushG(&a, "k");
    404   pushG(&a, 4);
    405   setG(&d, "0", &a);
    406   setTopG(&n, &d);
    407   B = serialG(&n);
    408   logI("len %u", lenG(B));
    409   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    410   s = sToString((smallt *) B->B);
    411   ck_assert_str_eq(s, "[0x6e,0x01,0x30,0x00,0x02,0x45,0x6b,0x00,0x08]");
    412   free(s);
    413   deserialG(&ds, B);
    414   s = toStringG(&ds);
    415   ck_assert_str_eq(s, "{\"0\":[\"k\",4]}");
    416   free(s);
    417   terminateG(B);
    418   freeManyG(&n, &ds);
    419 
    420   // uniform array
    421   initiateG(&d);
    422   initiateG(&a);
    423   pushG(&a, 1);
    424   pushG(&a, 2);
    425   pushG(&a, 3);
    426   pushG(&a, 4);
    427   setG(&d, "0", &a);
    428   setTopG(&n, &d);
    429   B = serialG(&n);
    430   logI("len %u", lenG(B));
    431   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    432   s = sToString((smallt *) B->B);
    433   ck_assert_str_eq(s, "[0xfe,0x01,0x30,0x00,0x44,0x02,0x04,0x06,0x08]");
    434   free(s);
    435   deserialG(&ds, B);
    436   s = toStringG(&ds);
    437   ck_assert_str_eq(s, "{\"0\":[1,2,3,4]}");
    438   free(s);
    439   terminateG(B);
    440   freeManyG(&n, &ds);
    441 
    442   // smallBytes
    443   initiateG(&d);
    444   createSmallBytes(b);
    445   createSmallBytes(b1);
    446   pushG(&b, 1);
    447   pushG(&b, 2);
    448   pushG(&b, 3);
    449   pushG(&b, 4);
    450   pushG(&b1, 5);
    451   pushG(&b1, 6);
    452   pushG(&b1, 7);
    453   setG(&d, "0", &b);
    454   setG(&d, "1", &b1);
    455   setTopG(&n, &d);
    456   B = serialG(&n);
    457   logI("len %u", lenG(B));
    458   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    459   s = sToString((smallt *) B->B);
    460   ck_assert_str_eq(s, "[0x7e,0x02,0x30,0x00,0x04,0x01,0x02,0x03,0x04,0x31,0x00,0x03,0x05,0x06,0x07]");
    461   free(s);
    462   deserialG(&ds, B);
    463   s = toStringG(&ds);
    464   ck_assert_str_eq(s, "{"_"0"_":[0x01,0x02,0x03,0x04],"_"1"_":[0x05,0x06,0x07]}");
    465   free(s);
    466   terminateG(B);
    467   freeManyG(&n, &ds);
    468 
    469 }
    470 
    471 
    472 // uniformArray
    473 void uniformArrayT(void) {
    474 
    475   // STEPS
    476   // init
    477   // init allocate
    478   // terminate
    479   // allocate
    480   // string
    481   // duplicate
    482 
    483   createNetSerial(n);
    484   createNetSerial(ds);
    485   char *s;
    486   smallBytest *B;
    487   createSmallArray(A);
    488   createSmallDict(dd);
    489   createSmallArray(a);
    490 
    491   // undefined
    492   undefinedt *oU = allocUndefined();
    493   pushG(&A, oU);
    494   pushG(&A, oU);
    495   pushG(&A, oU);
    496   pushG(&A, oU);
    497   pushG(&A, oU);
    498   pushNFreeG(&A, oU);
    499   setTopG(&n, &A);
    500   B = serialG(&n);
    501   logI("len %u", lenG(B));
    502   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    503   s = sToString((smallt *) B->B);
    504   ck_assert_str_eq(s, "[0x0f,0x06]");
    505   free(s);
    506   deserialG(&ds, B);
    507   s = toStringG(&ds);
    508   ck_assert_str_eq(s, "[null,null,null,null,null,null]");
    509   free(s);
    510   terminateG(B);
    511   freeManyG(&n, &ds);
    512 
    513   // empty dict
    514   initiateG(&A);
    515   setTopG(&n, &A);
    516   B = serialG(&n);
    517   logI("len %u", lenG(B));
    518   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    519   s = sToString((smallt *) B->B);
    520   ck_assert_str_eq(s, "[0x0f,0x00]");
    521   free(s);
    522   deserialG(&ds, B);
    523   s = toStringG(&ds);
    524   ck_assert_str_eq(s, "[]");
    525   free(s);
    526   terminateG(B);
    527   freeManyG(&n, &ds);
    528 
    529   // bool
    530   initiateG(&A);
    531   pushG(&A, TRUE);
    532   pushG(&A, TRUE);
    533   pushG(&A, TRUE);
    534   pushG(&A, TRUE);
    535   setTopG(&n, &A);
    536   B = serialG(&n);
    537   logI("len %u", lenG(B));
    538   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    539   s = sToString((smallt *) B->B);
    540   ck_assert_str_eq(s, "[0x1f,0x04,0x0f]");
    541   free(s);
    542   deserialG(&ds, B);
    543   s = toStringG(&ds);
    544   ck_assert_str_eq(s, "[true,true,true,true]");
    545   free(s);
    546   terminateG(B);
    547   freeManyG(&n, &ds);
    548 
    549   // double
    550   initiateG(&A);
    551   pushG(&A, 1.1);
    552   pushG(&A, 2.2);
    553   pushG(&A, 3.3);
    554   setTopG(&n, &A);
    555   B = serialG(&n);
    556   logI("len %u", lenG(B));
    557   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    558   s = sToString((smallt *) B->B);
    559   ck_assert_str_eq(s, "[0x3f,0x03,0x9a,0x99,0x99,0x99,0x99,0x99,0xf1,0x3f,0x9a,0x99,0x99,0x99,0x99,0x99,0x01,0x40,0x66,0x66,0x66,0x66,0x66,0x66,0x0a,0x40]");
    560   free(s);
    561   deserialG(&ds, B);
    562   s = toStringG(&ds);
    563   ck_assert_str_eq(s, "[1.100000e+00,2.200000e+00,3.300000e+00]");
    564   free(s);
    565   terminateG(B);
    566   freeManyG(&n, &ds);
    567 
    568   // int
    569   initiateG(&A);
    570   pushG(&A, 1);
    571   pushG(&A, 2);
    572   setTopG(&n, &A);
    573   B = serialG(&n);
    574   logI("len %u", lenG(B));
    575   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    576   s = sToString((smallt *) B->B);
    577   ck_assert_str_eq(s, "[0x4f,0x02,0x02,0x04]");
    578   free(s);
    579   deserialG(&ds, B);
    580   s = toStringG(&ds);
    581   ck_assert_str_eq(s, "[1,2]");
    582   free(s);
    583   terminateG(B);
    584   freeManyG(&n, &ds);
    585 
    586   // string
    587   initiateG(&A);
    588   pushG(&A, "a");
    589   pushG(&A, "A");
    590   pushG(&A, "z");
    591   setTopG(&n, &A);
    592   B = serialG(&n);
    593   logI("len %u", lenG(B));
    594   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    595   s = sToString((smallt *) B->B);
    596   ck_assert_str_eq(s, "[0x5f,0x03,0x61,0x00,0x41,0x00,0x7a,0x00]");
    597   free(s);
    598   deserialG(&ds, B);
    599   s = toStringG(&ds);
    600   ck_assert_str_eq(s, "[\"a\",\"A\",\"z\"]");
    601   free(s);
    602   terminateG(B);
    603   freeManyG(&n, &ds);
    604 
    605   // dict
    606   initiateG(&A);
    607   setG(&dd, "9", "z");
    608   setG(&dd, "1", 1);
    609   pushG(&A, &dd);
    610   initiateG(&dd);
    611   setG(&dd, "Z", "-");
    612   setG(&dd, "A", 234);
    613   pushG(&A, &dd);
    614   setTopG(&n, &A);
    615   logVarG(&n);
    616   B = serialG(&n);
    617   logI("len %u", lenG(B));
    618   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    619   s = sToString((smallt *) B->B);
    620   ck_assert_str_eq(s, "[0x2f,0x02,0x02,0x39,0x00,0x45,0x7a,0x00,0x31,0x00,0x02,0x02,0x5a,0x00,0x45,0x2d,0x00,0x41,0x00,0xd4,0x03]");
    621   free(s);
    622   deserialG(&ds, B);
    623   s = toStringG(&ds);
    624   ck_assert_str_eq(s, "[{\"9\":\"z\",\"1\":1},{\"Z\":\"-\",\"A\":234}]");
    625   free(s);
    626   terminateG(B);
    627   freeManyG(&n, &ds);
    628 
    629   // uniform dict
    630   initiateG(&dd);
    631   initiateG(&A);
    632   setG(&dd, "9", 1);
    633   setG(&dd, "1", 2);
    634   pushG(&A, &dd);
    635   initiateG(&dd);
    636   setG(&dd, "Z", "-");
    637   setG(&dd, "A", "+");
    638   pushG(&A, &dd);
    639   setTopG(&n, &A);
    640   logVarG(&n);
    641   B = serialG(&n);
    642   logI("len %u", lenG(B));
    643   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    644   s = sToString((smallt *) B->B);
    645   ck_assert_str_eq(s, "[0xef,0x02,0x24,0x39,0x00,0x02,0x31,0x00,0x04,0x25,0x5a,0x00,0x2d,0x00,0x41,0x00,0x2b,0x00]");
    646   free(s);
    647   deserialG(&ds, B);
    648   s = toStringG(&ds);
    649   ck_assert_str_eq(s, "[{\"9\":1,\"1\":2},{\"Z\":\"-\",\"A\":\"+\"}]");
    650   free(s);
    651   terminateG(B);
    652   freeManyG(&n, &ds);
    653 
    654   // array
    655   initiateG(&A);
    656   pushG(&a, "k");
    657   pushG(&a, 4);
    658   pushG(&A, &a);
    659   setTopG(&n, &A);
    660   B = serialG(&n);
    661   logI("len %u", lenG(B));
    662   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    663   s = sToString((smallt *) B->B);
    664   ck_assert_str_eq(s, "[0x6f,0x01,0x02,0x45,0x6b,0x00,0x08]");
    665   free(s);
    666   deserialG(&ds, B);
    667   s = toStringG(&ds);
    668   ck_assert_str_eq(s, "[[\"k\",4]]");
    669   free(s);
    670   terminateG(B);
    671   freeManyG(&n, &ds);
    672 
    673   initiateG(&A);
    674   initiateG(&a);
    675   pushG(&a, 1);
    676   pushG(&a, 2);
    677   pushG(&a, 3);
    678   pushG(&a, 4);
    679   pushG(&A, &a);
    680   setTopG(&n, &A);
    681   B = serialG(&n);
    682   logI("len %u", lenG(B));
    683   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    684   s = sToString((smallt *) B->B);
    685   ck_assert_str_eq(s, "[0xff,0x01,0x44,0x02,0x04,0x06,0x08]");
    686   free(s);
    687   deserialG(&ds, B);
    688   s = toStringG(&ds);
    689   ck_assert_str_eq(s, "[[1,2,3,4]]");
    690   free(s);
    691   terminateG(B);
    692   freeManyG(&n, &ds);
    693 
    694   // many bools in uniform array
    695   parseG(&n, "[true,true,true,true,true,true,true,true,false,true]");
    696   logVarG(&n);
    697   B = serialG(&n);
    698   logI("len %u", lenG(B));
    699   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    700   s = sToString((smallt *) B->B);
    701   ck_assert_str_eq(s, "[0x1f,0x0a,0xff,0x02]");
    702   free(s);
    703   deserialG(&ds, B);
    704   s = toStringG(&ds);
    705   ck_assert_str_eq(s, "[true,true,true,true,true,true,true,true,false,true]");
    706   free(s);
    707   terminateG(B);
    708   freeManyG(&n, &ds);
    709 
    710   // smallBytes
    711   initiateG(&A);
    712   createSmallBytes(b);
    713   pushG(&b, 1);
    714   pushG(&b, 2);
    715   pushG(&b, 3);
    716   pushG(&b, 4);
    717   pushG(&b, 5);
    718   pushG(&b, 6);
    719   pushG(&A, &b);
    720   initiateG(&b);
    721   pushG(&b, 7);
    722   pushG(&b, 8);
    723   pushG(&b, 9);
    724   pushG(&b, 10);
    725   pushG(&b, 11);
    726   pushG(&b, 12);
    727   pushG(&A, &b);
    728   setTopG(&n, &A);
    729   logVarG(&n);
    730   B = serialG(&n);
    731   logI("len %u", lenG(B));
    732   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    733   s = sToString((smallt *) B->B);
    734   ck_assert_str_eq(s, "[0x7f,0x02,0x06,0x01,0x02,0x03,0x04,0x05,0x06,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c]");
    735   free(s);
    736   deserialG(&ds, B);
    737   s = toStringG(&ds);
    738   ck_assert_str_eq(s, "[[0x01,0x02,0x03,0x04,0x05,0x06],[0x07,0x08,0x09,0x0a,0x0b,0x0c]]");
    739   free(s);
    740   terminateG(B);
    741   freeManyG(&n, &ds);
    742 
    743 }
    744 
    745 
    746 // dict with values, dict, array, uniforms, packed test high/low nibbles
    747 void dictT(void) {
    748 
    749   // STEPS
    750   // init
    751   // init allocate
    752   // terminate
    753   // allocate
    754   // string
    755   // duplicate
    756 
    757   createNetSerial(n);
    758   createNetSerial(ds);
    759   char *s;
    760   smallBytest *B;
    761   createSmallDict(d);
    762   createSmallDict(dd);
    763   createSmallArray(a);
    764 
    765   // dict with a deleted element (empty with dict->count == 1)
    766   initiateG(&d);
    767   setG(&d, "0", NULL);
    768   delElemG(&d, "0");
    769   setTopG(&n, &d);
    770   logVarG(&n);
    771   B = serialG(&n);
    772   logI("len %u", lenG(B));
    773   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    774   s = sToString((smallt *) B->B);
    775   ck_assert_str_eq(s, "[0x0e,0x00]");
    776   free(s);
    777   deserialG(&ds, B);
    778   s = toStringG(&ds);
    779   ck_assert_str_eq(s, "{}");
    780   free(s);
    781   terminateG(B);
    782   freeManyG(&n, &ds);
    783 
    784   // null and uniform dict
    785   initiateG(&d);
    786   setG(&d, "0", NULL);
    787   initiateG(&dd);
    788   setG(&dd, "Z", "-");
    789   setG(&dd, "A", "+");
    790   setG(&d, "1", &dd);
    791   setTopG(&n, &d);
    792   logVarG(&n);
    793   B = serialG(&n);
    794   logI("len %u", lenG(B));
    795   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    796   s = sToString((smallt *) B->B);
    797   ck_assert_str_eq(s, "[0x22,0x30,0x00,0xe0,0x31,0x00,0x25,0x5a,0x00,0x2d,0x00,0x41,0x00,0x2b,0x00]");
    798   free(s);
    799   deserialG(&ds, B);
    800   s = toStringG(&ds);
    801   ck_assert_str_eq(s, "{\"0\":null,\"1\":{\"Z\":\"-\",\"A\":\"+\"}}");
    802   free(s);
    803   terminateG(B);
    804   freeManyG(&n, &ds);
    805 
    806   // null and dict
    807   initiateG(&d);
    808   setG(&d, "0", NULL);
    809   initiateG(&dd);
    810   setG(&dd, "Z", "-");
    811   setG(&dd, "A", 1);
    812   setG(&d, "1", &dd);
    813   setTopG(&n, &d);
    814   logVarG(&n);
    815   B = serialG(&n);
    816   logI("len %u", lenG(B));
    817   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    818   s = sToString((smallt *) B->B);
    819   ck_assert_str_eq(s, "[0x22,0x30,0x00,0x20,0x31,0x00,0x02,0x5a,0x00,0x45,0x2d,0x00,0x41,0x00,0x02]");
    820   free(s);
    821   deserialG(&ds, B);
    822   s = toStringG(&ds);
    823   ck_assert_str_eq(s, "{\"0\":null,\"1\":{\"Z\":\"-\",\"A\":1}}");
    824   free(s);
    825   terminateG(B);
    826   freeManyG(&n, &ds);
    827 
    828   // bool and uniform dict
    829   initiateG(&d);
    830   setG(&d, "0", TRUE);
    831   initiateG(&dd);
    832   setG(&dd, "Z", "-");
    833   setG(&dd, "A", "+");
    834   setG(&d, "1", &dd);
    835   setTopG(&n, &d);
    836   logVarG(&n);
    837   B = serialG(&n);
    838   logI("len %u", lenG(B));
    839   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    840   s = sToString((smallt *) B->B);
    841   ck_assert_str_eq(s, "[0x22,0x30,0x00,0x11,0x31,0x00,0x5e,0x02,0x5a,0x00,0x2d,0x00,0x41,0x00,0x2b,0x00]");
    842   free(s);
    843   deserialG(&ds, B);
    844   s = toStringG(&ds);
    845   ck_assert_str_eq(s, "{\"0\":true,\"1\":{\"Z\":\"-\",\"A\":\"+\"}}");
    846   free(s);
    847   terminateG(B);
    848   freeManyG(&n, &ds);
    849 
    850   // null element and uniform array
    851   initiateG(&d);
    852   setG(&d, "1", NULL);
    853   initiateG(&a);
    854   pushG(&a, 1);
    855   pushG(&a, 2);
    856   pushG(&a, 3);
    857   pushG(&a, 4);
    858   setG(&d, "0", &a);
    859   setTopG(&n, &d);
    860   logVarG(&n);
    861   B = serialG(&n);
    862   logI("len %u", lenG(B));
    863   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    864   s = sToString((smallt *) B->B);
    865   ck_assert_str_eq(s, "[0x22,0x31,0x00,0xf0,0x30,0x00,0x44,0x02,0x04,0x06,0x08]");
    866   free(s);
    867   deserialG(&ds, B);
    868   s = toStringG(&ds);
    869   ck_assert_str_eq(s, "{\"1\":null,\"0\":[1,2,3,4]}");
    870   free(s);
    871   terminateG(B);
    872   freeManyG(&n, &ds);
    873 
    874   // uniform array high nibble
    875   initiateG(&d);
    876   setG(&d, "1", TRUE);
    877   initiateG(&a);
    878   pushG(&a, 1);
    879   pushG(&a, 2);
    880   pushG(&a, 3);
    881   pushG(&a, 4);
    882   setG(&d, "0", &a);
    883   setTopG(&n, &d);
    884   logVarG(&n);
    885   B = serialG(&n);
    886   logI("len %u", lenG(B));
    887   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    888   s = sToString((smallt *) B->B);
    889   ck_assert_str_eq(s, "[0x22,0x31,0x00,0x11,0x30,0x00,0x4f,0x04,0x02,0x04,0x06,0x08]");
    890   free(s);
    891   deserialG(&ds, B);
    892   s = toStringG(&ds);
    893   ck_assert_str_eq(s, "{\"1\":true,\"0\":[1,2,3,4]}");
    894   free(s);
    895   terminateG(B);
    896   freeManyG(&n, &ds);
    897 
    898   // uniform array in high nibble
    899   initiateG(&d);
    900   setG(&d, "1", "1");
    901   initiateG(&a);
    902   pushG(&a, 1);
    903   pushG(&a, 2);
    904   pushG(&a, 3);
    905   pushG(&a, 4);
    906   setG(&d, "0", &a);
    907   setTopG(&n, &d);
    908   logVarG(&n);
    909   B = serialG(&n);
    910   logI("len %u", lenG(B));
    911   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    912   s = sToString((smallt *) B->B);
    913   ck_assert_str_eq(s, "[0x22,0x31,0x00,0xf5,0x31,0x00,0x30,0x00,0x44,0x02,0x04,0x06,0x08]");
    914   free(s);
    915   deserialG(&ds, B);
    916   s = toStringG(&ds);
    917   ck_assert_str_eq(s, "{\"1\":\"1\",\"0\":[1,2,3,4]}");
    918   free(s);
    919   terminateG(B);
    920   freeManyG(&n, &ds);
    921 
    922   // low and high nibble undefined
    923   parseG(&n, "{"_"0"_":null,"_"1"_":null, "_"2"_":1}");
    924   logVarG(&n);
    925   B = serialG(&n);
    926   logI("len %u", lenG(B));
    927   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    928   s = sToString((smallt *) B->B);
    929   ck_assert_str_eq(s, "[0x32,0x30,0x00,0x00,0x31,0x00,0x32,0x00,0x24]");
    930   free(s);
    931   deserialG(&ds, B);
    932   s = toStringG(&ds);
    933   ck_assert_str_eq(s, "{\"0\":null,\"1\":null,\"2\":1}");
    934   free(s);
    935   terminateG(B);
    936   freeManyG(&n, &ds);
    937 
    938   // low and high nibble bool
    939   parseG(&n, "{"_"z"_":null,"_"0"_":true,"_"1"_":true, "_"2"_":true, "_"3"_":true"_"4"_":true"_"5"_":true, "_"6"_":true, "_"7"_":true, "_"8"_":true, "_"9"_":true, "_"a"_":true, "_"b"_":true, "_"c"_":true, "_"d"_":true}");
    940   logVarG(&n);
    941   B = serialG(&n);
    942   logI("len %u", lenG(B));
    943   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    944   s = sToString((smallt *) B->B);
    945   ck_assert_str_eq(s, "[0xf2,0x01,0x7a,0x00,0x10,0x30,0x00,0xff,0x31,0x00,0x11,0x32,0x00,0x33,0x00,0x11,0x34,0x00,0x35,0x00,0x11,0x36,0x00,0x37,0x00,0x11,0x38,0x00,0x3f,0x39,0x00,0x11,0x61,0x00,0x62,0x00,0x11,0x63,0x00,0x64,0x00,0x01]");
    946   free(s);
    947   deserialG(&ds, B);
    948   s = toStringG(&ds);
    949   ck_assert_str_eq(s, "{\"z\":null,\"0\":true,\"1\":true,\"2\":true,\"3\":true,\"4\":true,\"5\":true,\"6\":true,\"7\":true,\"8\":true,\"9\":true,\"a\":true,\"b\":true,\"c\":true,\"d\":true}");
    950   free(s);
    951   terminateG(B);
    952   freeManyG(&n, &ds);
    953 
    954   // low and high nibble bool - deserialDict ctx->nibble == lowNbl and ctx->boolShift == 8
    955   parseG(&n, "{"_"z"_":null,"_"0"_":true,"_"1"_":true, "_"2"_":true, "_"3"_":true, "_"4"_":true, "_"5"_":true, "_"6"_":true, "_"7"_":true, \"Z\": null, "_"8"_":true, "_"9"_":true, "_"a"_":true, "_"b"_":true, "_"c"_":true, "_"d"_":true}");
    956   logVarG(&n);
    957   B = serialG(&n);
    958   logI("len %u", lenG(B));
    959   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    960   s = sToString((smallt *) B->B);
    961   ck_assert_str_eq(s, "[0x82,0x02,0x7a,0x00,0x10,0x30,0x00,0xff,0x31,0x00,0x11,0x32,0x00,0x33,0x00,0x11,0x34,0x00,0x35,0x00,0x11,0x36,0x00,0x37,0x00,0x01,0x5a,0x00,0x38,0x00,0xf1,0x39,0x00,0x11,0x61,0x00,0x62,0x00,0x11,0x63,0x00,0x03,0x64,0x00,0x01]");
    962   free(s);
    963   deserialG(&ds, B);
    964   s = toStringG(&ds);
    965   ck_assert_str_eq(s, "{\"z\":null,\"0\":true,\"1\":true,\"2\":true,\"3\":true,\"4\":true,\"5\":true,\"6\":true,\"7\":true,\"Z\":null,\"8\":true,\"9\":true,\"a\":true,\"b\":true,\"c\":true,\"d\":true}");
    966   free(s);
    967   terminateG(B);
    968   freeManyG(&n, &ds);
    969 
    970   // dict in dict
    971   parseG(&n, "{"_"0"_":{\"0\":true}, "_"2"_":{\"0\":false},\"z\":null}");
    972   logVarG(&n);
    973   B = serialG(&n);
    974   logI("len %u", lenG(B));
    975   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    976   s = sToString((smallt *) B->B);
    977   ck_assert_str_eq(s, "[0x32,0x30,0x00,0x1e,0x01,0x30,0x00,0x01,0x32,0x00,0x1e,0x01,0x30,0x00,0x7a,0x00,0x00]");
    978   free(s);
    979   deserialG(&ds, B);
    980   s = toStringG(&ds);
    981   ck_assert_str_eq(s, "{\"0\":{\"0\":true},\"2\":{\"0\":false},\"z\":null}");
    982   free(s);
    983   terminateG(B);
    984   freeManyG(&n, &ds);
    985 
    986 
    987   // low and high nibble double
    988   parseG(&n, "{"_"0"_":0.0, "_"2"_":2.0,\"z\":null}");
    989   logVarG(&n);
    990   B = serialG(&n);
    991   logI("len %u", lenG(B));
    992   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
    993   s = sToString((smallt *) B->B);
    994   ck_assert_str_eq(s, "[0x32,0x30,0x00,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x7a,0x00,0x00]");
    995   free(s);
    996   deserialG(&ds, B);
    997   s = toStringG(&ds);
    998   ck_assert_str_eq(s, "{\"0\":0.000000e+00,\"2\":2.000000e+00,\"z\":null}");
    999   free(s);
   1000   terminateG(B);
   1001   freeManyG(&n, &ds);
   1002 
   1003   // high nibble string
   1004   parseG(&n, "{"_"0"_":null, "_"2"_":\"2.0\",\"z\":null}");
   1005   logVarG(&n);
   1006   B = serialG(&n);
   1007   logI("len %u", lenG(B));
   1008   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1009   s = sToString((smallt *) B->B);
   1010   ck_assert_str_eq(s, "[0x32,0x30,0x00,0x50,0x32,0x00,0x32,0x2e,0x30,0x00,0x7a,0x00,0x00]");
   1011   free(s);
   1012   deserialG(&ds, B);
   1013   s = toStringG(&ds);
   1014   ck_assert_str_eq(s, "{\"0\":null,\"2\":\"2.0\",\"z\":null}");
   1015   free(s);
   1016   terminateG(B);
   1017   freeManyG(&n, &ds);
   1018 
   1019   // array in dict
   1020   parseG(&n, "{"_"0"_":null, "_"2"_":[1,2],\"z\":[true,3]}");
   1021   logVarG(&n);
   1022   B = serialG(&n);
   1023   logI("len %u", lenG(B));
   1024   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1025   s = sToString((smallt *) B->B);
   1026   ck_assert_str_eq(s, "[0x32,0x30,0x00,0xf0,0x32,0x00,0x24,0x02,0x04,0x7a,0x00,0x26,0x11,0x64]");
   1027   free(s);
   1028   deserialG(&ds, B);
   1029   s = toStringG(&ds);
   1030   ck_assert_str_eq(s, "{\"0\":null,\"2\":[1,2],\"z\":[true,3]}");
   1031   free(s);
   1032   terminateG(B);
   1033   freeManyG(&n, &ds);
   1034 
   1035 
   1036 
   1037   // packed dicts
   1038   parseG(&n, "{"_"0"_":{},"_"1"_":{}, "_"2"_":{}, "_"3"_":{}, "_"4"_":{}, "_"5"_": 1}");
   1039   logVarG(&n);
   1040   B = serialG(&n);
   1041   logI("len %u", lenG(B));
   1042   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1043   s = sToString((smallt *) B->B);
   1044   ck_assert_str_eq(s, "[0x62,0x30,0x00,0x58,0x00,0x31,0x00,0x00,0x32,0x00,0x00,0x33,0x00,0x00,0x34,0x00,0x00,0x35,0x00,0x24]");
   1045   free(s);
   1046   deserialG(&ds, B);
   1047   s = toStringG(&ds);
   1048   ck_assert_str_eq(s, "{\"0\":{},\"1\":{},\"2\":{},\"3\":{},\"4\":{},\"5\":1}");
   1049   free(s);
   1050   terminateG(B);
   1051   freeManyG(&n, &ds);
   1052 
   1053   parseG(&n, "{"_"0"_":{"_"0"_":null,"_"1"_":1},"_"1"_":{"_"0"_":"_"0"_","_"1"_":1}, "_"2"_":{"_"0"_":"_"0"_","_"1"_":1}, "_"3"_":{"_"0"_":"_"0"_","_"1"_":1}, "_"4"_":{"_"0"_":"_"0"_","_"1"_":1}, "_"5"_": 1}");
   1054   logVarG(&n);
   1055   B = serialG(&n);
   1056   logI("len %u", lenG(B));
   1057   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1058   s = sToString((smallt *) B->B);
   1059   ck_assert_str_eq(s, "[0x62,0x30,0x00,0x58,0x02,0x30,0x00,0x40,0x31,0x00,0x02,0x31,0x00,0x02,0x30,0x00,0x45,0x30,0x00,0x31,0x00,0x02,0x32,0x00,0x02,0x30,0x00,0x45,0x30,0x00,0x31,0x00,0x02,0x33,0x00,0x02,0x30,0x00,0x45,0x30,0x00,0x31,0x00,0x02,0x34,0x00,0x02,0x30,0x00,0x45,0x30,0x00,0x31,0x00,0x02,0x35,0x00,0x24]");
   1060   free(s);
   1061   deserialG(&ds, B);
   1062   s = toStringG(&ds);
   1063   ck_assert_str_eq(s, "{\"0\":{\"0\":null,\"1\":1},\"1\":{\"0\":\"0\",\"1\":1},\"2\":{\"0\":\"0\",\"1\":1},\"3\":{\"0\":\"0\",\"1\":1},\"4\":{\"0\":\"0\",\"1\":1},\"5\":1}");
   1064   free(s);
   1065   terminateG(B);
   1066   freeManyG(&n, &ds);
   1067 
   1068   // high nibble packed dicts
   1069   parseG(&n, "{\"a\": null,"_"0"_":{},"_"1"_":{}, "_"2"_":{}, "_"3"_":{}, "_"4"_":{}, "_"5"_": 1}");
   1070   logVarG(&n);
   1071   B = serialG(&n);
   1072   logI("len %u", lenG(B));
   1073   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1074   s = sToString((smallt *) B->B);
   1075   ck_assert_str_eq(s, "[0x72,0x61,0x00,0x80,0x30,0x00,0x05,0x00,0x31,0x00,0x00,0x32,0x00,0x00,0x33,0x00,0x00,0x34,0x00,0x00,0x35,0x00,0x24]");
   1076   free(s);
   1077   deserialG(&ds, B);
   1078   s = toStringG(&ds);
   1079   ck_assert_str_eq(s, "{\"a\":null,\"0\":{},\"1\":{},\"2\":{},\"3\":{},\"4\":{},\"5\":1}");
   1080   free(s);
   1081   terminateG(B);
   1082   freeManyG(&n, &ds);
   1083 
   1084 
   1085   // packed doubles
   1086   parseG(&n, "{"_"0"_":0.0,"_"1"_":1.0, "_"2"_":2.0, "_"3"_":3.0, "_"4"_":4.0, "_"5"_": null}");
   1087   logVarG(&n);
   1088   B = serialG(&n);
   1089   logI("len %u", lenG(B));
   1090   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1091   s = sToString((smallt *) B->B);
   1092   ck_assert_str_eq(s, "[0x62,0x30,0x00,0x59,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x31,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x40,0x34,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x40,0x35,0x00,0x00]");
   1093   free(s);
   1094   deserialG(&ds, B);
   1095   s = toStringG(&ds);
   1096   ck_assert_str_eq(s, "{\"0\":0.000000e+00,\"1\":1.000000e+00,\"2\":2.000000e+00,\"3\":3.000000e+00,\"4\":4.000000e+00,\"5\":null}");
   1097   free(s);
   1098   terminateG(B);
   1099   freeManyG(&n, &ds);
   1100 
   1101   // high nibble packed doubles
   1102   parseG(&n, "{\"a\": null, "_"0"_":0.0,"_"1"_":1.0, "_"2"_":2.0, "_"3"_":3.0, "_"4"_":4.0, "_"5"_": null}");
   1103   logVarG(&n);
   1104   B = serialG(&n);
   1105   logI("len %u", lenG(B));
   1106   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1107   s = sToString((smallt *) B->B);
   1108   ck_assert_str_eq(s, "[0x72,0x61,0x00,0x90,0x30,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x31,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f,0x32,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x40,0x34,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x40,0x35,0x00,0x00]");
   1109   free(s);
   1110   deserialG(&ds, B);
   1111   s = toStringG(&ds);
   1112   ck_assert_str_eq(s, "{\"a\":null,\"0\":0.000000e+00,\"1\":1.000000e+00,\"2\":2.000000e+00,\"3\":3.000000e+00,\"4\":4.000000e+00,\"5\":null}");
   1113   free(s);
   1114   terminateG(B);
   1115   freeManyG(&n, &ds);
   1116 
   1117 
   1118   // packed ints
   1119   parseG(&n, "{\"1\":1,\"2\":2,\"3\":3,\"4\":4,\"Z\":\"l\"}");
   1120   logVarG(&n);
   1121   B = serialG(&n);
   1122   logI("len %u", lenG(B));
   1123   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1124   s = sToString((smallt *) B->B);
   1125   ck_assert_str_eq(s, "[0x52,0x31,0x00,0x4a,0x02,0x32,0x00,0x04,0x33,0x00,0x06,0x34,0x00,0x08,0x5a,0x00,0x05,0x6c,0x00]");
   1126   free(s);
   1127   deserialG(&ds, B);
   1128   s = toStringG(&ds);
   1129   ck_assert_str_eq(s, "{\"1\":1,\"2\":2,\"3\":3,\"4\":4,\"Z\":\"l\"}");
   1130   free(s);
   1131   terminateG(B);
   1132   freeManyG(&n, &ds);
   1133 
   1134   // high nibble packed ints
   1135   parseG(&n, "{\"0\":null,\"1\":1,\"2\":2,\"3\":3,\"4\":4,\"Z\":\"l\"}");
   1136   logVarG(&n);
   1137   B = serialG(&n);
   1138   logI("len %u", lenG(B));
   1139   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1140   s = sToString((smallt *) B->B);
   1141   ck_assert_str_eq(s, "[0x62,0x30,0x00,0xa0,0x31,0x00,0x04,0x02,0x32,0x00,0x04,0x33,0x00,0x06,0x34,0x00,0x08,0x5a,0x00,0x05,0x6c,0x00]");
   1142   free(s);
   1143   deserialG(&ds, B);
   1144   s = toStringG(&ds);
   1145   ck_assert_str_eq(s, "{\"0\":null,\"1\":1,\"2\":2,\"3\":3,\"4\":4,\"Z\":\"l\"}");
   1146   free(s);
   1147   terminateG(B);
   1148   freeManyG(&n, &ds);
   1149 
   1150 
   1151   // packed strings
   1152   parseG(&n, "{\"1\":\"1\",\"2\":\"2\",\"3\":\"3\",\"4\":\"4\",\"Z\":null}");
   1153   logVarG(&n);
   1154   B = serialG(&n);
   1155   logI("len %u", lenG(B));
   1156   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1157   s = sToString((smallt *) B->B);
   1158   ck_assert_str_eq(s, "[0x52,0x31,0x00,0x4b,0x31,0x00,0x32,0x00,0x32,0x00,0x33,0x00,0x33,0x00,0x34,0x00,0x34,0x00,0x5a,0x00,0x00]");
   1159   free(s);
   1160   deserialG(&ds, B);
   1161   s = toStringG(&ds);
   1162   ck_assert_str_eq(s, "{\"1\":\"1\",\"2\":\"2\",\"3\":\"3\",\"4\":\"4\",\"Z\":null}");
   1163   free(s);
   1164   terminateG(B);
   1165   freeManyG(&n, &ds);
   1166 
   1167   // high nibble packed strings
   1168   parseG(&n, "{\"0\":null,\"1\":\"1\",\"2\":\"2\",\"3\":\"3\",\"4\":\"4\",\"Z\":null}");
   1169   logVarG(&n);
   1170   B = serialG(&n);
   1171   logI("len %u", lenG(B));
   1172   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1173   s = sToString((smallt *) B->B);
   1174   ck_assert_str_eq(s, "[0x62,0x30,0x00,0xb0,0x31,0x00,0x04,0x31,0x00,0x32,0x00,0x32,0x00,0x33,0x00,0x33,0x00,0x34,0x00,0x34,0x00,0x5a,0x00,0x00]");
   1175   free(s);
   1176   deserialG(&ds, B);
   1177   s = toStringG(&ds);
   1178   ck_assert_str_eq(s, "{\"0\":null,\"1\":\"1\",\"2\":\"2\",\"3\":\"3\",\"4\":\"4\",\"Z\":null}");
   1179   free(s);
   1180   terminateG(B);
   1181   freeManyG(&n, &ds);
   1182 
   1183   // packed arrays
   1184   parseG(&n, "{\"1\":[],\"2\":[1],\"3\":[\"3r\"],\"4\":[true],\"Z\":null}");
   1185   logVarG(&n);
   1186   B = serialG(&n);
   1187   logI("len %u", lenG(B));
   1188   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1189   s = sToString((smallt *) B->B);
   1190   ck_assert_str_eq(s, "[0x52,0x31,0x00,0x4c,0x00,0x32,0x00,0x01,0x24,0x33,0x00,0x01,0x15,0x33,0x72,0x00,0x34,0x00,0x01,0x01,0x5a,0x00,0x00]");
   1191   free(s);
   1192   deserialG(&ds, B);
   1193   s = toStringG(&ds);
   1194   ck_assert_str_eq(s, "{\"1\":[],\"2\":[1],\"3\":[\"3r\"],\"4\":[true],\"Z\":null}");
   1195   free(s);
   1196   terminateG(B);
   1197   freeManyG(&n, &ds);
   1198 
   1199   // high nibble packed arrays
   1200   parseG(&n, "{\"0\":null,\"1\":[],\"2\":[1],\"3\":[\"3r\"],\"4\":[true],\"Z\":null}");
   1201   logVarG(&n);
   1202   B = serialG(&n);
   1203   logI("len %u", lenG(B));
   1204   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1205   s = sToString((smallt *) B->B);
   1206   ck_assert_str_eq(s, "[0x62,0x30,0x00,0xc0,0x31,0x00,0x04,0x00,0x32,0x00,0x01,0x24,0x33,0x00,0x01,0x15,0x33,0x72,0x00,0x34,0x00,0x01,0x01,0x5a,0x00,0x00]");
   1207   free(s);
   1208   deserialG(&ds, B);
   1209   s = toStringG(&ds);
   1210   ck_assert_str_eq(s, "{\"0\":null,\"1\":[],\"2\":[1],\"3\":[\"3r\"],\"4\":[true],\"Z\":null}");
   1211   free(s);
   1212   terminateG(B);
   1213   freeManyG(&n, &ds);
   1214 
   1215   // smallBytes
   1216   parseG(&n, "{"_"0"_":null,"_"z"_":[true,3]}");
   1217   createSmallBytes(b);
   1218   pushG(&b, 1);
   1219   pushG(&b, 2);
   1220   pushG(&b, 3);
   1221   pushG(&b, 4);
   1222   pushG(&b, 5);
   1223   pushG(&b, 6);
   1224   setG(&n, "bytes", &b);
   1225   logVarG(&n);
   1226   B = serialG(&n);
   1227   logI("len %u", lenG(B));
   1228   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1229   s = sToString((smallt *) B->B);
   1230   ck_assert_str_eq(s, "[0x32,0x30,0x00,0x60,0x7a,0x00,0x02,0x11,0x64,0x62,0x79,0x74,0x65,0x73,0x00,0x67,0x01,0x02,0x03,0x04,0x05,0x06]");
   1231   free(s);
   1232   deserialG(&ds, B);
   1233   s = toStringG(&ds);
   1234   ck_assert_str_eq(s, "{"_"0"_":null,"_"z"_":[true,3],"_"bytes"_":[0x01,0x02,0x03,0x04,0x05,0x06]}");
   1235   free(s);
   1236   terminateG(B);
   1237   freeManyG(&n, &ds);
   1238 
   1239   parseG(&n, "{"_"0"_":null,"_"z"_":[true,3],"_"1"_":null}");
   1240   initiateG(&b);
   1241   pushG(&b, 1);
   1242   pushG(&b, 2);
   1243   pushG(&b, 3);
   1244   pushG(&b, 4);
   1245   pushG(&b, 5);
   1246   pushG(&b, 6);
   1247   setG(&n, "bytes", &b);
   1248   logVarG(&n);
   1249   B = serialG(&n);
   1250   logI("len %u", lenG(B));
   1251   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1252   s = sToString((smallt *) B->B);
   1253   ck_assert_str_eq(s, "[0x42,0x30,0x00,0x60,0x7a,0x00,0x02,0x11,0x64,0x31,0x00,0x70,0x62,0x79,0x74,0x65,0x73,0x00,0x06,0x01,0x02,0x03,0x04,0x05,0x06]");
   1254   free(s);
   1255   deserialG(&ds, B);
   1256   s = toStringG(&ds);
   1257   ck_assert_str_eq(s, "{"_"0"_":null,"_"z"_":[true,3],"_"1"_":null,"_"bytes"_":[0x01,0x02,0x03,0x04,0x05,0x06]}");
   1258   free(s);
   1259   terminateG(B);
   1260   freeManyG(&n, &ds);
   1261 
   1262 }
   1263 
   1264 
   1265 // array with values, dict, array, uniforms, packed test high/low nibbles
   1266 void arrayT(void) {
   1267 
   1268   // STEPS
   1269   // init
   1270   // init allocate
   1271   // terminate
   1272   // allocate
   1273   // string
   1274   // duplicate
   1275 
   1276   createNetSerial(n);
   1277   createNetSerial(ds);
   1278   char *s;
   1279   smallBytest *B;
   1280   createSmallArray(A);
   1281   createSmallArray(a);
   1282 
   1283   // null and uniform array
   1284   initiateG(&A);
   1285   pushG(&A, NULL);
   1286   initiateG(&a);
   1287   pushG(&a, 1);
   1288   pushG(&a, 2);
   1289   pushG(&a, 3);
   1290   pushG(&a, 4);
   1291   pushG(&A, &a);
   1292   setTopG(&n, &A);
   1293   logVarG(&n);
   1294   B = serialG(&n);
   1295   logI("len %u", lenG(B));
   1296   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1297   s = sToString((smallt *) B->B);
   1298   ck_assert_str_eq(s, "[0x26,0xf0,0x44,0x02,0x04,0x06,0x08]");
   1299   free(s);
   1300   deserialG(&ds, B);
   1301   s = toStringG(&ds);
   1302   //ck_assert_str_eq(s, "[null,null]");
   1303   ck_assert_str_eq(s, "[null,[1,2,3,4]]");
   1304   free(s);
   1305   terminateG(B);
   1306   freeManyG(&n, &ds);
   1307 
   1308   // uniform array in high low
   1309   initiateG(&A);
   1310   pushG(&A, FALSE);
   1311   initiateG(&a);
   1312   pushG(&a, 1);
   1313   pushG(&a, 2);
   1314   pushG(&a, 3);
   1315   pushG(&a, 4);
   1316   pushG(&A, &a);
   1317   setTopG(&n, &A);
   1318   logVarG(&n);
   1319   B = serialG(&n);
   1320   logI("len %u", lenG(B));
   1321   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1322   s = sToString((smallt *) B->B);
   1323   ck_assert_str_eq(s, "[0x26,0x01,0x4f,0x04,0x02,0x04,0x06,0x08]");
   1324   free(s);
   1325   deserialG(&ds, B);
   1326   s = toStringG(&ds);
   1327   //ck_assert_str_eq(s, "[null,null]");
   1328   ck_assert_str_eq(s, "[false,[1,2,3,4]]");
   1329   free(s);
   1330   terminateG(B);
   1331   freeManyG(&n, &ds);
   1332 
   1333   // uniform array in high nibble
   1334   initiateG(&A);
   1335   pushG(&A, "1");
   1336   initiateG(&a);
   1337   pushG(&a, 1);
   1338   pushG(&a, 2);
   1339   pushG(&a, 3);
   1340   pushG(&a, 4);
   1341   pushG(&A, &a);
   1342   setTopG(&n, &A);
   1343   logVarG(&n);
   1344   B = serialG(&n);
   1345   logI("len %u", lenG(B));
   1346   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1347   s = sToString((smallt *) B->B);
   1348   ck_assert_str_eq(s, "[0x26,0xf5,0x31,0x00,0x44,0x02,0x04,0x06,0x08]");
   1349   free(s);
   1350   deserialG(&ds, B);
   1351   s = toStringG(&ds);
   1352   ck_assert_str_eq(s, "[\"1\",[1,2,3,4]]");
   1353   free(s);
   1354   terminateG(B);
   1355   freeManyG(&n, &ds);
   1356 
   1357   // high nibble array
   1358   parseG(&n, "[null, [1,null]]");
   1359   logVarG(&n);
   1360   B = serialG(&n);
   1361   logI("len %u", lenG(B));
   1362   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1363   s = sToString((smallt *) B->B);
   1364   ck_assert_str_eq(s, "[0x26,0x60,0x02,0x24,0x00]");
   1365   free(s);
   1366   deserialG(&ds, B);
   1367   s = toStringG(&ds);
   1368   ck_assert_str_eq(s, "[null,[1,null]]");
   1369   free(s);
   1370   terminateG(B);
   1371   freeManyG(&n, &ds);
   1372 
   1373   // low and high undefined
   1374   parseG(&n, "[null,null,1]");
   1375   logVarG(&n);
   1376   B = serialG(&n);
   1377   logI("len %u", lenG(B));
   1378   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1379   s = sToString((smallt *) B->B);
   1380   ck_assert_str_eq(s, "[0x36,0x00,0x24]");
   1381   free(s);
   1382   deserialG(&ds, B);
   1383   s = toStringG(&ds);
   1384   ck_assert_str_eq(s, "[null,null,1]");
   1385   free(s);
   1386   terminateG(B);
   1387   freeManyG(&n, &ds);
   1388 
   1389   // low and high nibble bool
   1390   parseG(&n, "[null,true,false,false,true,true,false,true,false,true,true,true,true,true]");
   1391   logVarG(&n);
   1392   B = serialG(&n);
   1393   logI("len %u", lenG(B));
   1394   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1395   s = sToString((smallt *) B->B);
   1396   ck_assert_str_eq(s, "[0xe6,0x01,0x10,0x59,0x11,0x11,0x11,0x11,0x1f,0x11,0x11]");
   1397   free(s);
   1398   deserialG(&ds, B);
   1399   s = toStringG(&ds);
   1400   ck_assert_str_eq(s, "[null,true,false,false,true,true,false,true,false,true,true,true,true,true]");
   1401   free(s);
   1402   terminateG(B);
   1403   freeManyG(&n, &ds);
   1404 
   1405   // low and high nibble bool - ctx->boolOffset != 0 ctx->nibble == lowNbl ctx->boolShift == 8
   1406   parseG(&n, "[true,false,false,true,null,true,false,true,false,true,true,true,true,true]");
   1407   logVarG(&n);
   1408   B = serialG(&n);
   1409   logI("len %u", lenG(B));
   1410   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1411   s = sToString((smallt *) B->B);
   1412   ck_assert_str_eq(s, "[0xe6,0x01,0x91,0x11,0x01,0x51,0x11,0x11,0x1f,0x11,0x11]");
   1413   free(s);
   1414   deserialG(&ds, B);
   1415   s = toStringG(&ds);
   1416   ck_assert_str_eq(s, "[true,false,false,true,null,true,false,true,false,true,true,true,true,true]");
   1417   free(s);
   1418   terminateG(B);
   1419   freeManyG(&n, &ds);
   1420 
   1421 
   1422   // dict in array
   1423   parseG(&n, "[{\"0\":null,\"1\":1},{\"2\":2},{\"3\":3},null]");
   1424   logVarG(&n);
   1425   B = serialG(&n);
   1426   logI("len %u", lenG(B));
   1427   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1428   s = sToString((smallt *) B->B);
   1429   ck_assert_str_eq(s, "[0x46,0x22,0x30,0x00,0x40,0x31,0x00,0x02,0x4e,0x01,0x32,0x00,0x04,0x4e,0x01,0x33,0x00,0x06,0x00]");
   1430   free(s);
   1431   deserialG(&ds, B);
   1432   s = toStringG(&ds);
   1433   ck_assert_str_eq(s, "[{\"0\":null,\"1\":1},{\"2\":2},{\"3\":3},null]");
   1434   free(s);
   1435   terminateG(B);
   1436   freeManyG(&n, &ds);
   1437 
   1438   // double in array
   1439   parseG(&n, "[1.0,2.0,null]");
   1440   logVarG(&n);
   1441   B = serialG(&n);
   1442   logI("len %u", lenG(B));
   1443   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1444   s = sToString((smallt *) B->B);
   1445   ck_assert_str_eq(s, "[0x36,0x33,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00]");
   1446   free(s);
   1447   deserialG(&ds, B);
   1448   s = toStringG(&ds);
   1449   ck_assert_str_eq(s, "[1.000000e+00,2.000000e+00,null]");
   1450   free(s);
   1451   terminateG(B);
   1452   freeManyG(&n, &ds);
   1453 
   1454   // int in array
   1455   parseG(&n, "[1,2,null]");
   1456   logVarG(&n);
   1457   B = serialG(&n);
   1458   logI("len %u", lenG(B));
   1459   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1460   s = sToString((smallt *) B->B);
   1461   ck_assert_str_eq(s, "[0x36,0x24,0x44,0x00]");
   1462   free(s);
   1463   deserialG(&ds, B);
   1464   s = toStringG(&ds);
   1465   ck_assert_str_eq(s, "[1,2,null]");
   1466   free(s);
   1467   terminateG(B);
   1468   freeManyG(&n, &ds);
   1469 
   1470   // string in array
   1471   parseG(&n, "[\"1\",\"2\",null]");
   1472   logVarG(&n);
   1473   B = serialG(&n);
   1474   logI("len %u", lenG(B));
   1475   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1476   s = sToString((smallt *) B->B);
   1477   ck_assert_str_eq(s, "[0x36,0x55,0x31,0x00,0x32,0x00,0x00]");
   1478   free(s);
   1479   deserialG(&ds, B);
   1480   s = toStringG(&ds);
   1481   ck_assert_str_eq(s, "[\"1\",\"2\",null]");
   1482   free(s);
   1483   terminateG(B);
   1484   freeManyG(&n, &ds);
   1485 
   1486   // array in array
   1487   parseG(&n, "[[],[1,2],null]");
   1488   logVarG(&n);
   1489   B = serialG(&n);
   1490   logI("len %u", lenG(B));
   1491   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1492   s = sToString((smallt *) B->B);
   1493   ck_assert_str_eq(s, "[0x36,0x0f,0x00,0x4f,0x02,0x02,0x04,0x00]");
   1494   free(s);
   1495   deserialG(&ds, B);
   1496   s = toStringG(&ds);
   1497   ck_assert_str_eq(s, "[[],[1,2],null]");
   1498   free(s);
   1499   terminateG(B);
   1500   freeManyG(&n, &ds);
   1501 
   1502 
   1503   // packed dicts
   1504   parseG(&n, "[{\"1\":1},{\"2\":2},{\"3\":3},{\"4\":4},null]");
   1505   logVarG(&n);
   1506   B = serialG(&n);
   1507   logI("len %u", lenG(B));
   1508   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1509   s = sToString((smallt *) B->B);
   1510   ck_assert_str_eq(s, "[0x56,0x48,0x01,0x31,0x00,0x24,0x01,0x32,0x00,0x44,0x01,0x33,0x00,0x64,0x01,0x34,0x00,0x84,0x01,0x00]");
   1511   free(s);
   1512   deserialG(&ds, B);
   1513   s = toStringG(&ds);
   1514   ck_assert_str_eq(s, "[{\"1\":1},{\"2\":2},{\"3\":3},{\"4\":4},null]");
   1515   free(s);
   1516   terminateG(B);
   1517   freeManyG(&n, &ds);
   1518 
   1519   // high nibble packed dicts
   1520   parseG(&n, "[null,{\"1\":1},{\"2\":2},{\"3\":3},{\"4\":4},null]");
   1521   logVarG(&n);
   1522   B = serialG(&n);
   1523   logI("len %u", lenG(B));
   1524   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1525   s = sToString((smallt *) B->B);
   1526   ck_assert_str_eq(s, "[0x66,0x80,0x04,0x01,0x31,0x00,0x24,0x01,0x32,0x00,0x44,0x01,0x33,0x00,0x64,0x01,0x34,0x00,0x84,0x01,0x00]");
   1527   free(s);
   1528   deserialG(&ds, B);
   1529   s = toStringG(&ds);
   1530   ck_assert_str_eq(s, "[null,{\"1\":1},{\"2\":2},{\"3\":3},{\"4\":4},null]");
   1531   free(s);
   1532   terminateG(B);
   1533   freeManyG(&n, &ds);
   1534 
   1535   // packed doubles
   1536   parseG(&n, "[1.0,2.0,3.0,4.0,null]");
   1537   logVarG(&n);
   1538   B = serialG(&n);
   1539   logI("len %u", lenG(B));
   1540   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1541   s = sToString((smallt *) B->B);
   1542   ck_assert_str_eq(s, "[0x56,0x49,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x40,0x00]");
   1543   free(s);
   1544   deserialG(&ds, B);
   1545   s = toStringG(&ds);
   1546   ck_assert_str_eq(s, "[1.000000e+00,2.000000e+00,3.000000e+00,4.000000e+00,null]");
   1547   free(s);
   1548   terminateG(B);
   1549   freeManyG(&n, &ds);
   1550 
   1551   // high nibble packed doubles
   1552   parseG(&n, "[null,1.0,2.0,3.0,4.0,null]");
   1553   logVarG(&n);
   1554   B = serialG(&n);
   1555   logI("len %u", lenG(B));
   1556   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1557   s = sToString((smallt *) B->B);
   1558   ck_assert_str_eq(s, "[0x66,0x90,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0xf0,0x3f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x10,0x40,0x00]");
   1559   free(s);
   1560   deserialG(&ds, B);
   1561   s = toStringG(&ds);
   1562   ck_assert_str_eq(s, "[null,1.000000e+00,2.000000e+00,3.000000e+00,4.000000e+00,null]");
   1563   free(s);
   1564   terminateG(B);
   1565   freeManyG(&n, &ds);
   1566 
   1567   // packed ints
   1568   parseG(&n, "[1,2,3,4,null]");
   1569   logVarG(&n);
   1570   B = serialG(&n);
   1571   logI("len %u", lenG(B));
   1572   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1573   s = sToString((smallt *) B->B);
   1574   ck_assert_str_eq(s, "[0x56,0x4a,0x02,0x04,0x06,0x08,0x00]");
   1575   free(s);
   1576   deserialG(&ds, B);
   1577   s = toStringG(&ds);
   1578   ck_assert_str_eq(s, "[1,2,3,4,null]");
   1579   free(s);
   1580   terminateG(B);
   1581   freeManyG(&n, &ds);
   1582 
   1583   // high nibble packed ints
   1584   parseG(&n, "[null,1,2,3,4,null]");
   1585   logVarG(&n);
   1586   B = serialG(&n);
   1587   logI("len %u", lenG(B));
   1588   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1589   s = sToString((smallt *) B->B);
   1590   ck_assert_str_eq(s, "[0x66,0xa0,0x04,0x02,0x04,0x06,0x08,0x00]");
   1591   free(s);
   1592   deserialG(&ds, B);
   1593   s = toStringG(&ds);
   1594   ck_assert_str_eq(s, "[null,1,2,3,4,null]");
   1595   free(s);
   1596   terminateG(B);
   1597   freeManyG(&n, &ds);
   1598 
   1599   // packed strings
   1600   parseG(&n, "[\"1\",\"2\",\"3\",\"4\",null]");
   1601   logVarG(&n);
   1602   B = serialG(&n);
   1603   logI("len %u", lenG(B));
   1604   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1605   s = sToString((smallt *) B->B);
   1606   ck_assert_str_eq(s, "[0x56,0x4b,0x31,0x00,0x32,0x00,0x33,0x00,0x34,0x00,0x00]");
   1607   free(s);
   1608   deserialG(&ds, B);
   1609   s = toStringG(&ds);
   1610   ck_assert_str_eq(s, "[\"1\",\"2\",\"3\",\"4\",null]");
   1611   free(s);
   1612   terminateG(B);
   1613   freeManyG(&n, &ds);
   1614 
   1615   // high nibble packed strings
   1616   parseG(&n, "[null,\"1\",\"2\",\"3\",\"4\",null]");
   1617   logVarG(&n);
   1618   B = serialG(&n);
   1619   logI("len %u", lenG(B));
   1620   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1621   s = sToString((smallt *) B->B);
   1622   ck_assert_str_eq(s, "[0x66,0xb0,0x04,0x31,0x00,0x32,0x00,0x33,0x00,0x34,0x00,0x00]");
   1623   free(s);
   1624   deserialG(&ds, B);
   1625   s = toStringG(&ds);
   1626   ck_assert_str_eq(s, "[null,\"1\",\"2\",\"3\",\"4\",null]");
   1627   free(s);
   1628   terminateG(B);
   1629   freeManyG(&n, &ds);
   1630 
   1631   // packed arrays
   1632   parseG(&n, "[[1],[2],[3],[4],null]");
   1633   logVarG(&n);
   1634   B = serialG(&n);
   1635   logI("len %u", lenG(B));
   1636   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1637   s = sToString((smallt *) B->B);
   1638   ck_assert_str_eq(s, "[0x56,0x4c,0x01,0x24,0x01,0x44,0x01,0x64,0x01,0x84,0x01,0x00]");
   1639   free(s);
   1640   deserialG(&ds, B);
   1641   s = toStringG(&ds);
   1642   ck_assert_str_eq(s, "[[1],[2],[3],[4],null]");
   1643   free(s);
   1644   terminateG(B);
   1645   freeManyG(&n, &ds);
   1646 
   1647   // high nibble packed arrays
   1648   parseG(&n, "[null,[1],[2],[3],[4],null]");
   1649   logVarG(&n);
   1650   B = serialG(&n);
   1651   logI("len %u", lenG(B));
   1652   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1653   s = sToString((smallt *) B->B);
   1654   ck_assert_str_eq(s, "[0x66,0xc0,0x04,0x01,0x24,0x01,0x44,0x01,0x64,0x01,0x84,0x01,0x00]");
   1655   free(s);
   1656   deserialG(&ds, B);
   1657   s = toStringG(&ds);
   1658   ck_assert_str_eq(s, "[null,[1],[2],[3],[4],null]");
   1659   free(s);
   1660   terminateG(B);
   1661   freeManyG(&n, &ds);
   1662 
   1663   // smallBytes
   1664   parseG(&n, "[1,2,null]");
   1665   createSmallBytes(b);
   1666   pushG(&b, 1);
   1667   pushG(&b, 2);
   1668   pushG(&b, 3);
   1669   pushG(&b, 4);
   1670   pushG(&b, 5);
   1671   pushG(&b, 6);
   1672   pushG(&n, &b);
   1673   logVarG(&n);
   1674   B = serialG(&n);
   1675   logI("len %u", lenG(B));
   1676   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1677   s = sToString((smallt *) B->B);
   1678   ck_assert_str_eq(s, "[0x46,0x24,0x44,0x70,0x06,0x01,0x02,0x03,0x04,0x05,0x06]");
   1679   free(s);
   1680   deserialG(&ds, B);
   1681   s = toStringG(&ds);
   1682   ck_assert_str_eq(s, "[1,2,null,[0x01,0x02,0x03,0x04,0x05,0x06]]");
   1683   free(s);
   1684   terminateG(B);
   1685   freeManyG(&n, &ds);
   1686 
   1687   parseG(&n, "[1,2]");
   1688   initiateG(&b);
   1689   pushG(&b, 1);
   1690   pushG(&b, 2);
   1691   pushG(&b, 3);
   1692   pushG(&b, 4);
   1693   pushG(&b, 5);
   1694   pushG(&b, 6);
   1695   pushG(&n, &b);
   1696   logVarG(&n);
   1697   B = serialG(&n);
   1698   logI("len %u", lenG(B));
   1699   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1700   s = sToString((smallt *) B->B);
   1701   ck_assert_str_eq(s, "[0x36,0x24,0x44,0x67,0x01,0x02,0x03,0x04,0x05,0x06]");
   1702   free(s);
   1703   deserialG(&ds, B);
   1704   s = toStringG(&ds);
   1705   ck_assert_str_eq(s, "[1,2,[0x01,0x02,0x03,0x04,0x05,0x06]]");
   1706   free(s);
   1707   terminateG(B);
   1708   freeManyG(&n, &ds);
   1709 
   1710 }
   1711 
   1712 
   1713 void variousT(void) {
   1714 
   1715   createNetSerial(n);
   1716   createNetSerial(ds);
   1717   char *s;
   1718   smallBytest *B;
   1719 
   1720 
   1721   // array dict int bool string
   1722   parseG(&n, "[0, \"asd\", {\"rpc\":\"ds\", \"id\":1, \"p\":true}, [true, \"user\", [[false,\"name\",1], [true, \"name2\", 12340], [false, \"zxc\", 234]]]]");
   1723   logVarG(&n);
   1724   B = serialG(&n);
   1725   logI("len %u", lenG(B));
   1726   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1727   s = sToString((smallt *) B->B);
   1728   ck_assert_str_eq(s, "[0x46,0x04,0x25,0x61,0x73,0x64,0x00,0x03,0x72,0x70,0x63,0x00,0x45,0x64,0x73,0x00,0x69,0x64,0x00,0x02,0x70,0x00,0xb1,0x36,0x51,0x75,0x73,0x65,0x72,0x00,0x6f,0x03,0x03,0x51,0x6e,0x61,0x6d,0x65,0x00,0x24,0x03,0x51,0x6e,0x61,0x6d,0x65,0x32,0x00,0x84,0x8d,0x18,0x03,0x01,0x45,0x7a,0x78,0x63,0x00,0xd4,0x03]");
   1729   free(s);
   1730   deserialG(&ds, B);
   1731   s = toStringG(&ds);
   1732   ck_assert_str_eq(s, "[0,\"asd\",{\"rpc\":\"ds\",\"id\":1,\"p\":true},[true,\"user\",[[false,\"name\",1],[true,\"name2\",12340],[false,\"zxc\",234]]]]");
   1733   free(s);
   1734   terminateG(B);
   1735   freeManyG(&n, &ds);
   1736 
   1737   parseG(&n, "[[{a:1}, null, {a:1}, {a:1}]]");
   1738   logVarG(&n);
   1739   B = serialG(&n);
   1740   logI("len %u", lenG(B));
   1741   logSI("%s",toHexSepS(getValG(B), lenG(B), " "));
   1742   s = sToString((smallt *) B->B);
   1743   ck_assert_str_eq(s, "[0x6f,0x01,0x04,0x4e,0x01,0x61,0x00,0x02,0xe0,0x14,0x61,0x00,0x02,0x4e,0x01,0x61,0x00,0x02]");
   1744   free(s);
   1745   deserialG(&ds, B);
   1746   s = toStringG(&ds);
   1747   ck_assert_str_eq(s, "[[{\"a\":1},null,{\"a\":1},{\"a\":1}]]");
   1748   free(s);
   1749   terminateG(B);
   1750   freeManyG(&n, &ds);
   1751 
   1752 }
   1753 
   1754 
   1755 int main(int n, char**v) {
   1756 
   1757 initLibsheepy(v[0]);
   1758 setLogMode(LOG_FUNC);
   1759 
   1760 topT();
   1761 uniformDictT();
   1762 uniformArrayT();
   1763 dictT();
   1764 arrayT();
   1765 variousT();
   1766 }