Re: unpacking an array of structs...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



have you considered using json as transport?
http://json.org/ has code you can re-use.

On Tue, Feb 23, 2010 at 7:29 AM, php.list@xxxxxxxx <php.list@xxxxxxxx> wrote:
>
> I have a desktop app that has a data structure that looks like this:
>
> typedef struct MANGOpie
> {
>   unsigned char   mango;
>   unsigned short  pie;
> }
> MANGOpie;
>
>
>
> I manage a C array of these things in memory:
>
> MANGOpie * pies = (MANGOpie *)malloc(count*sizeof(MANGOpie));
>
>
>
>
> I pass these to a PHP script on my webserver who needs to unpack the array
> of structs.
>
> The unpack() PHP function appears to be what I need, but it doesn't like the
> formatting I'm using to describe an array of these structs:
>
> "(Cmango/npie)*"
>
> What it doesn't like are the parentheses.  I've tried brackets and curlies
> too, but nothing works.  I have to have the parentheses to tell the parser
> to repeat the entire struct:
>
> mango
> pie
> mango
> pie
> mango
> pie
> ...
>
>
>
> Formatting without the parentheses -- "Cmango/npie*" -- is:
>
> mango
> pie
> pie
> pie
> pie
> pie
> ...
>
>
>
> One workaround is to drop the struct and just manage two separate parallel
> arrays of each data type in the desktop app:
>
> unsigned char *   mangos = (unsigned char  *)malloc(count*sizeof(unsigned
> char));
> unsigned short *  pies   = (unsigned short *)malloc(count*sizeof(unsigned
> short));
>
> With PHP unpack() format strings:
>
> "Cmango*"
> "npie*"
>
> But, I'd rather keep the struct for the sake of code clarity and neatness.
>
>
>
> Another would be to iterate thru the binary data, unpacking one struct at a
> time, but that would be slower, presumably.
>
>
>
>
>
>
>
>
>
> Anyone know the trick to this?
>
> Thanks.
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux