From a5009d2e8c0378180dd3aca39c10c1dc0af3a93e Mon Sep 17 00:00:00 2001 From: David Date: Mon, 21 Feb 2011 22:42:42 +0000 Subject: david - int usage changes --- php/phpgats.php | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'php') 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 { if( getType($_elem) != "resource" ) $this->elem = gmp_init($_elem); + else + $this->elem = $_elem; } function set( $_elem ) @@ -165,6 +167,11 @@ class phpgats_Integer extends phpgats_Element } function get() + { + return gmp_intval($this->elem); + } + + function get64() { return $this->elem; } @@ -380,38 +387,38 @@ function phpgats_pM( $str_data, &$offset, $dbg=0 ) switch( $c ) { case 'i': - echo "int:"; + //echo "int:"; $obj = phpgats_pI( $str_data, $offset, $dbg ); - echo gmp_strval($obj->get()) . "\n"; + //echo gmp_strval($obj->get()) . "\n"; return $obj; break; case 'l': - echo "list:\n"; + //echo "list:\n"; $obj = phpgats_pL( $str_data, $offset, $dbg+1 ); return $obj; break; case 'd': - echo "dic:\n"; + //echo "dic:\n"; $obj = phpgats_pD( $str_data, $offset, $dbg+1 ); return $obj; break; case 'f': - echo "float:\n"; + //echo "float:\n"; $obj = phpgats_pF( $str_data, $offset, $dbg ); return $obj; break; case '1': - echo "true\n"; + //echo "true\n"; return new phpgats_Boolean( true ); break; case '0': - echo "false\n"; + //echo "false\n"; return new phpgats_Boolean( false ); break; default: - echo "str:"; + //echo "str:"; $obj = phpgats_pS( $str_data, $offset, $dbg ); - echo $obj->get() . "\n"; + //echo $obj->get() . "\n"; return $obj; break; } @@ -419,22 +426,26 @@ function phpgats_pM( $str_data, &$offset, $dbg=0 ) function phpgats_parseGats( $str_data ) { - print "parsing\n"; + //print "parsing\n"; $offset = 0; $data_size = strlen( $str_data ); if( $data_size < 5 ) { - print "invalid size (< 5)\n"; + throw new Exception( "invalid size (< 5)\n" ); return false; } if( ord($str_data) != 1 ) //version + { + throw new Exception( "invalid gats version" ); return false; + } $size = "" . $str_data[1] . $str_data[2] . $str_data[3] . $str_data[4]; $size = unpack( "Nsize", $size ); $size = $size["size"]; if( $data_size < $size ) { - print "invalid size (needed: " . $size . ", was: " . $data_size . ")\n"; + throw new Exception( "invalid size (needed: " . $size . + ", was: " . $data_size . ")\n" ); return false; } $offset+=5; -- cgit v1.2.3