in reply to keeping binary data raw

Hi downer,

Damn intriguing question (imho).

Fwiw, I think you'll find that if you change the Inline::C incantation of varbyte() to:
SV * varbyte(int number) { oneRecord record; //int decom_num; record = vbyte_compress(number); return newSVpv(record.vbyte_result, record.vbyte_len); }
then you'll find it does what you want.

Furthermore, I suspect that therein lies a reason that the vbyte_record structure contains the vbyte_len element.

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: keeping binary data raw
by downer (Monk) on Oct 26, 2007 at 16:20 UTC
    this seems to create a result much closer to what i would expect (where the compressed length is < the input length). however, i can't claim i understand the whole newSVpv() thing. I dont need the vbyte_len returned, this is simply an internal value i used for printing out a representation of the compressed numbers. however, when i just try to do a newSVpv with one value, it doesnt compile.

      vbyte_result points to an array of characters. You can't do anything with an array unless you know its size. How is Perl suppose to know how big the array is? For the same reason you need to know the length of the array to print it, you need to know the length of the array to create the Perl string the contains it. That's why you need to pass both the data and the length of the data to newSVpv.

        forgive me, i couldnt find how newSVpv worked. thanks!