summaryrefslogtreecommitdiff
path: root/lib/val/ypc_get_size.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/val/ypc_get_size.c')
-rw-r--r--lib/val/ypc_get_size.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/val/ypc_get_size.c b/lib/val/ypc_get_size.c
new file mode 100644
index 0000000..2fdaa97
--- /dev/null
+++ b/lib/val/ypc_get_size.c
@@ -0,0 +1,36 @@
+#include "../internal.h"
+
+YPC_EXPORT size_t ypc_get_size(ypc_get g) {
+ switch(*g.buf) {
+ case YPCT_NULL:
+ case YPCT_FALSE:
+ case YPCT_TRUE:
+ case YPCT_CLOSE:
+ return 1;
+ case YPCT_INT8:
+ return 2;
+ case YPCT_INT16:
+ return 3;
+ case YPCT_INT32:
+ return 5;
+ case YPCT_INT64:
+ case YPCT_FLOAT:
+ return 9;
+ case YPCT_BIN:
+ return 4+ypc_get_bin_len(g);
+ case YPCT_TEXT:
+ return 2+strlen((const char *)g.buf+1);
+ case YPCT_ARRAY:
+ case YPCT_MAP:
+ {
+ size_t l = 1;
+ while(g.buf[l] != YPCT_CLOSE) {
+ ypc_get v = {g.buf+l};
+ l += ypc_get_size(v);
+ }
+ return l+1;
+ }
+ }
+ assert(0 && "ypc_get_size() used on an invalid value");
+ return 0;
+}