commit d891bff6fc039f15c701e27f3a389ba25eec7b20
parent 82ed9e083e931af3004c10f24da26a873ed41e33
Author: Remy Noulin <loader2x@gmail.com>
Date: Sun, 30 Aug 2020 12:24:43 +0200
add set function in smallBytes class
release/json/libsheepyCSmallBytes.h | 34 +++++++++++++++++++++++-----------
release/libsheepy.h | 2 +-
src/json/libsheepyCSmallBytes.c | 9 +++++++++
src/json/libsheepyCSmallBytes.h | 34 +++++++++++++++++++++++-----------
src/libsheepy.h | 2 +-
5 files changed, 57 insertions(+), 24 deletions(-)
Diffstat:
5 files changed, 57 insertions(+), 24 deletions(-)
diff --git a/release/json/libsheepyCSmallBytes.h b/release/json/libsheepyCSmallBytes.h
@@ -37,19 +37,31 @@ typedef struct smallBytes smallBytest;
typedef void (*freeSmallBytesFt) (smallBytest *self);
typedef void (*terminateSmallBytesFt) (smallBytest **self);
typedef char* (*toStringSmallBytesFt) (smallBytest *self);
-typedef smallBytest* (*duplicateSmallBytesFt) (smallBytest *self);
+typedef smallBytest* (*duplicateSmallBytesFt) (smallBytest *self);
/**
* free container
*/
-typedef void (*finishSmallBytesFt)(smallBytest **self);
+typedef void (*finishSmallBytesFt)(smallBytest **self);
-typedef const char* (*helpSmallBytesFt) (smallBytest *self);
+typedef const char* (*helpSmallBytesFt) (smallBytest *self);
/**
* get buffer in object
*/
-typedef void* (*getSmallBytesFt) (smallBytest *self);
+typedef void* (*getSmallBytesFt) (smallBytest *self);
+
+/**
+ * set data buffer in object
+ *
+ * after this call, the smallBytes object will have only data
+ *
+ * \param
+ * self small bytes
+ * data buffer to push
+ * size size of buffer
+ */
+typedef smallBytest* (*setSmallBytesFt) (smallBytest *self, void *data, uint32_t size);
/**
* push char to object
@@ -57,17 +69,17 @@ typedef void* (*getSmallBytesFt) (smallBytest *self);
* \param
* data char to push
*/
-typedef smallBytest* (*pushSmallBytesFt) (smallBytest *self, char data);
+typedef smallBytest* (*pushSmallBytesFt) (smallBytest *self, char data);
/**
* push data buffer to object
*
* \param
- * bytes small bytes
+ * self small bytes
* data buffer to push
* size size of buffer
*/
-typedef smallBytest* (*pushBufferSmallBytesFt) (smallBytest *self, void *data, uint32_t size);
+typedef smallBytest* (*pushBufferSmallBytesFt) (smallBytest *self, void *data, uint32_t size);
/**
* get char at index
@@ -77,7 +89,7 @@ typedef smallBytest* (*pushBufferSmallBytesFt) (smallBytest *self, void *data, u
* \return
* char at index
*/
-typedef char (*getAtSmallBytesFt) (smallBytest *self, uint32_t index);
+typedef char (*getAtSmallBytesFt) (smallBytest *self, uint32_t index);
/**
* return buffer size in bytes
@@ -86,14 +98,14 @@ typedef char (*getAtSmallBytesFt) (smallBytest *self, uint32_t index);
* size in bytes
* 0 when smallBytes is NULL
*/
-typedef size_t (*lenSmallBytesFt) (smallBytest *self);
+typedef size_t (*lenSmallBytesFt) (smallBytest *self);
/**
* \return
* true when self is empty (len=0)
* false when len > 0
*/
-typedef bool (*isEmptySmallBytesFt)(smallBytest *self);
+typedef bool (*isEmptySmallBytesFt)(smallBytest *self);
/**
* read file to self
@@ -180,7 +192,7 @@ typedef bool (*equalSmallBytesBaseFt)(smallBytest *self, baset *value);
#define SMALLBYTESFUNCTIONST \
helpSmallBytesFt help;\
getSmallBytesFt get;\
- /*set-*/\
+ setSmallBytesFt set;\
pushSmallBytesFt push;\
pushBufferSmallBytesFt pushBuffer;\
getAtSmallBytesFt getAt;\
diff --git a/release/libsheepy.h b/release/libsheepy.h
@@ -98,7 +98,7 @@
// version accoring to the version package: Release.Major.minor.patch
// https://noulin.net/version/file/README.md.html
-#define LIBSHEEPY_VERSION "1.2.2.1"
+#define LIBSHEEPY_VERSION "1.2.3"
#ifndef SH_PREFIX
#define SH_PREFIX(NAME) NAME
diff --git a/src/json/libsheepyCSmallBytes.c b/src/json/libsheepyCSmallBytes.c
@@ -52,6 +52,7 @@ internal const char* helpSmallBytes(smallBytest UNUSED *self);
internal char* toStringSmallBytes(smallBytest *self);
internal smallBytest* duplicateSmallBytes(smallBytest *self);
internal void* getSmallBytes(smallBytest *self);
+internal smallBytest* setSmallBytes(smallBytest *self, void *data, uint32_t size);
internal smallBytest* pushSmallBytes(smallBytest *self, char data);
internal smallBytest* pushBufferSmallBytes(smallBytest *self, void *data, uint32_t size);
internal char getAtSmallBytes(smallBytest *self, uint32_t index);
@@ -130,6 +131,7 @@ void registerMethodsSmallBytes(smallBytesFunctionst *f) {
f->finish = finishSmallBytes;
f->help = helpSmallBytes;
f->get = getSmallBytes;
+ f->set = setSmallBytes;
f->push = pushSmallBytes;
f->pushBuffer = pushBufferSmallBytes;
f->getAt = getAtSmallBytes;
@@ -291,6 +293,13 @@ internal void* getSmallBytes(smallBytest *self) {
return(sBytesGet(self->B));
}
+internal smallBytest* setSmallBytes(smallBytest *self, void *data, uint32_t size) {
+
+ freeSmallBytes(self);
+ sBytesPushBuffer(&(self->B), data, size);
+ return(self);
+}
+
internal smallBytest* pushSmallBytes(smallBytest *self, char data) {
sBytesPush(&(self->B), data);
diff --git a/src/json/libsheepyCSmallBytes.h b/src/json/libsheepyCSmallBytes.h
@@ -37,19 +37,31 @@ typedef struct smallBytes smallBytest;
typedef void (*freeSmallBytesFt) (smallBytest *self);
typedef void (*terminateSmallBytesFt) (smallBytest **self);
typedef char* (*toStringSmallBytesFt) (smallBytest *self);
-typedef smallBytest* (*duplicateSmallBytesFt) (smallBytest *self);
+typedef smallBytest* (*duplicateSmallBytesFt) (smallBytest *self);
/**
* free container
*/
-typedef void (*finishSmallBytesFt)(smallBytest **self);
+typedef void (*finishSmallBytesFt)(smallBytest **self);
-typedef const char* (*helpSmallBytesFt) (smallBytest *self);
+typedef const char* (*helpSmallBytesFt) (smallBytest *self);
/**
* get buffer in object
*/
-typedef void* (*getSmallBytesFt) (smallBytest *self);
+typedef void* (*getSmallBytesFt) (smallBytest *self);
+
+/**
+ * set data buffer in object
+ *
+ * after this call, the smallBytes object will have only data
+ *
+ * \param
+ * self small bytes
+ * data buffer to push
+ * size size of buffer
+ */
+typedef smallBytest* (*setSmallBytesFt) (smallBytest *self, void *data, uint32_t size);
/**
* push char to object
@@ -57,17 +69,17 @@ typedef void* (*getSmallBytesFt) (smallBytest *self);
* \param
* data char to push
*/
-typedef smallBytest* (*pushSmallBytesFt) (smallBytest *self, char data);
+typedef smallBytest* (*pushSmallBytesFt) (smallBytest *self, char data);
/**
* push data buffer to object
*
* \param
- * bytes small bytes
+ * self small bytes
* data buffer to push
* size size of buffer
*/
-typedef smallBytest* (*pushBufferSmallBytesFt) (smallBytest *self, void *data, uint32_t size);
+typedef smallBytest* (*pushBufferSmallBytesFt) (smallBytest *self, void *data, uint32_t size);
/**
* get char at index
@@ -77,7 +89,7 @@ typedef smallBytest* (*pushBufferSmallBytesFt) (smallBytest *self, void *data, u
* \return
* char at index
*/
-typedef char (*getAtSmallBytesFt) (smallBytest *self, uint32_t index);
+typedef char (*getAtSmallBytesFt) (smallBytest *self, uint32_t index);
/**
* return buffer size in bytes
@@ -86,14 +98,14 @@ typedef char (*getAtSmallBytesFt) (smallBytest *self, uint32_t index);
* size in bytes
* 0 when smallBytes is NULL
*/
-typedef size_t (*lenSmallBytesFt) (smallBytest *self);
+typedef size_t (*lenSmallBytesFt) (smallBytest *self);
/**
* \return
* true when self is empty (len=0)
* false when len > 0
*/
-typedef bool (*isEmptySmallBytesFt)(smallBytest *self);
+typedef bool (*isEmptySmallBytesFt)(smallBytest *self);
/**
* read file to self
@@ -180,7 +192,7 @@ typedef bool (*equalSmallBytesBaseFt)(smallBytest *self, baset *value);
#define SMALLBYTESFUNCTIONST \
helpSmallBytesFt help;\
getSmallBytesFt get;\
- /*set-*/\
+ setSmallBytesFt set;\
pushSmallBytesFt push;\
pushBufferSmallBytesFt pushBuffer;\
getAtSmallBytesFt getAt;\
diff --git a/src/libsheepy.h b/src/libsheepy.h
@@ -98,7 +98,7 @@
// version accoring to the version package: Release.Major.minor.patch
// https://noulin.net/version/file/README.md.html
-#define LIBSHEEPY_VERSION "1.2.2.1"
+#define LIBSHEEPY_VERSION "1.2.3"
#ifndef SH_PREFIX
#define SH_PREFIX(NAME) NAME