Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- @author: Devsaider;
- @author-uri: devsaider.ru, devmices.ru;
- @description: Original ByteArray by L'fleur rewrite for PHP by Devsaider;
- http://pastebin.com/u/Devsaider
- */
- class ByteArray{
- private $BytesString;
- function ByteArray($bytes = "") {
- $this->BytesString = $bytes;
- }
- function writeBoolean($value = 1) {
- $this->BytesString .= $this->writeByte($value, False);
- }
- function writeByte($value, $noReturning=True) {
- if ($noReturning) $this->BytesString .= pack("C", $value);
- else return pack("C", $value);
- }
- function writeBytes($value) {
- $this->BytesString .= $value;
- }
- function writeInt($value) {
- $this->BytesString .= pack('N', $value);
- }
- function writeShort($value) {
- $this->BytesString .= pack('n', $value);
- }
- function writeUTF($value) {
- $valueSize = strlen($value);
- $this->writeShort($valueSize);
- $this->writeUTFBytes($value);
- }
- function writeUTFBytes($value) {
- $this->BytesString .= $value;
- }
- function length() {
- return strlen($this->BytesString);
- }
- function toString() {
- return $this->BytesString;
- }
- function toPack() {
- $value = pack('N', strlen($this->BytesString)+4);
- return $value.$this->BytesString;
- }
- function getSize() {
- $value = unpack('N', substr($this->BytesString, 0, 4));
- return $value[1];
- }
- function readBy($Pos) {
- $this->BytesString = substr($this->BytesString, $Pos);
- return $this->BytesString;
- }
- function loc($byte) {
- $loc = substr($this->BytesString, 0, $byte);
- $this->BytesString = substr($this->BytesString, $byte);
- return unpack('C', $loc);
- }
- function readInt() {
- $size = unpack('N', substr($this->BytesString, 0, 4)); $size = $size[1];
- $this->BytesString = substr($this->BytesString, 4);
- return $size;
- }
- function readUTF() {
- $size = unpack('n', substr($this->BytesString, 0, 2)); $size = $size[1];
- $string = substr($this->BytesString, 2, $size);
- $this->BytesString = substr($this->BytesString, $size + 2);
- return $string;
- }
- function readShort() {
- $size = unpack('n', substr($this->BytesString, 0, 2)); $size = $size[1];
- $this->BytesString = substr($this->BytesString, 2);
- return $size;
- }
- function readBoolean() {
- $loc = unpack('C', substr($this->BytesString, 0, 1)); $loc = $loc[1];
- $this->BytesString = substr($this->BytesString, 1);
- if ($loc == 1) return True;
- else return False;
- }
- function readByte() {
- $byte = unpack('C', substr($this->BytesString, 0, 1)); $byte = $byte[1];
- $this->BytesString = substr($this->BytesString, 1);
- return $byte;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement