Skip to content
Snippets Groups Projects
Commit 33f29e9d authored by tewk's avatar tewk
Browse files

Added unpackmem routines that just copy memory from a message buffer to a buffer in a structure

parent 0097b1b6
No related branches found
No related tags found
No related merge requests found
...@@ -162,6 +162,33 @@ _unpackmem_ptr(char **valp, uint16_t *size_valp, void **bufp, int *lenp) ...@@ -162,6 +162,33 @@ _unpackmem_ptr(char **valp, uint16_t *size_valp, void **bufp, int *lenp)
} }
/*
* Given 'bufp' pointing to a network byte order 32-bit integer
* (size) and an arbitrary data string, return a pointer to the
* data string in 'valp'. Also return the sizes of 'valp' in bytes.
* Advance bufp and decrement lenp by 4 bytes (size of memory
* size records) plus the actual buffer size.
*/
void
_unpackmem(char *valp, uint16_t *size_valp, void **bufp, int *lenp)
{
uint16_t nl;
memcpy(&nl, *bufp, sizeof(nl));
*size_valp = ntohs(nl);
(size_t)*bufp += sizeof(nl);
*lenp -= sizeof(nl);
if (*size_valp > 0) {
memcpy ( valp, *bufp, *size_valp);
(size_t)*bufp += *size_valp;
*lenp -= *size_valp;
}
else
*valp = 0 ;
}
/* /*
* Given 'bufp' pointing to a network byte order 32-bit integer * Given 'bufp' pointing to a network byte order 32-bit integer
* (size) and an arbitrary data string, return a pointer to the * (size) and an arbitrary data string, return a pointer to the
......
...@@ -32,6 +32,7 @@ void _packstrarray(char **valp, uint16_t size_val, void **bufp, int *lenp); ...@@ -32,6 +32,7 @@ void _packstrarray(char **valp, uint16_t size_val, void **bufp, int *lenp);
void _unpackstrarray(char ***valp, uint16_t* size_val, void **bufp, int *lenp); void _unpackstrarray(char ***valp, uint16_t* size_val, void **bufp, int *lenp);
void _packmem(char *valp, uint16_t size_val, void **bufp, int *lenp); void _packmem(char *valp, uint16_t size_val, void **bufp, int *lenp);
void _unpackmem(char *valp, uint16_t *size_valp, void **bufp, int *lenp);
void _unpackmem_ptr(char **valp, uint16_t *size_valp, void **bufp, int *lenp); void _unpackmem_ptr(char **valp, uint16_t *size_valp, void **bufp, int *lenp);
void _unpackmem_xmalloc(char **valp, uint16_t *size_valp, void **bufp, int *lenp); void _unpackmem_xmalloc(char **valp, uint16_t *size_valp, void **bufp, int *lenp);
void _unpackmem_malloc(char **valp, uint16_t *size_valp, void **bufp, int *lenp); void _unpackmem_malloc(char **valp, uint16_t *size_valp, void **bufp, int *lenp);
...@@ -78,6 +79,15 @@ void _unpackmem_malloc(char **valp, uint16_t *size_valp, void **bufp, int *lenp) ...@@ -78,6 +79,15 @@ void _unpackmem_malloc(char **valp, uint16_t *size_valp, void **bufp, int *lenp)
_packmem(valp,(uint16_t)size_val,bufp,lenp); \ _packmem(valp,(uint16_t)size_val,bufp,lenp); \
} while (0) } while (0)
#define unpackmem(valp,size_valp,bufp,lenp) do { \
assert(valp != NULL); \
assert(sizeof(size_valp) == sizeof(uint16_t *));\
assert((bufp) != NULL && *(bufp) != NULL); \
assert((lenp) != NULL); \
assert(*(lenp) >= sizeof(uint16_t)); \
_unpackmem(valp,(uint16_t *)size_valp,bufp,lenp); \
} while (0)
#define packstr(str,bufp,lenp) do { \ #define packstr(str,bufp,lenp) do { \
uint32_t _size; \ uint32_t _size; \
_size = (uint32_t)(str ? strlen(str)+1 : 0); \ _size = (uint32_t)(str ? strlen(str)+1 : 0); \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment