Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > reading in C structs

Reply
Thread Tools

reading in C structs

 
 
Joe Van Dyk
Guest
Posts: n/a
 
      08-26-2005
I have the following C struct:

typedef struct
{
short Elev; /* vertex elevation */
u_char Zone; /* terrain fearture type */
u_char Mono; /* monochrome brightness value */
ulong rgb; /* rgb color components of vertex */

} cell_type

The rgb values are bitshifted into the rgb ulong, and then the rgb
ulong is converted to a network long.

Then a bunch of those structs are written into a file. =20

What's the Ruby way of getting the RGB values out? Is the unpack
specification "sccN"? And then I'd unpack the network long with
"cccc"?


 
Reply With Quote
 
 
 
 
Joel VanderWerf
Guest
Posts: n/a
 
      08-26-2005
Joe Van Dyk wrote:
> I have the following C struct:
>
> typedef struct
> {
> short Elev; /* vertex elevation */
> u_char Zone; /* terrain fearture type */
> u_char Mono; /* monochrome brightness value */
> ulong rgb; /* rgb color components of vertex */
>
> } cell_type
>
> The rgb values are bitshifted into the rgb ulong, and then the rgb
> ulong is converted to a network long.
>
> Then a bunch of those structs are written into a file.
>
> What's the Ruby way of getting the RGB values out? Is the unpack
> specification "sccN"? And then I'd unpack the network long with
> "cccc"?
>


IIUC, just unpack "sC6", C for unsigned char.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Packed structs vs. unpacked structs: what's the difference? Daniel Rudy C Programming 15 04-10-2006 08:10 AM
Array of structs instead of an array with pointers to structs? Paminu C Programming 5 10-11-2005 07:18 PM
length of an array in a struct in an array of structs in a struct in an array of structs Tuan Bui Perl Misc 14 07-29-2005 02:39 PM
const structs in other structs Chris Hauxwell C Programming 6 04-27-2004 07:03 PM
structs with fields that are structs Patricia Van Hise C Programming 5 04-05-2004 01:37 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57