From d28adc34f20d54649302a0cb5279f6e8d285bdef Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Sun, 27 Mar 2016 23:58:06 +0000 Subject: [PATCH] Data type FossilOrigin-Name: 53a190d63de93cea35c7f791131d35aeab6db855406501adfaaa3396638f77ee --- src/cw/mbag_type_data.c | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/cw/mbag_type_data.c diff --git a/src/cw/mbag_type_data.c b/src/cw/mbag_type_data.c new file mode 100644 index 00000000..ac8a4f77 --- /dev/null +++ b/src/cw/mbag_type_data.c @@ -0,0 +1,43 @@ + +#include + +#include "mbag.h" +#include "format.h" + + + +static int to_str(void *item,char *dst) +{ + mbag_item_t *i= item; + return format_hex(dst, ((uint8_t*)i->data)+1, *((uint8_t*)i->data)); +} + + +static struct mbag_item * from_str(const char *src) +{ + + mbag_item_t * i = mbag_item_new(MBAG_DATA); + if (!i) + return NULL; + + + int l=strlen(src); + int msize=l/2; + if(l&1) + msize++; + uint8_t * mem = malloc(1+msize); + if (!mem) + return NULL; + + *(mem)=msize; + format_scan_hex_bytes(mem+1,src,l); + i->data=mem; + return i; + +} + + + +const struct mbag_typedef mbag_type_data = { + "Data",free,to_str,from_str +};