libsheepy

C lib for handling text files, strings and json like data structure with an object oriented system
git clone https://spartatek.se/git/libsheepy.git
Log | Files | Refs | README | LICENSE

libsheepyCSmallBytes.c (24471B)


      1 // MIT License
      2 //
      3 // Copyright (c) 2026 Remy Noulin
      4 //
      5 // Permission is hereby granted, free of charge, to any person obtaining a copy
      6 // of this software and associated documentation files (the "Software"), to deal
      7 // in the Software without restriction, including without limitation the rights
      8 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      9 // copies of the Software, and to permit persons to whom the Software is
     10 // furnished to do so, subject to the following conditions:
     11 //
     12 // The above copyright notice and this permission notice shall be included in all
     13 // copies or substantial portions of the Software.
     14 //
     15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     18 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     21 // SOFTWARE.
     22 
     23 #include "../libsheepyObject.h"
     24 #include "libsheepyCSmallBytes.h"
     25 #include "libsheepyCSmallBytesInternal.h"
     26 
     27 #define internal static
     28 
     29 #include <stdbool.h>
     30 #include <stdlib.h>
     31 #include <stdint.h>
     32 #include <string.h>
     33 #include <stdio.h>
     34 
     35 void initiateSmallBytes(smallBytest *self);
     36 void registerMethodsSmallBytes(smallBytesFunctionst *f);
     37 void initiateAllocateSmallBytes(smallBytest **self);
     38 void finalizeRecycleSmallBytes(void *arg UNUSED);
     39 void finalizeSmallBytes(void);
     40 smallBytest* allocSmallBytes(void *data, uint32_t size);
     41 void cleanUpSmallBytesTerminateG(smallBytest **val);
     42 void cleanUpSmallBytesFreeLocalG(smallBytest *val);
     43 void cleanUpSmallBytesFreeG(smallBytest **val);
     44 void cleanUpSmallBytesFinishG(smallBytest **val);
     45 internal void freeSmallBytes(smallBytest *self);
     46 internal void terminateSmallBytes(smallBytest **self);
     47 #if (NFreeStackCheck)
     48 internal void finishSmallBytes(smallBytest **self);
     49 #else
     50 internal void finishSmallBytes(smallBytest **self);
     51 #endif
     52 internal const char* helpSmallBytes(smallBytest UNUSED *self);
     53 internal char* toStringSmallBytes(smallBytest *self);
     54 internal smallBytest* duplicateSmallBytes(smallBytest *self);
     55 internal void* getSmallBytes(smallBytest *self);
     56 internal smallBytest* setSmallBytes(smallBytest *self, void *data, uint32_t size);
     57 internal smallBytest* pushSmallBytes(smallBytest *self, char data);
     58 internal smallBytest* pushBufferSmallBytes(smallBytest *self, void *data, uint32_t size);
     59 internal char getAtSmallBytes(smallBytest *self, int64_t index);
     60 internal size_t lenSmallBytes(smallBytest *self);
     61 internal bool isEmptySmallBytes(smallBytest *self);
     62 internal smallBytest* readFileSmallBytes(smallBytest *self, const char *filePath);
     63 internal smallBytest* readFileSmallJsonSmallBytes(smallBytest *self, smallJsont *filePath);
     64 internal smallBytest* readFileSmallStringSmallBytes(smallBytest *self, smallStringt *filePath);
     65 internal smallBytest* readStreamSmallBytes(smallBytest *self, FILE *fp);
     66 internal int writeFileSmallBytes(smallBytest *self, const char *filePath);
     67 internal int writeFileSmallJsonSmallBytes(smallBytest *self, smallJsont *filePath);
     68 internal int writeFileSmallStringSmallBytes(smallBytest *self, smallStringt *filePath);
     69 internal int writeStreamSmallBytes(smallBytest *self, FILE *fp);
     70 internal int appendFileSmallBytes(smallBytest *self, const char *filePath);
     71 internal int appendFileSmallStringSmallBytes(smallBytest *self, smallStringt *filePath);
     72 internal bool equalSmallBytes(smallBytest *self, smallBytest *value);
     73 internal bool equalSmallBytesBool(smallBytest *self, bool value);
     74 internal bool equalSmallBytesDouble(smallBytest *self, double value);
     75 internal bool equalSmallBytesInt64(smallBytest *self, int64_t value);
     76 internal bool equalSmallBytesInt32(smallBytest *self, int32_t value);
     77 internal bool equalSmallBytesUint32(smallBytest *self, uint32_t value);
     78 internal bool equalSmallBytesUint64(smallBytest *self, uint64_t value);
     79 internal bool equalSmallBytesSmallBool(smallBytest *self, smallBoolt *value);
     80 internal bool equalSmallBytesSmallDouble(smallBytest *self, smallDoublet *value);
     81 internal bool equalSmallBytesSmallInt(smallBytest *self, smallIntt *value);
     82 internal bool equalSmallBytesChar(smallBytest *self, const char *value);
     83 internal bool equalSmallBytesSmallString(smallBytest *self, smallStringt *value);
     84 internal bool equalSmallBytesBase(smallBytest *self, baset *value);
     85 smallBytest* duplicateSmallBytesG (smallBytest *self);
     86 smallBytest* setSmallBytesG(smallBytest *self, void *data, uint32_t size);
     87 char getAtSmallBytesG(smallBytest *self, char retType UNUSED, int64_t index);
     88 smallBytest* pushSmallBytesG (smallBytest *self, char data);
     89 size_t lenSmallBytesG(smallBytest *self);
     90 bool isEmptySmallBytesG(smallBytest *self);
     91 smallBytest* readFileSmallBytesG(smallBytest *self, const char *filePath);
     92 smallBytest* readFileSmallJsonSmallBytesG(smallBytest *self, smallJsont *filePath);
     93 smallBytest* readFileSmallStringSmallBytesG(smallBytest *self, smallStringt *filePath);
     94 smallBytest* readStreamSmallBytesG(smallBytest *self, FILE *fp);
     95 int writeFileSmallBytesG(smallBytest *self, const char *filePath);
     96 int writeFileSmallJsonSmallBytesG(smallBytest *self, smallJsont *filePath);
     97 int writeFileSmallStringSmallBytesG(smallBytest *self, smallStringt *filePath);
     98 int writeStreamSmallBytesG(smallBytest *self, FILE *fp);
     99 int appendFileSmallBytesG(smallBytest *self, const char *filePath);
    100 int appendFileSmallStringSmallBytesG(smallBytest *self, smallStringt *filePath);
    101 bool equalSmallBytesG(smallBytest *self, smallBytest *value);
    102 bool equalSmallBytesBoolG(smallBytest *self, bool value);
    103 bool equalSmallBytesDoubleG(smallBytest *self, double value);
    104 bool equalSmallBytesInt64G(smallBytest *self, int64_t value);
    105 bool equalSmallBytesInt32G(smallBytest *self, int32_t value);
    106 bool equalSmallBytesUint32G(smallBytest *self, uint32_t value);
    107 bool equalSmallBytesUint64G(smallBytest *self, uint64_t value);
    108 bool equalSmallBytesSmallBoolG(smallBytest *self, smallBoolt *value);
    109 bool equalSmallBytesSmallDoubleG(smallBytest *self, smallDoublet *value);
    110 bool equalSmallBytesSmallIntG(smallBytest *self, smallIntt *value);
    111 bool equalSmallBytesCharG(smallBytest *self, const char *value);
    112 bool equalSmallBytesSmallStringG(smallBytest *self, smallStringt *value);
    113 bool equalSmallBytesBaseG(smallBytest *self, baset *value);
    114 
    115 void initiateSmallBytes(smallBytest *self) {
    116 
    117   self->type = "smallBytes";
    118   if (!smallBytesF) {
    119     isError(smallBytesF, malloc(sizeof(smallBytesFunctionst))) {
    120       self->f = NULL;
    121       return;
    122     }
    123     registerMethodsSmallBytes(smallBytesF);
    124   }
    125   self->f = smallBytesF;
    126   self->B = NULL;
    127 }
    128 
    129 void registerMethodsSmallBytes(smallBytesFunctionst *f) {
    130 
    131   f->free                  = freeSmallBytes;
    132   f->terminate             = terminateSmallBytes;
    133   f->toString              = toStringSmallBytes;
    134   f->duplicate             = duplicateSmallBytes;
    135   f->smash                 = finishSmallBytes;
    136   f->finish                = finishSmallBytes;
    137   f->help                  = helpSmallBytes;
    138   f->get                   = getSmallBytes;
    139   f->set                   = setSmallBytes;
    140   f->push                  = pushSmallBytes;
    141   f->pushBuffer            = pushBufferSmallBytes;
    142   f->getAt                 = getAtSmallBytes;
    143   f->len                   = lenSmallBytes;
    144   f->isEmpty               = isEmptySmallBytes;
    145   f->readFile              = readFileSmallBytes;
    146   f->readFileSmallJson     = readFileSmallJsonSmallBytes;
    147   f->readFileSmallString   = readFileSmallStringSmallBytes;
    148   f->readStream            = readStreamSmallBytes;
    149   f->writeFile             = writeFileSmallBytes;
    150   f->writeFileSmallJson    = writeFileSmallJsonSmallBytes;
    151   f->writeFileSmallString  = writeFileSmallStringSmallBytes;
    152   f->writeStream           = writeStreamSmallBytes;
    153   f->appendFile            = appendFileSmallBytes;
    154   f->appendFileSmallString = appendFileSmallStringSmallBytes;
    155   f->equal                 = equalSmallBytes;
    156   f->equalBool             = equalSmallBytesBool;
    157   f->equalDouble           = equalSmallBytesDouble;
    158   f->equalInt64            = equalSmallBytesInt64;
    159   f->equalInt32            = equalSmallBytesInt32;
    160   f->equalUint32           = equalSmallBytesUint32;
    161   f->equalUint64           = equalSmallBytesUint64;
    162   f->equalSmallBool        = equalSmallBytesSmallBool;
    163   f->equalSmallDouble      = equalSmallBytesSmallDouble;
    164   f->equalSmallInt         = equalSmallBytesSmallInt;
    165   f->equalS                = equalSmallBytesChar;
    166   f->equalSmallString      = equalSmallBytesSmallString;
    167   f->equalBase             = equalSmallBytesBase;
    168 }
    169 
    170 void initiateAllocateSmallBytes(smallBytest **self) {
    171 
    172   if (self) {
    173     #if (recycleContainers)
    174     initAllocateRecycle(smallBytest);
    175     #else
    176     isError(*self, malloc(sizeof(smallBytest)))
    177       return;
    178     #endif
    179     if (*self) {
    180       initiateSmallBytes(*self);
    181       if (!(*self)->f) {
    182         finishSmallBytes(self);
    183 }
    184   }
    185     }
    186       }
    187 
    188 void finalizeRecycleSmallBytes(void *arg UNUSED) {
    189 
    190   #if (recycleContainers)
    191   finalizeRecycle
    192   #endif
    193   // recycleContainers
    194 }
    195 
    196 void finalizeSmallBytes(void) {
    197 
    198   if (smallBytesF) {
    199     free(smallBytesF);
    200     smallBytesF = NULL;
    201   }
    202   finalizeRecycleSmallBytes(NULL);
    203 }
    204 
    205 smallBytest* allocSmallBytes(void *data, uint32_t size) {
    206   smallBytest *r = NULL;
    207 
    208   initiateAllocateSmallBytes(&r);
    209   if (!r) {
    210     return(NULL);
    211   }
    212   r->f->pushBuffer(r, data, size);
    213   return(r);
    214 }
    215 
    216 void cleanUpSmallBytesTerminateG(smallBytest **val) {
    217 
    218   terminateO(*val);
    219 }
    220 
    221 void cleanUpSmallBytesFreeLocalG(smallBytest *val) {
    222 
    223   freeO(val);
    224 }
    225 
    226 void cleanUpSmallBytesFreeG(smallBytest **val) {
    227 
    228   freeO(*val);
    229 }
    230 
    231 void cleanUpSmallBytesFinishG(smallBytest **val) {
    232 
    233   finishO(*val);
    234 }
    235 
    236 
    237 
    238 internal void freeSmallBytes(smallBytest *self) {
    239 
    240   sFree((smallt *)self->B);
    241   self->B = NULL;
    242   return;
    243 }
    244 
    245 internal void terminateSmallBytes(smallBytest **self) {
    246 
    247   freeSmallBytes(*self);
    248   finishSmallBytes(self);
    249 }
    250 
    251 #if (NFreeStackCheck)
    252 internal void finishSmallBytes(smallBytest **self) {
    253 
    254   register u64 rsp asm("rsp");
    255   if ((u64)*self > rsp) {
    256     logW("Probably trying to free a smallBytes on stack: "BLD PRIx64 RST" sp: "BLD PRIx64 RST, *self, rsp);
    257     logBtrace;
    258   }
    259   else {
    260     #if (recycleContainers)
    261     finishRecycle
    262     #else
    263     free(*self);
    264     #endif
    265     // recycleContainers
    266     *self = NULL;
    267 }
    268   }
    269 
    270 #else
    271 // #if NFreeStackCheck
    272 internal void finishSmallBytes(smallBytest **self) {
    273 
    274   #if (recycleContainers)
    275   finishRecycle
    276   #else
    277   free(*self);
    278   #endif
    279   // recycleContainers
    280   *self = NULL;
    281 }
    282 
    283 #endif
    284 // #if NFreeStackCheck
    285 
    286 internal const char* helpSmallBytes(smallBytest UNUSED *self) {
    287 
    288   return(helpTextSmallBytes);
    289 }
    290 
    291 
    292 internal char* toStringSmallBytes(smallBytest *self) {
    293 
    294   if (!self->B) {
    295     return(strdup("[]"));
    296   }
    297 
    298   return(sToString((smallt *)self->B));
    299 }
    300 
    301 internal smallBytest* duplicateSmallBytes(smallBytest *self) {
    302 
    303   createAllocateSmallBytes(dup);
    304   if (!dup) {
    305     return(NULL);
    306   }
    307   dup->B = (sBytest *)sDuplicate((smallt *)self->B);;
    308   return(dup);
    309 }
    310 
    311 internal void* getSmallBytes(smallBytest *self) {
    312 
    313   return(sBytesGet(self->B));
    314 }
    315 
    316 internal smallBytest* setSmallBytes(smallBytest *self, void *data, uint32_t size) {
    317 
    318   freeSmallBytes(self);
    319   sBytesPushBuffer(&(self->B), data, size);
    320   return(self);
    321 }
    322 
    323 internal smallBytest* pushSmallBytes(smallBytest *self, char data) {
    324 
    325   sBytesPush(&(self->B), data);
    326   return(self);
    327 }
    328 
    329 internal smallBytest* pushBufferSmallBytes(smallBytest *self, void *data, uint32_t size) {
    330 
    331   sBytesPushBuffer(&(self->B), data, size);
    332   return(self);
    333 }
    334 
    335 internal char getAtSmallBytes(smallBytest *self, int64_t index) {
    336 
    337   if (!self->B) {
    338     return(0);
    339   }
    340 
    341   if (index >= self->B->count) {
    342     return(0);
    343   }
    344   if (index < -(int64_t)self->B->count) {
    345     return(0);
    346   }
    347   if (index < 0) {
    348     index = (int64_t)self->B->count + index;
    349   }
    350 
    351   return((&(self->B->data))[index]);
    352 }
    353 
    354 internal size_t lenSmallBytes(smallBytest *self) {
    355 
    356   if (!self->B) {
    357     return(0);
    358   }
    359 
    360   return(self->B->count);
    361 }
    362 
    363 internal bool isEmptySmallBytes(smallBytest *self) {
    364 
    365   return(!lenSmallBytes(self));
    366 }
    367 
    368 internal smallBytest* readFileSmallBytes(smallBytest *self, const char *filePath) {
    369   FILE *f = NULL;
    370   ssize_t len;
    371   size_t readStatus;
    372 
    373   // sanity checks
    374   if (!filePath || isBlankS(filePath)) {
    375     return(NULL);
    376   }
    377 
    378   len = fileSize(filePath);;
    379   // TODO check that len is less than 4GB because sBytes can hold 4GB at most
    380   if (len == -1) {
    381     return(NULL);
    382   }
    383 
    384   freeSmallBytes(self);
    385 
    386   void *buffer = malloc((size_t)len);
    387   if (!buffer) {
    388     return(NULL);
    389   }
    390 
    391   f = fopen(filePath, "r");
    392   readStatus = fread(buffer, 1, (size_t)len , f);
    393   fclose(f);
    394 
    395   // readStatus == len when ok
    396   pushBufferSmallBytes(self, buffer, (uint32_t)readStatus);
    397 
    398   // pushBuffer copies the buffer, buffer is not used anymore, free it
    399   free(buffer);
    400 
    401   if (readStatus != (size_t)len) {
    402     pFuncError
    403     shEPrintfS("The path was: \"%s\"\n", filePath);
    404     return(NULL);
    405   }
    406 
    407   return(self);
    408 }
    409 
    410 internal smallBytest* readFileSmallJsonSmallBytes(smallBytest *self, smallJsont *filePath) {
    411 
    412   if (!filePath) {
    413     return(NULL);
    414   }
    415 
    416   if (checkObjectTypes && !isOSmallJson(filePath)) {
    417     return(NULL);
    418   }
    419 
    420   const char *type = getTopTypeO(filePath);
    421 
    422   if (!eqS(type,"string")) {
    423     return(NULL);
    424   }
    425 
    426   return(readFileSmallBytes(self, getTopSO(filePath)));
    427 }
    428 
    429 internal smallBytest* readFileSmallStringSmallBytes(smallBytest *self, smallStringt *filePath) {
    430 
    431   if (!filePath) {
    432     return(NULL);
    433   }
    434 
    435   if (checkObjectTypes && !isOSmallString(filePath)) {
    436     return(NULL);
    437   }
    438 
    439   return(readFileSmallBytes(self, ssGet(filePath)));
    440 }
    441 
    442 internal smallBytest* readStreamSmallBytes(smallBytest *self, FILE *fp) {
    443   ssize_t len;
    444   size_t readStatus;
    445 
    446   // sanity checks
    447   if (!fp) {
    448     return(NULL);
    449   }
    450 
    451   len = fileSizeFP(fp);
    452   // TODO check that len is less than 4GB because sBytes can hold 4GB at most
    453   if (len == -1) {
    454     return(NULL);
    455   }
    456 
    457   freeSmallBytes(self);
    458 
    459   void *buffer = malloc((size_t)len);
    460   if (!buffer) {
    461     return(NULL);
    462   }
    463 
    464   readStatus = fread(buffer, 1, (size_t)len , fp);
    465 
    466   // readStatus == len when ok
    467   pushBufferSmallBytes(self, buffer, (uint32_t)readStatus);
    468 
    469   // pushBuffer copies the buffer, buffer is not used anymore, free it
    470   free(buffer);
    471 
    472   if (readStatus != (size_t)len) {
    473     pFuncError
    474     return(NULL);
    475   }
    476 
    477   return(self);
    478 }
    479 
    480 internal int writeFileSmallBytes(smallBytest *self, const char *filePath) {
    481   FILE *f = NULL;
    482   size_t len;
    483   size_t writeStatus;
    484 
    485   // sanity checks
    486   if (!filePath || isBlankS(filePath) || !self->B) {
    487     return(0);
    488   }
    489 
    490   len = self->B->count;
    491 
    492   f = fopen(filePath, "w");
    493   if (!f) {
    494     pFuncError
    495     shEPrintfS("The path was: \"%s\"\n", filePath);
    496     return(0);
    497   }
    498   writeStatus = fwrite(sBytesGet(self->B), 1, len , f);
    499   fclose(f);
    500 
    501   if (writeStatus != len) {
    502     pFuncError
    503     shEPrintfS("The path was: \"%s\"\n", filePath);
    504     return(0);
    505   }
    506 
    507   return(1);
    508 }
    509 
    510 internal int writeFileSmallJsonSmallBytes(smallBytest *self, smallJsont *filePath) {
    511 
    512   if (!filePath) {
    513     return(0);
    514   }
    515 
    516   if (checkObjectTypes && !isOSmallJson(filePath)) {
    517     return(0);
    518   }
    519 
    520   const char *type = getTopTypeO(filePath);
    521 
    522   if (!eqS(type,"string")) {
    523     return(0);
    524   }
    525 
    526   return(writeFileSmallBytes(self, getTopSO(filePath)));
    527 }
    528 
    529 internal int writeFileSmallStringSmallBytes(smallBytest *self, smallStringt *filePath) {
    530 
    531   if (!filePath) {
    532     return(0);
    533   }
    534 
    535   if (checkObjectTypes && !isOSmallString(filePath)) {
    536     return(0);
    537   }
    538 
    539   return(writeFileSmallBytes(self, ssGet(filePath)));
    540 }
    541 
    542 internal int writeStreamSmallBytes(smallBytest *self, FILE *fp) {
    543   size_t len;
    544   size_t writeStatus;
    545 
    546   // sanity checks
    547   if (!fp || !self->B) {
    548     return(0);
    549   }
    550 
    551   len = self->B->count;
    552 
    553   writeStatus = fwrite(sBytesGet(self->B), 1, len , fp);
    554 
    555   if (writeStatus != len) {
    556     pFuncError
    557     return(0);
    558   }
    559 
    560   return(1);
    561 }
    562 
    563 internal int appendFileSmallBytes(smallBytest *self, const char *filePath) {
    564   FILE *f = NULL;
    565   size_t len;
    566   size_t writeStatus;
    567 
    568   // sanity checks
    569   if (!filePath || isBlankS(filePath) || !self->B) {
    570     return(0);
    571   }
    572 
    573   len = self->B->count;
    574 
    575   f = fopen(filePath, "a");
    576   if (!f) {
    577     pFuncError
    578     shEPrintfS("The path was: \"%s\"\n", filePath);
    579     return(0);
    580   }
    581   writeStatus = fwrite(sBytesGet(self->B), 1, len , f);
    582   fclose(f);
    583 
    584   if (writeStatus != len) {
    585     pFuncError
    586     shEPrintfS("The path was: \"%s\"\n", filePath);
    587     return(0);
    588   }
    589 
    590   return(1);
    591 }
    592 
    593 internal int appendFileSmallStringSmallBytes(smallBytest *self, smallStringt *filePath) {
    594 
    595   if (!filePath) {
    596     return(0);
    597   }
    598   return(appendFileSmallBytes(self, ssGet(filePath)));
    599 }
    600 
    601 internal bool equalSmallBytes(smallBytest *self, smallBytest *value) {
    602 
    603   if (!self->B || !value || !value->B) {
    604     return(false);
    605   }
    606 
    607   if (self->B->count != value->B->count) {
    608     return(false);
    609   }
    610 
    611   return(memcmp(sBytesGet(self->B),sBytesGet(value->B), self->B->count) == 0);;
    612 }
    613 
    614 internal bool equalSmallBytesBool(smallBytest *self, bool value) {
    615 
    616   if (!self->B) {
    617     return(false);
    618   }
    619 
    620   if (equalSmallBytesChar(self, "true") || equalSmallBytesChar(self, "TRUE")) {
    621     return(value);
    622   }
    623   else if (equalSmallBytesChar(self, "false") || equalSmallBytesChar(self, "FALSE")) {
    624     return(!value);
    625   }
    626   return(false);
    627 }
    628 
    629 internal bool equalSmallBytesDouble(smallBytest *self, double value) {
    630 
    631   if (!self->B) {
    632     return(false);
    633   }
    634 
    635   char *s = sBytesGet(self->B);
    636 
    637   bool has0 = false;
    638   rangeDown(i, self->B->count) {
    639     if (s[i] == 0) {
    640       has0 = true;
    641       break;
    642     }
    643   }
    644 
    645   if (!has0) {
    646     return(false);
    647   }
    648 
    649   if (isInt(s) || !isNumber(s)) {
    650     return(false);
    651   }
    652 
    653   double val = parseDouble(s);
    654 
    655   return(val == value);;
    656 }
    657 
    658 internal bool equalSmallBytesInt64(smallBytest *self, int64_t value) {
    659 
    660   if (!self->B) {
    661     return(false);
    662   }
    663 
    664   char *s = sBytesGet(self->B);
    665 
    666   bool has0 = false;
    667   rangeDown(i, self->B->count) {
    668     if (s[i] == 0) {
    669       has0 = true;
    670       break;
    671     }
    672   }
    673 
    674   if (!has0) {
    675     return(false);
    676   }
    677 
    678   if (!isInt(s)) {
    679     return(false);
    680   }
    681 
    682   int64_t val = parseInt(s);
    683 
    684   return(val == value);;
    685 }
    686 
    687 internal bool equalSmallBytesInt32(smallBytest *self, int32_t value) {
    688 
    689   if (!self->B) {
    690     return(false);
    691   }
    692 
    693   char *s = sBytesGet(self->B);
    694 
    695   bool has0 = false;
    696   rangeDown(i, self->B->count) {
    697     if (s[i] == 0) {
    698       has0 = true;
    699       break;
    700     }
    701   }
    702 
    703   if (!has0) {
    704     return(false);
    705   }
    706 
    707   if (!isInt(s)) {
    708     return(false);
    709   }
    710 
    711   int32_t val = (int32_t)parseInt(s);
    712 
    713   return(val == value);;
    714 }
    715 
    716 internal bool equalSmallBytesUint32(smallBytest *self, uint32_t value) {
    717 
    718   if (!self->B) {
    719     return(false);
    720   }
    721 
    722   char *s = sBytesGet(self->B);
    723 
    724   bool has0 = false;
    725   rangeDown(i, self->B->count) {
    726     if (s[i] == 0) {
    727       has0 = true;
    728       break;
    729     }
    730   }
    731 
    732   if (!has0) {
    733     return(false);
    734   }
    735 
    736   if (!isInt(s)) {
    737     return(false);
    738   }
    739 
    740   uint32_t val = (uint32_t)parseInt(s);
    741 
    742   return(val == value);;
    743 }
    744 
    745 internal bool equalSmallBytesUint64(smallBytest *self, uint64_t value) {
    746 
    747   if (!self->B) {
    748     return(false);
    749   }
    750 
    751   char *s = sBytesGet(self->B);
    752 
    753   bool has0 = false;
    754   rangeDown(i, self->B->count) {
    755     if (s[i] == 0) {
    756       has0 = true;
    757       break;
    758     }
    759   }
    760 
    761   if (!has0) {
    762     return(false);
    763   }
    764 
    765   if (!isInt(s)) {
    766     return(false);
    767   }
    768 
    769   uint64_t val = (uint64_t)parseInt(s);
    770 
    771   return(val == value);;
    772 }
    773 
    774 internal bool equalSmallBytesSmallBool(smallBytest *self, smallBoolt *value) {
    775 
    776   if (!self->B || !value || !value->value) {
    777     return(false);
    778   }
    779 
    780   return(equalSmallBytesBool(self, value->value->value));
    781 }
    782 
    783 internal bool equalSmallBytesSmallDouble(smallBytest *self, smallDoublet *value) {
    784 
    785   if (!self->B || !value || !value->value) {
    786     return(false);
    787   }
    788 
    789   return(equalSmallBytesDouble(self, value->value->value));
    790 }
    791 
    792 internal bool equalSmallBytesSmallInt(smallBytest *self, smallIntt *value) {
    793 
    794   if (!self->B || !value || !value->value) {
    795     return(false);
    796   }
    797 
    798   return(equalSmallBytesInt64(self, value->value->value));
    799 }
    800 
    801 
    802 internal bool equalSmallBytesChar(smallBytest *self, const char *value) {
    803 
    804   if (!self->B || !value) {
    805     return(false);
    806   }
    807 
    808   size_t size = strlen(value) + 1;
    809   if (self->B->count != size) {
    810     return(false);
    811   }
    812 
    813   return(memcmp(sBytesGet(self->B), value, size) == 0);;
    814 }
    815 
    816 internal bool equalSmallBytesSmallString(smallBytest *self, smallStringt *value) {
    817 
    818   if (!self->B || !value || !value->data) {
    819     return(false);
    820   }
    821 
    822   if (self->B->count != (value->_len + 1)) {
    823     return(false);
    824   }
    825 
    826   return(memcmp(sBytesGet(self->B), sStringGetTiny(value->data), self->B->count) == 0);;
    827 }
    828 
    829 internal bool equalSmallBytesBase(smallBytest *self, baset *value) {
    830 
    831   if (!self->B || !value) {
    832     return(false);
    833   }
    834 
    835   if (isOSmallBytes(value)) {
    836     return(equalSmallBytes(self, (smallBytest*)value));
    837   }
    838   else if (isOSmallString(value)) {
    839     return(equalSmallBytesSmallString(self, (smallStringt*)value));
    840   }
    841   else {
    842     return(false);
    843 }
    844   }
    845 
    846 smallBytest* duplicateSmallBytesG (smallBytest *self) {
    847 
    848   return(self->f->duplicate(self));
    849 }
    850 
    851 void freeSmallBytesG (smallBytest *self) {self->f->free(self);}
    852 
    853 smallBytest* setSmallBytesG(smallBytest *self, void *data, uint32_t size) {
    854 
    855   return(self->f->set(self, data, size));
    856 }
    857 
    858 char getAtSmallBytesG(smallBytest *self, char retType UNUSED, int64_t index) {
    859 
    860   return(self->f->getAt(self,index));
    861 }
    862 
    863 smallBytest* pushSmallBytesG (smallBytest *self, char data) {
    864 
    865   return(self->f->push(self, data));
    866 }
    867 
    868 size_t lenSmallBytesG(smallBytest *self) {
    869 
    870   return(self->f->len(self));
    871 }
    872 
    873 bool isEmptySmallBytesG(smallBytest *self) {
    874 
    875   return(self->f->isEmpty(self));
    876 }
    877 
    878 smallBytest* readFileSmallBytesG(smallBytest *self, const char *filePath) {
    879 
    880   return(self->f->readFile(self, filePath));
    881 }
    882 
    883 smallBytest* readFileSmallJsonSmallBytesG(smallBytest *self, smallJsont *filePath) {
    884 
    885   return(self->f->readFileSmallJson(self,filePath));
    886 }
    887 
    888 smallBytest* readFileSmallStringSmallBytesG(smallBytest *self, smallStringt *filePath) {
    889 
    890   return(self->f->readFileSmallString(self,filePath));
    891 }
    892 
    893 smallBytest* readStreamSmallBytesG(smallBytest *self, FILE *fp) {
    894 
    895   return(self->f->readStream(self, fp));
    896 }
    897 
    898 
    899 int writeFileSmallBytesG(smallBytest *self, const char *filePath) {
    900 
    901   return(self->f->writeFile(self, filePath));
    902 }
    903 
    904 int writeFileSmallJsonSmallBytesG(smallBytest *self, smallJsont *filePath) {
    905 
    906   return(self->f->writeFileSmallJson(self, filePath));
    907 }
    908 
    909 int writeFileSmallStringSmallBytesG(smallBytest *self, smallStringt *filePath) {
    910 
    911   return(self->f->writeFileSmallString(self, filePath));
    912 }
    913 
    914 int writeStreamSmallBytesG(smallBytest *self, FILE *fp) {
    915 
    916   return(self->f->writeStream(self, fp));
    917 }
    918 
    919 int appendFileSmallBytesG(smallBytest *self, const char *filePath) {
    920 
    921   return(self->f->appendFile(self, filePath));
    922 }
    923 
    924 int appendFileSmallStringSmallBytesG(smallBytest *self, smallStringt *filePath) {
    925 
    926   return(self->f->appendFileSmallString(self, filePath));
    927 }
    928 
    929 bool equalSmallBytesG(smallBytest *self, smallBytest *value) {
    930 
    931   return(self->f->equal(self, value));
    932 }
    933 
    934 bool equalSmallBytesBoolG(smallBytest *self, bool value) {
    935 
    936   return(self->f->equalBool(self, value));
    937 }
    938 
    939 bool equalSmallBytesDoubleG(smallBytest *self, double value) {
    940 
    941   return(self->f->equalDouble(self, value));
    942 }
    943 
    944 bool equalSmallBytesInt64G(smallBytest *self, int64_t value) {
    945 
    946   return(self->f->equalInt64(self, value));
    947 }
    948 
    949 bool equalSmallBytesInt32G(smallBytest *self, int32_t value) {
    950 
    951   return(self->f->equalInt32(self, value));
    952 }
    953 
    954 bool equalSmallBytesUint32G(smallBytest *self, uint32_t value) {
    955 
    956   return(self->f->equalUint32(self, value));
    957 }
    958 
    959 bool equalSmallBytesUint64G(smallBytest *self, uint64_t value) {
    960 
    961   return(self->f->equalUint64(self, value));
    962 }
    963 
    964 bool equalSmallBytesSmallBoolG(smallBytest *self, smallBoolt *value) {
    965 
    966   return(self->f->equalSmallBool(self, value));
    967 }
    968 
    969 bool equalSmallBytesSmallDoubleG(smallBytest *self, smallDoublet *value) {
    970 
    971   return(self->f->equalSmallDouble(self, value));
    972 }
    973 
    974 bool equalSmallBytesSmallIntG(smallBytest *self, smallIntt *value) {
    975 
    976   return(self->f->equalSmallInt(self, value));
    977 }
    978 
    979 bool equalSmallBytesCharG(smallBytest *self, const char *value) {
    980 
    981   return(self->f->equalS(self, value));
    982 }
    983 
    984 bool equalSmallBytesSmallStringG(smallBytest *self, smallStringt *value) {
    985 
    986   return(self->f->equalSmallString(self, value));
    987 }
    988 
    989 bool equalSmallBytesBaseG(smallBytest *self, baset *value) {
    990 
    991   return(self->f->equalBase(self, value));
    992 }
    993