<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Honestly I'm not sure; it's been years since the last time I used XDR.<br>
<br>
Perhaps there's an XDR or RPC mailing list somewhere? At this point
you're getting detailed enough in your questions that I suspect you'll
have better results if you seek out a group of people who are
specifically talking about XDR. I'm guessing there are very few people
serializing C structures to store in memcached, though I could be
wrong. Most of the client-side discussion here has been around
higher-level languages (Java, PHP, Perl, etc.) which provide built-in
serialization capabilities.<br>
<br>
-Steve<br>
<br>
<br>
Jure Petrovic wrote:
<blockquote cite="mid1165942535.5139.12.camel@localhost.localdomain"
type="cite">
<pre wrap="">
Got it!
It doesn't produce a 16 byte string. Whole input buffer is used. When
using xdrmem_create, the buffer for XDR_ENCODE and XDR_DECODE must have
the same length.
So, instead of
xdrmem_create(xdrs, input, strlen(input), XDR_DECODE);
I used:
xdrmem_create(xdrs, input, 32, XDR_DECODE);
and it works. Like it was so hard :=) In this case, I also have to send
all 32 bytes to memcached, even though not all are used by my 2
structures.
But I don't want network to deal with overhead. So what is the smallest
buffer size to use? Would simple sizeof(struct1) + sizeof(struct2) do?
Regards,
Jure
On Tue, 2006-12-12 at 15:29 +0100, Jure Petrovic wrote:
</pre>
<blockquote type="cite">
<pre wrap="">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
</pre>
</blockquote>
<pre wrap=""><!---->
</pre>
</blockquote>
<br>
</body>
</html>