💾 Archived View for gmi.noulin.net › gitRepositories › netSerial › file › netSerial.h.gmi captured on 2024-07-09 at 02:35:44. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2023-01-29)
-=-=-=-=-=-=-
netSerial.h (5245B)
1 #pragma once 2 3 /** \file 4 * TODO 5 * create a not trusted version of deserializer that check the data and stop when there is an error 6 * 7 * the netSerial class inherits from the smallJson class 8 * the generics for smallJson can be used with netSerial objects 9 * 10 * serializer level 3 (default) interface: 11 * createNetSerial 12 * initiateNetSerial 13 * initiateAllocateNetSerial 14 * finalizeNetSerial 15 * allocNetSerial 16 * serialG 17 * deserialG 18 * 19 * serializer level 3 (default) description: 20 * 21 * data 22 * 4 bits type 23 * 0 undefined 24 * 1 bool 25 * 2 dict 26 * 3 double 27 * 4 varint 28 * 5 string 29 * 6 array 30 * 7 bytes = faststring 31 * 8 packed dict 32 * 9 packed double 33 * 10 A packed varint 34 * 11 B packed string 35 * 12 C packed array 36 * 13 D packed bytes = faststring 37 * 14 E dict - all elements have same type 38 * 15 F array - all elements have same type 39 * 40 * undefined takes 4 bits (type 0) 41 * bool takes 5 bites and is packed in groups of 4 or 8 42 * dict is normal or uniform 43 * double takes 8.5 bytes 44 * varint: b7=0 last bytes, b7=1 next byte belongs to this varint 45 * string takes 4 bits + string size including nul terminator 46 * array is normal or uniform 47 * bytes takes 4 bits + data for count + sBytes size 48 * 49 * normal array/dict are array/dict having any type of data, each element has a 4 bit type 50 * when 4 or more element have the identical types among dict,double,int,string,array and bytes, they are packed, the element types are not recorded 51 * array/dict are always normal array/dict when packed 52 * 53 * uniform array/dict are array/dict having only one type of data, type is not recorded for the elements 54 * undefined elements dont take space in uniform array/dict 55 * bools are stored in single bits in uniform array/dict 56 * 57 * 58 * > undefined if in b0..3 then next type is b4..7, if in b4..7 then no information about next byte 59 * > bool if in b0..3 then b4 is value, b5..7 is the value for next 3 bools, if in b4..7 then next byte is bool value for next 8 bools 60 * > dict if in b0..3 then b4..7 is varint of length (0 to 7), if in b4..7 then next byte is length varint, if b0..2 are 1 then all elements have the same type and next byte is type for all elements 61 * > double if in b0..3 next 8 bytes is double and b4..7 is type for next element 62 * > varint (n << 1) ^ (n >>(arithmetic shift) 63) sign bit at bit 0, if in b0..3 then b4..7 is varint start, if in b4..7 then next byte is first varint byte 63 * > string next bytes are NUL terminated string 64 * > array if in b0..3 then b4..7 is varint of length (0 to 7), if in b4..7 then next byte is length varint, if b0..2 are 1 then all elements have the same type and next byte is type for all elements 65 * > bytes if in b0..3 then b4..7 is varint of length (0 to 7) and next bytes are string, if in b4..7 then next byte is length varint 66 * > packed double if in b0..3 then b4..7 is varint of element count (0 to 7) and next groups of 8 bytes are doubles 67 * > packed varint if in b0..3 then b4..7 is varint of element count (0 to 7) and next bytes are varints 68 * > uniform dict if in b0..3 then b4..7 is element type, next byte is element count 69 * > unfiform array if in b0..3 then b4..7 is element type, next byte is element count 70 */ 71 72 73 /* netSerial */ 74 75 #define createNetSerialLevel0(obj) ;smallJsont obj; initiateNetSerialLevel0(&obj) 76 #define createNetSerialLevel1(obj) ;smallJsont obj; initiateNetSerialLevel1(&obj) 77 #define createNetSerialLevel2(obj) ;smallJsont obj; initiateNetSerialLevel2(&obj) 78 #define createNetSerial(obj) ;smallJsont obj; initiateNetSerial(&obj) 79 #define createAllocateNetSerialLevel0(obj) ;smallJsont *obj; initiateAllocateNetSerialLevel0(&obj) 80 #define createAllocateNetSerialLevel1(obj) ;smallJsont *obj; initiateAllocateNetSerialLevel1(&obj) 81 #define createAllocateNetSerialLevel2(obj) ;smallJsont *obj; initiateAllocateNetSerialLevel2(&obj) 82 #define createAllocateNetSerial(obj) ;smallJsont *obj; initiateAllocateNetSerial(&obj) 83 84 void initiateNetSerialLevel0(smallJsont *self); 85 void initiateNetSerialLevel1(smallJsont *self); 86 void initiateNetSerialLevel2(smallJsont *self); 87 void initiateNetSerial(smallJsont *self); 88 void initiateAllocateNetSerialLevel0(smallJsont **self); 89 void initiateAllocateNetSerialLevel1(smallJsont **self); 90 void initiateAllocateNetSerialLevel2(smallJsont **self); 91 void initiateAllocateNetSerial(smallJsont **self); 92 void finalizeNetSerial(void); 93 94 /* initialize class methods, call registerMethodsNetSerial from classes inheriting this class */ 95 void registerMethodsNetSerialLevel0(smallJsonFunctionst *f); 96 void registerMethodsNetSerialLevel1(smallJsonFunctionst *f); 97 void registerMethodsNetSerialLevel2(smallJsonFunctionst *f); 98 void registerMethodsNetSerial(smallJsonFunctionst *f); 99 100 smallJsont* allocNetSerialLevel0(void); 101 smallJsont* allocNetSerialLevel1(void); 102 smallJsont* allocNetSerialLevel2(void); 103 smallJsont* allocNetSerial(void); 104 105 /* end class netSerial*/ 106 107 #define isNetSerialCompiledWithCurrentLisheepyVersion checkLibsheepyVersionNetSerial(LIBSHEEPY_VERSION) 108 bool checkLibsheepyVersionNetSerial(const char *currentLibsheepyVersion); 109 110 // vim: set expandtab ts=2 sw=2: