From: Robert Feldt Date: 2003-05-29T18:01:41+09:00 Subject: Re: RCR: unpack/pack Bignum On Thu, 29 May 2003, Brian Candler wrote: > On Thu, May 29, 2003 at 07:20:04AM +0900, Robert Feldt wrote: > > This patch adds a 'W' template character to pack and unpack for > > packing/unpacking an unsigned integer (Fixnum *OR* Bignum). The packing > > is from MSB to LSB so that > > > > [0xff00].pack("W") == "\377\000" > > It's variable length, but without carrying a length indication? How would > you unpack such a thing when included in a string with other items; do you > have to add a length indication yourself? > In general yes but its not currently implemented, instead unpack("W") eats all chars. IMHO, pack/unpack include two major types of templates, one group has fixed length and can be used in sequence with each other, the other group eats as many chars it can while unpacking and thus are typically used on their own. "m" is an examples of the latter and I propose we have one for bignums as well. Although, we could do something like for "A" and have the count be the width. Maybe I'm mixing different things here, maybe better to have this a a method on Numeric? Numeric#to_raw_string and Numeric.from_raw_string(str)? Regards, Robert