💾 Archived View for gmi.noulin.net › gitRepositories › netSerial › file › test.c.gmi captured on 2023-07-10 at 15:40:22. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
test.c (2128B)
1 #! /usr/bin/env sheepy 2 /* or direct path to sheepy: #! /usr/local/bin/sheepy */ 3 4 /* Libsheepy documentation: http://spartatek.se/libsheepy/ */ 5 #include "libsheepyObject.h" 6 #include "netSerial.h" 7 8 int argc; char **argv; 9 10 /* enable/disable logging */ 11 /* #undef pLog */ 12 /* #define pLog(...) */ 13 14 #define lv logVarG 15 16 int main(int ARGC, char** ARGV) { 17 18 argc = ARGC; argv = ARGV; 19 20 initLibsheepy(ARGV[0]); 21 setLogMode(LOG_FUNC); 22 23 createNetSerial(n); 24 createNetSerial(ds); 25 createSmallJson(j); 26 char *s; 27 28 goto bytes; 29 puts(helpO(&n)); 30 31 // empty > null 32 var r = serialG(&n); 33 lv(r); 34 35 void show(void) { 36 logI("------------------------"); 37 s = toStringG(&n); 38 lv(strlen(s)); 39 free(s); 40 lv(&n); 41 stopwatchStart; 42 r = serialG(&n); 43 stopwatchLog; 44 logI("len %u", lenG(r)); 45 logSI(BLD"netSerial"RST" %s",toHexSepS(getValG(r), lenG(r), " ")); 46 deserialG(&ds, r); 47 lv(&ds) 48 terminateG(r);freeG(&ds); 49 setsoG(&j, getsoG(&n)); 50 stopwatchStart; 51 r = serialG(&j); 52 stopwatchLog; 53 logI("smallJson len %u", lenG(r)); 54 logSI(BLD"smallJson"RST" %s",toHexSepS(getValG(r), lenG(r), " ")); 55 terminateG(r);freeG(&n); 56 } 57 58 // bool 59 setTopG(&n, TRUE); 60 show(); 61 62 // dict 63 parseG(&n, "{\"sdf\":true, \"0\":null, \"1\":null, \"2\":true, \"3\":true}"); 64 show(); 65 66 // array 67 pushG(&n, "qwe"); 68 show(); 69 70 /* // bytes */ 71 /* createSmallBytes(B); */ 72 /* freeG(&B); */ 73 74 // simple message 75 setTopG(&n, 150); 76 show(); 77 78 setTopG(&n, "testing"); 79 show(); 80 81 parseG(&n, "[150]"); 82 show(); 83 84 parseG(&n, "[3,270,-86942]"); 85 show(); 86 87 parseG(&n, "[null,null,null]"); 88 show(); 89 90 parseG(&n, "{\"a\":[3,270,-86942]}"); 91 show(); 92 93 parseG(&n, "[{\"dict\":\"hello \\\"wef\\\" qewe\",\"array\":[1,1],\"float\":3.434000e+01,\"asd\":true},\"asd \\\"qwe\\\"qwe\",234]"); 94 show(); 95 96 bytes: 97 createSmallBytes(b); 98 pushG(&b,'A'); 99 pushG(&b,'B'); 100 pushG(&b,'C'); 101 createSmallArray(a); 102 pushG(&a, &b); 103 delElemG(&a, 0); 104 /* createSmallDict(a); */ 105 /* setG(&a, "a", &b); */ 106 /* delElemG(&a, "a"); */ 107 setTopG(&n, &a); 108 show(); 109 } 110 // vim: set expandtab ts=2 sw=2: