Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Automatically exported from code.google.com/p/phpbuffer

Notifications You must be signed in to change notification settings

sunli1223/phpbuffer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

4 Commits

Repository files navigation

phpbuffer is used to serialize php object and that communicate with other language.

sample1:

require 'class/BigEndianBytesBuffer.php';
class request {
	public $width = 5;
	public $height = 6;
	private $buffer;
	public function __construct() {
		
		$this->buffer = new BigEndianBytesBuffer ( );
	}
	public function tobytes() {
		$this->buffer->clear ();
		$this->buffer->writeInt ( $this->width );
		$this->buffer->writeInt ( $this->height );
		return $this->buffer;
	}
}

sample2: read data from a binary file which is written by java code.

	public static void main(String[] args) throws IOException {
		RandomAccessFile file = new RandomAccessFile("db", "rw");
		file.write(100);
		file.writeShort(101);
		file.writeInt(100000);
		file.writeLong(4000000000L);
		file.writeBytes("test");
		file.close();
	}

and php like following.


/**
 * get file buffer
 *
 * @return BigEndianBuffer
 */
function getfile(){
return new BigEndianBytesBuffer(file_get_contents('db'));
}
$buffer=getfile();
echo $buffer->readBytes(1);
echo "\r\n";
echo $buffer->readShort();
echo "\r\n";
echo $buffer->readInt();
echo "\r\n";
echo $buffer->readLong();
echo "\r\n";
echo $buffer->readBytes(4);
echo "\r\n";

will output

100
101
100000
4000000000
test

and you can use it in socket programe like this,

	$this->fd = new BigEndianSocketBuffer ( $host, $port );
		$this->fd->writeChar ( 0xC8 );
		$this->fd->writeChar ( 0xa0 );
		echo "\r\nstarted at:$rts\r\n";
		$this->fd->writeLong ( $rts );
		$this->fd->writeInt ( $sid );
		$this->fd->readInt ();

About

Automatically exported from code.google.com/p/phpbuffer

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /