dimanche 1 mars 2015

Help converting python::bitstream usage to PHP equivalent


I need to read some data coming in from a client via a SOCKET using PHP. I found an example in python but I am not a python programmer. Here is the full python example code I am trying to covert. Note this part:


The values are transmitted in little-endian format, and we’ll use ConstBitStream (code.google.com) to manage it.


I can read the data from the client but I am having a hard time deciphering it. I thought I needed to use PHP's UNPACK but that doesn't seem to be working - or I am using it incorrectly. I need some help converting this portion of the python code to PHP code please:


PYTHON CODE



msize = data.read('intle:16')
mtype = data.read('intle:16')
mtime = data.read('intle:64')

# RA:
ant_pos = data.bitpos
ra = data.read('hex:32')
data.bitpos = ant_pos
ra_uint = data.read('uintle:32')

# DEC:
ant_pos = data.bitpos
dec = data.read('hex:32')
data.bitpos = ant_pos
dec_int = data.read('intle:32')


PHP CODE (my attempt anyway)



$buf = \socket_read( $msgsock, 30, \PHP_BINARY_READ )
$mLength = \unpack( 's', \substr( $buf, 0, 2 ) );
$mType = \unpack( 's', \substr( $buf, 2, 2 ) );
$mTime = \unpack( 'P', \substr( $buf, 4, 8 ) );
$mDate = \date( 'Y-m-d H:i:s', $mTime[ 1 ] );




Aucun commentaire:

Enregistrer un commentaire