reading in C structs

J

Joe Van Dyk

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"?
 
J

Joel VanderWerf

Joe said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top