aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid <david@xagasoft.com>2011-02-21 22:42:42 +0000
committerDavid <david@xagasoft.com>2011-02-21 22:42:42 +0000
commita5009d2e8c0378180dd3aca39c10c1dc0af3a93e (patch)
tree21ef9286cb9eb5f005dc0f1c6a8eecebbd5d91d1
parent035a2609a8ee30d580026ba0c8b451e781c6e555 (diff)
downloadlibgats-a5009d2e8c0378180dd3aca39c10c1dc0af3a93e.tar.gz
libgats-a5009d2e8c0378180dd3aca39c10c1dc0af3a93e.tar.bz2
libgats-a5009d2e8c0378180dd3aca39c10c1dc0af3a93e.tar.xz
libgats-a5009d2e8c0378180dd3aca39c10c1dc0af3a93e.zip
david - int usage changes
Diffstat (limited to '')
-rw-r--r--php/phpgats.php35
1 files changed, 23 insertions, 12 deletions
diff --git a/php/phpgats.php b/php/phpgats.php
index 20e5ef2..c2b7857 100644
--- a/php/phpgats.php
+++ b/php/phpgats.php
@@ -157,6 +157,8 @@ class phpgats_Integer extends phpgats_Element
157 { 157 {
158 if( getType($_elem) != "resource" ) 158 if( getType($_elem) != "resource" )
159 $this->elem = gmp_init($_elem); 159 $this->elem = gmp_init($_elem);
160 else
161 $this->elem = $_elem;
160 } 162 }
161 163
162 function set( $_elem ) 164 function set( $_elem )
@@ -166,6 +168,11 @@ class phpgats_Integer extends phpgats_Element
166 168
167 function get() 169 function get()
168 { 170 {
171 return gmp_intval($this->elem);
172 }
173
174 function get64()
175 {
169 return $this->elem; 176 return $this->elem;
170 } 177 }
171 178
@@ -380,38 +387,38 @@ function phpgats_pM( $str_data, &$offset, $dbg=0 )
380 switch( $c ) 387 switch( $c )
381 { 388 {
382 case 'i': 389 case 'i':
383 echo "int:"; 390 //echo "int:";
384 $obj = phpgats_pI( $str_data, $offset, $dbg ); 391 $obj = phpgats_pI( $str_data, $offset, $dbg );
385 echo gmp_strval($obj->get()) . "\n"; 392 //echo gmp_strval($obj->get()) . "\n";
386 return $obj; 393 return $obj;
387 break; 394 break;
388 case 'l': 395 case 'l':
389 echo "list:\n"; 396 //echo "list:\n";
390 $obj = phpgats_pL( $str_data, $offset, $dbg+1 ); 397 $obj = phpgats_pL( $str_data, $offset, $dbg+1 );
391 return $obj; 398 return $obj;
392 break; 399 break;
393 case 'd': 400 case 'd':
394 echo "dic:\n"; 401 //echo "dic:\n";
395 $obj = phpgats_pD( $str_data, $offset, $dbg+1 ); 402 $obj = phpgats_pD( $str_data, $offset, $dbg+1 );
396 return $obj; 403 return $obj;
397 break; 404 break;
398 case 'f': 405 case 'f':
399 echo "float:\n"; 406 //echo "float:\n";
400 $obj = phpgats_pF( $str_data, $offset, $dbg ); 407 $obj = phpgats_pF( $str_data, $offset, $dbg );
401 return $obj; 408 return $obj;
402 break; 409 break;
403 case '1': 410 case '1':
404 echo "true\n"; 411 //echo "true\n";
405 return new phpgats_Boolean( true ); 412 return new phpgats_Boolean( true );
406 break; 413 break;
407 case '0': 414 case '0':
408 echo "false\n"; 415 //echo "false\n";
409 return new phpgats_Boolean( false ); 416 return new phpgats_Boolean( false );
410 break; 417 break;
411 default: 418 default:
412 echo "str:"; 419 //echo "str:";
413 $obj = phpgats_pS( $str_data, $offset, $dbg ); 420 $obj = phpgats_pS( $str_data, $offset, $dbg );
414 echo $obj->get() . "\n"; 421 //echo $obj->get() . "\n";
415 return $obj; 422 return $obj;
416 break; 423 break;
417 } 424 }
@@ -419,22 +426,26 @@ function phpgats_pM( $str_data, &$offset, $dbg=0 )
419 426
420function phpgats_parseGats( $str_data ) 427function phpgats_parseGats( $str_data )
421{ 428{
422 print "parsing\n"; 429 //print "parsing\n";
423 $offset = 0; 430 $offset = 0;
424 $data_size = strlen( $str_data ); 431 $data_size = strlen( $str_data );
425 if( $data_size < 5 ) 432 if( $data_size < 5 )
426 { 433 {
427 print "invalid size (< 5)\n"; 434 throw new Exception( "invalid size (< 5)\n" );
428 return false; 435 return false;
429 } 436 }
430 if( ord($str_data) != 1 ) //version 437 if( ord($str_data) != 1 ) //version
438 {
439 throw new Exception( "invalid gats version" );
431 return false; 440 return false;
441 }
432 $size = "" . $str_data[1] . $str_data[2] . $str_data[3] . $str_data[4]; 442 $size = "" . $str_data[1] . $str_data[2] . $str_data[3] . $str_data[4];
433 $size = unpack( "Nsize", $size ); 443 $size = unpack( "Nsize", $size );
434 $size = $size["size"]; 444 $size = $size["size"];
435 if( $data_size < $size ) 445 if( $data_size < $size )
436 { 446 {
437 print "invalid size (needed: " . $size . ", was: " . $data_size . ")\n"; 447 throw new Exception( "invalid size (needed: " . $size .
448 ", was: " . $data_size . ")\n" );
438 return false; 449 return false;
439 } 450 }
440 $offset+=5; 451 $offset+=5;