2016-03-19 12:32:11 +01:00
|
|
|
#include "mbag.h"
|
|
|
|
#include "cw.h"
|
|
|
|
|
2016-03-19 12:54:40 +01:00
|
|
|
int mbag_set_from_buf(mbag_t dst, mbagtype_t type, const char *item_id, uint8_t *data, int len)
|
2016-03-19 12:32:11 +01:00
|
|
|
{
|
|
|
|
|
2016-03-19 12:54:40 +01:00
|
|
|
if (type == MBAG_BYTE) {
|
2016-03-19 12:32:11 +01:00
|
|
|
mbag_set_byte(dst, item_id, *data);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-03-19 12:54:40 +01:00
|
|
|
if (type == MBAG_WORD) {
|
2016-03-19 12:32:11 +01:00
|
|
|
mbag_set_word(dst, item_id, cw_get_word(data));
|
|
|
|
return 1;
|
|
|
|
}
|
2018-02-18 14:17:45 +01:00
|
|
|
if (type == MTYPE_DWORD) {
|
2016-03-19 12:32:11 +01:00
|
|
|
mbag_set_dword(dst, item_id, cw_get_dword(data));
|
|
|
|
return 1;
|
|
|
|
}
|
2016-03-19 12:54:40 +01:00
|
|
|
if (type == MBAG_STR) {
|
2016-03-19 12:32:11 +01:00
|
|
|
mbag_set_strn(dst, item_id, (char *) data, len);
|
|
|
|
return 1;
|
|
|
|
}
|
2016-03-19 12:54:40 +01:00
|
|
|
if (type == MBAG_BSTR) {
|
2016-03-19 12:32:11 +01:00
|
|
|
mbag_set_bstrn(dst, item_id, data, len);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-03-19 12:54:40 +01:00
|
|
|
if (type == MBAG_BSTR16) {
|
2016-03-19 12:32:11 +01:00
|
|
|
mbag_set_bstr16n(dst, item_id, data, len);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-03-19 12:54:40 +01:00
|
|
|
if (type == MBAG_VENDORSTR) {
|
2016-03-19 12:32:11 +01:00
|
|
|
mbag_set_bstrv(dst, item_id,
|
|
|
|
cw_get_dword(data), data + 4, len - 4);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-03-28 16:46:38 +02:00
|
|
|
if (type->get){
|
|
|
|
struct mbag_item * item = type->get(data,len);
|
|
|
|
if (!item)
|
|
|
|
return 0;
|
|
|
|
item->id=item_id;
|
|
|
|
mbag_set(dst,item);
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-03-19 12:32:11 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|