Vernier -- wrote: > Joel VanderWerf wrote: >> Another option: >> >> http://redshift.sourceforge.net/bit-struct/ >> >> I don't know bindata, but from a quick glance at the docs I see that it >> does handle related fields, like length fields that specify the length >> of another field. BitStruct does *not* do that. >> >> Another difference is that BitStruct is a subclass of string, so it is >> very efficient to send a bitstruct to a socket or file or perform other >> string operations. > > amazing performance, for creating 10k instances of the same simple > struct (ruby 1.9 rc1): > > user system total real > bindata 3.681000 0.000000 3.681000 ( 3.827000) > bit-struct 0.063000 0.000000 0.063000 ( 0.057000) > > so bit-struct is actually a good choice for networking without any > modifications Exactly. If you have big packets, and only need to access a few fields (esp. fixed length), bit-struct is especially efficient. But if you want to use accessors a lot, then other libs might be better. With bit-struct, each field access may require pack/unpack, bit masking/shifting, etc. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407