libmemcache - custom structures

Jure Petrovic fonz at siol.net
Mon Dec 18 16:06:17 UTC 2006


I know I was a bit off topic here, since XDR is usually not used in
conjunction with memcached. Just thought somebody already used XDR,
since the suggestion mentioned it.

Anyway, I tested this thing and it's like said in previous post. The
minimum buffer size, that you need for encoding is equal to the sum of
sizes of all the structures you're encoding. So, in my case simple

int size = sizeof(struct1) + sizeof(struct2);

does the trick.    

I'm posting this here for the sake of completeness. Thank you, Mr. Steve
for helping me out :=)


>> 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
> 
> 



More information about the memcached mailing list