in reply to [NOT] How would you decode this?
Same way in Perl or C:
my $c= getc(); return $c if $c < 0x80; $c= getc() + (($c-0x80)<<8); return $c if $c < 0x4000 return getc() + (($c-0x4000)<<8);
In Perl, getc() would be something like:
sub getc { ord( substr($buf,0,1,'') ); }
In C, I'd probably consume the buffer building a normalized buffer that I'd read from Perl via something like unpack "L*" (and thus mostly not deal with Perl data structures in C code). And I don't think I'd sweat the few extra arithmetic operations by resorting to switch(c>>6) { case 0: case 1: return c; case 2: return ...; case 3: return ...; }
- tye
|
|---|