On Wed, 14 Mar 2007, Dharshana Eswaran wrote:

On 3/13/07, Tom Phoenix <[EMAIL PROTECTED]> wrote:

 On 3/13/07, Dharshana Eswaran <[EMAIL PROTECTED]> wrote:

>  I was going thro the topic "Accessing packed data structures" in the
 Perl
>  Complete Reference Book. I came across this example:
> > struct utmp {
>  char ut_user[8]; /* User login name */
>  char ut_id[4]; /* /etc/inittab id */
>  char ut_line[12]; /* device name */
>  short ut_pid; /* process ID */
>  short ut_type; /* type of entry */
>  struct exit_status ut_exit; /* The exit status of a process */
>  /* marked as DEAD_PROCESS. */
>  time_t ut_time; /* time entry was made */
> };
> > For the above structure: > > The pack template given was "a8a4a12ssssl".

>  I am, somehow, not able to understand how to generate the pack template
 from
>  the structure's data types.

 The pieces match up this way:

 char ut_user[8]; /* User login name: a8 */
 char ut_id[4]; /* /etc/inittab id: a4 */
 char ut_line[12]; /* device name: a12 */
 short ut_pid; /* process ID: s */
 short ut_type; /* type of entry: s */
 struct exit_status ut_exit; /* The exit status of a process */
 /* marked as DEAD_PROCESS: s s */
 time_t ut_time; /* time entry was made: l */

 A char array becomes an a42, with the number being the length of the
 array. A short becomes s, and a long becomes l. (You do need to know
 something about how C stores data in memory. Note that exit_status and
 ut_exit are two variables, even though they are declared on the same
 line; that's why there are two s's in the comment.)

>  Here, how does the pack and unpack play its role? What format should the
>  input be in? What are the possible formats it can accept here?

 Have you seen the documentation for pack and unpack? There is a large
 table of format letters. Are you asking for something else?

 Do you have a C struct that you can't translate to a pack/unpack
 template? If so, feel free to post it here. Someone will know how to
 deal with it.

 Yes, you are right...

I have a structure and it is somethiung like this

typedef struct  _TAPI_VOICE_NOTIFY_INCOMING_CALL_MSG_S

               TAPI_CALL_ID_T                  callId;
               TAPI_VOICE_INCOMING_CALL_TYPE_E type;
               TAPI_PHONE_NUMBER_A             phoneNumber;
               TAPI_CALL_LINE_E                lineNo;
               TAPI_PHONEBOOK_NAME_A           alpha;
           } TAPI_VOICE_NOTIFY_INCOMING_CALL_MSG_S;

Here the typedefs are:

TAPI_CALL_ID_T, TAPI_PHONE_NUMBER_A, TAPI_PHONEBOOK_NAME_A   => Unsigned int
8
TAPI_VOICE_INCOMING_CALL_TYPE_E => enum type
TAPI_CALL_LINE_E  => signed int 8

Now how do i come up with the pack template? I dont know how a enum should
be represented in the pack template. :-(

/I8(enum)I8i8I8/ => pack template

The above mentioned enum just contains two elements.

The data which i need to pack and unpack to these elements are in hex
format(0x0B 0x1C 0x34 etc). It is a string of hex bytes.

I kindly request anyone to guide me in this.

Thanks and Regards,
Dharshana


What about this one:

http://search.cpan.org/~mhx/Convert-Binary-C-0.67/lib/Convert/Binary/C.pm

I once used it to solve the complex pack/unpack temlate and machine endianess problem

Vincent Li
http://bl0g.blogdns.com

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to