💾 Archived View for gmi.noulin.net › gitRepositories › netSerial › file › netSerialInternal.h.gmi captured on 2023-01-29 at 11:26:35. Gemini links have been rewritten to link to archived content

View Raw

More Information

-=-=-=-=-=-=-

netSerial

Log

Files

Refs

README

LICENSE

netSerialInternal.h (1448B)

     1 #pragma once
     2 
     3 static smallJsonFunctionst *netSerialF = NULL;
     4 
     5 /** 4 bits - 16 types in the serialized bitstream */
     6 enum {S_UNDEFINED, S_BOOL, S_DICT, S_DOUBLE, S_INT, S_STRING, S_ARRAY, S_BYTES, PK_DICT, PK_DOUBLE, PK_INT, PK_STRING, PK_ARRAY, PK_BYTES, UNIFORM_DICT, UNIFORM_ARRAY};
     7 
     8 typ enum {NOPACKING, PACK, UNIFORM} packingT;
     9 
    10 /**
    11  * libsheepy object types to netSerial types
    12  */
    13 static const u8 NET_SERIAL_TYPES[] = {
    14   0,  // "not a sheepy object",
    15   0,  // "undefined",
    16   1,  // "bool",
    17   0,  // "container",
    18   2,  // "dict",
    19   0,  // "element",
    20   3,  // "double",
    21   4,  // "int",
    22   5,  // "string",
    23   7,  // "faststring",
    24   6,  // "array",
    25   7   // "bytes"
    26 };
    27 
    28 /**
    29  * object types to packed netSerial type
    30  */
    31 static const u8 PACKED_NET_SERIAL_TYPES[] = {
    32   0,  // "not a sheepy object",
    33   0,  // "undefined",
    34   0,  // "bool",
    35   0,  // "container",
    36   8,  // "dict",
    37   0,  // "element",
    38   9,  // "double",
    39   10, // "int",
    40   11, // "string",
    41   13, // "faststring",
    42   12, // "array",
    43   13  // "bytes"
    44 };
    45 
    46 /** where is next nibble in current bytes: high or low */
    47 enum {lowNbl, highNbl};
    48 
    49 /** de/serializer context to keep track of which nibble to use and where are the bits for the bools */
    50 typ struct {
    51   // store next type in low or high nibble
    52   u8 nibble;
    53   size_t nblOffset;
    54   u8 boolShift;
    55   size_t boolOffset;
    56   // debug - u8 *dbuf; // deserial buffer start
    57   u8 *nblAddr;
    58   u8 *boolAddr;
    59 } contextt;
    60 
    61 // vim: set expandtab ts=2 sw=2: