libmemcache - custom structures
Jure Petrovic
fonz at siol.net
Tue Dec 12 14:29:50 UTC 2006
Hello,
Maybe someone already used XDR...
Having 2 structures like this:
bool_t xdr_doubles (XDR *xdrs, doubles *objp)
{
register int32_t *buf;
if (!xdr_double (xdrs, &objp->a))
return FALSE;
if (!xdr_double (xdrs, &objp->b))
return FALSE;
if (!xdr_reference (xdrs, (char **)&objp->c, sizeof (person),
(xdrproc_t)xdr_person))
return FALSE;
return TRUE;
}
bool_t xdr_person (XDR *xdrs, person *objp)
{
register int32_t *buf;
if (!xdr_int (xdrs, &objp->age))
return FALSE;
return TRUE;
}
Now encoding with:
XDR *xdrs = malloc(sizeof(XDR));
char *input = malloc(32);
xdrmem_create(xdrs, input, 32, XDR_ENCODE);
if (xdr_doubles(xdrs, structure)) printf("encode()::success\n");
works great and produces a 16-byte string. But when decoding with:
XDR *xdrs = malloc(sizeof(XDR));
doubles *structure = malloc(sizeof(doubles));
structure->c = NULL; // if null, XDR should allocate memory!!
xdrmem_create(xdrs, input, strlen(input), XDR_DECODE);
if (xdr_doubles(xdrs, structure)) printf("decode()::success\n");
structure->c->age doesn't get filled. As I understand from manuals,
memory for deserializing should get allocated automatically, but it
seems that is not the case.
If I use xdr_pointer() instead of xdr_reference() as suggested, I get a
null pointer for structure->c.
Any ideas?
Thanks,
Jure
More information about the memcached
mailing list