libmemcache - custom structures
Steven Grimm
sgrimm at facebook.com
Tue Dec 12 17:33:15 UTC 2006
Honestly I'm not sure; it's been years since the last time I used XDR.
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.
-Steve
Jure Petrovic wrote:
> 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:
>
>> 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
>>
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.danga.com/pipermail/memcached/attachments/20061212/8005451e/attachment.htm
More information about the memcached
mailing list