[OSM-dev] Ruby help - streams of bits

Richard Fairhurst richard at systemeD.net
Thu May 17 11:57:10 BST 2007


Hi all,

I'm working on removing the Ming dependency from Potlatch's GPS code.  
In other words, you won't need Ming to run Potlatch on your own  
machine - you'll only need it to compile the SWF if you want to make  
any changes to Potlatch.

I've rewritten the getgps script to assemble the SWF 'manually', and  
it works exactly as it should. Only trouble is that it's a bit slow.

SWF's opcodes and arguments are encoded as variable-length streams of  
bits. These are all packed in direct succession - i.e. not padded to  
byte boundaries or anything like that.

So, for example, you might have

   00111         5-bit record
   0110101       7-bit record
   0000110       7-bit record
   0001100       7-bit record
   1111101       7-bit record

which would be packed as

   0b00111011,0b01010000,0b11000011,0b00111110,0b10000000
                                               (final byte null-padded)

At present I'm doing this by assembling a big big big binary string,  
then splitting it into eight-character strings and converting each one  
into a number. But this is dreadfully slow.

Do any of the Ruby experts here have any better ideas?

cheers
Richard





More information about the dev mailing list