binary protocol notes from the facebook hackathon

Trond Norbye Trond.Norbye at Sun.COM
Wed Jul 11 09:19:01 UTC 2007


Dustin Sallings wrote:
>
> On Jul 11, 2007, at 1:55, Trond Norbye wrote:
>
>> I would also prefer a total length field. This would let me easily 
>> determine if I have the complete packet or not without searching 
>> through the packet and look for the various length fields...
>
>     You do have that.  You must have 12 bytes for any packet.  The 
> last four bytes of that tells you the number of bytes remaining.
>
>     I use that in my test server now to detect when I've accumulated 
> enough data to process a complete response.
>
Sorry.. I looked at the structure in the mail I replied to:
 > What I prefer is:
 >  * Magic byte / version
 >  * Cmd byte
 >  * 4 byte opaque id.
 >  * Key len byte  (if no key, 0)
 >  * key, if key length above is non-zero.
 >  * 4 byte body length (not including reserved byte at the end)
 >  * [ cmd-specific fixed-width fields ]
 >  * [ cmd-specific variable-width field ]
 >  * Reserved byte (should be 0)

In this structure I need to get the key before I can get the body length 
;-) I looked at the original structure now, and you're right :-)

Trond



More information about the memcached mailing list