c - Serialize directory tree to send over TCP -
i sending dirtree on tcp client application. dir node structure looks this:
struct node { char *name; int count_subnodes; struct node **subnodes; };
to serialize:
void serialize(void *buffer, struct node *n, int *c){ int i; if(!n) return; memcpy(buffer+(*c), n, sizeof(*n)); *c+=sizeof(n); for(i = 0; < n->count_subnodes; i++){ serialize(buffer, n->subnode[i], c); } }
what doing wrong? segfaults when call serialize recursively subnodes. also, need sort of marker delimitation can reconstruct tree on client side?
edit: c keep count of current position in buffer.
edit 2: typo. sizeof(*n) not c. sorry
how know buffer big enough?
sizeof(n)
give the size of pointer, not struct; usesizeof(*n)
check
n->subnode[i]
notnull
Comments
Post a Comment