Put and get methods added

FossilOrigin-Name: 7ce316e51021deae3f714236c0b17b19fa7861a9261c6d9e631e269dc14a5c08
This commit is contained in:
7u83@mail.ru 2016-04-03 07:48:42 +00:00
parent f37d318cbe
commit eaa57a65e5
3 changed files with 68 additions and 6 deletions

View File

@ -16,7 +16,7 @@
*/
#include "cw.h"
#include "mbag.h"
@ -35,10 +35,32 @@ static int to_str(void *item,char *dst)
return sprintf(dst, "%d", i->byte);
}
static struct mbag_item * get(const uint8_t *src,int len)
{
mbag_item_t * item = mbag_item_new(MBAG_BYTE);
if (!item)
return NULL;
item->byte=*src;
return item;
}
static int put(struct mbag_item * i, uint8_t *dst)
{
return cw_put_byte(dst,i->byte);
}
/** Defines a word, two bytes. */
const struct mbag_typedef mbag_type_byte = {
"Byte",NULL,to_str,from_str
.name = "Byte",
.del = NULL,
.to_str = to_str,
.from_str = from_str,
.get = get,
.put = put
};

View File

@ -16,7 +16,7 @@
*/
#include "cw.h"
#include "mbag.h"
@ -35,9 +35,29 @@ static int to_str(void *item,char *dst)
return sprintf(dst, "%d", i->dword);
}
static struct mbag_item * get(const uint8_t *src,int len)
{
mbag_item_t * item = mbag_item_new(MBAG_DWORD);
if (!item)
return NULL;
item->dword=cw_get_dword(src);
return item;
}
static int put(struct mbag_item * i, uint8_t *dst)
{
return cw_put_dword(dst,i->dword);
}
const struct mbag_typedef mbag_type_dword = {
"DWORD",NULL,to_str,from_str
.name = "Dword",
.del = NULL,
.to_str = to_str,
.from_str = from_str,
.get = get,
.put = put
};

View File

@ -16,7 +16,7 @@
*/
#include "cw.h"
#include "mbag.h"
@ -35,10 +35,30 @@ static int to_str(void *item,char *dst)
return sprintf(dst, "%d", i->word);
}
static struct mbag_item * get(const uint8_t *src,int len)
{
mbag_item_t * item = mbag_item_new(MBAG_WORD);
if (!item)
return NULL;
item->word=cw_get_word(src);
return item;
}
static int put(struct mbag_item * i, uint8_t *dst)
{
return cw_put_word(dst,i->word);
}
/** Defines a word, two bytes. */
const struct mbag_typedef mbag_type_word = {
"WORD",NULL,to_str,from_str
.name = "Word",
.del = NULL,
.to_str = to_str,
.from_str = from_str,
.get = get,
.put = put
};