Data type
FossilOrigin-Name: 53a190d63de93cea35c7f791131d35aeab6db855406501adfaaa3396638f77ee
This commit is contained in:
parent
93d53d3351
commit
d28adc34f2
43
src/cw/mbag_type_data.c
Normal file
43
src/cw/mbag_type_data.c
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#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
|
||||
};
|
Loading…
Reference in New Issue
Block a user