[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: How to pack/unpack nested structures?

Nobuyoshi Nakada

7/14/2006 3:15:00 PM

Hi,

At Thu, 13 Jul 2006 00:31:37 +0900,
Justin Bailey wrote in [ruby-talk:201532]:
> version = 1
> numBuffers = 1
>
> bufferSize = 100
> bufferType = 2
> buffer = "\0" * bufferSize

I guess this buffer is the answer, unless the function returns
another pointer.

> struct = [version, numBuffers, [bufferSize, bufferType,
> buffer].pack("LLP")].pack("LLP")

or:

nested_struct = [bufferSize, bufferType, buffer].pack("LLP")
struct = [version, numBuffers, inner_struct].pack("LLP")

nested_struct.unpack("LLP12")

If the function alters buffer of struct SecurityBuffer, says it
allocates new buffer and returns it, unpack can't deal with it.
You need DL instead.

--
Nobu Nakada