POT
POT
POT
Main menu

Download

Forum

SVN

Class: OTS_Buffer

Source Location: /classes/OTS_Buffer.php

Class OTS_Buffer

Class Overview

Binary buffer container.

Binary buffer container. This is generic class for classes that uses buffer-baser read-write operations (it can also emulate C-like pointers).

Note that unlike NetworkMessage class from OTServ C++ source code, in this one reading and writing positions are separated so you can pararelly read and write it's content like for example using object of this class as stack.

Located in /classes/OTS_Buffer.php [line 38]



		
				Author(s):
		
API Tags:
Property:  string $buffer: Properties binary string.
Property:  int $char: getChar()/putChar() method wrapper.
Property:  int $short: getShort()/putShort() method wrapper.
Property:  int $long: getLong()/putLong() method wrapper.
Property:  string $string: getString(false)/putString(, true) call wrapper.
Property:  int $pos: getPos()/setPos() method wrapper.
Property-read:  bool $valid: isValid() method wrapper.
Property-read:  int $size: getSize() method wrapper.

Information Tags:
Version:  0.1.3
Version:  0.1.2
Since:  0.1.2

Properties

Methods

[ Top ]
Descendants
Child Class Description
OTS_FileNode OTServ binary file node representation.

[ Top ]
Property Summary
string   $buffer   Node properties stream.
int   $pos   Properties stream pointer.

[ Top ]
Method Summary
static void   __set_state()   Magic PHP5 method.
OTS_Buffer   __construct()   Initializes new buffered reader.
void   check()   Checks stream end state.
string   getBuffer()   Returs properties stream.
int   getChar()   Returns single byte.
int   getLong()   Returns quater byte.
int   getPos()   Returns current read position.
int   getShort()   Returns double byte.
int   getSize()   Returns buffer size.
string   getString()   Returns string from buffer.
bool   isValid()   Checks if there is anything left in stream.
void   putChar()   Appends single byte to buffer.
void   putLong()   Appends quater byte to buffer.
void   putShort()   Appends double byte to buffer.
void   putString()   Appends string to buffer.
void   reset()   Empties buffer.
void   setBuffer()   Sets properties stream.
void   setPos()   Seeks current reading position.
void   skip()   Skips given amount of bytes.
void   __clone()   Resets pointer of cloned object.
mixed   __get()   Magic PHP5 method.
void   __set()   Magic PHP5 method.
string   __toString()   Returns string representation of buffer object.

[ Top ]
Properties
string   $buffer [line 45]

Node properties stream.

Node properties stream.

API Tags:
Access:  protected

Information Tags:
Version:  0.1.2
Since:  0.1.2

[ Top ]
int   $pos [line 51]

Properties stream pointer.

Properties stream pointer.

API Tags:
Access:  protected

Information Tags:
Version:  0.1.2
Since:  0.1.2

[ Top ]
Methods
static method __set_state  [line 73]

  static void __set_state( array $properties  )

Magic PHP5 method.

Magic PHP5 method. Allows object importing from var_export().

Parameters:
array   $properties:  List of object properties.

API Tags:
Access:  public

Information Tags:
Version:  0.1.2
Since:  0.1.2

[ Top ]
Constructor __construct  [line 58]

  OTS_Buffer __construct( [string $buffer = '']  )

Initializes new buffered reader.

Initializes new buffered reader.

Parameters:
string   $buffer:  Buffer content.

API Tags:
Access:  public

Information Tags:
Version:  0.1.2
Since:  0.1.2

[ Top ]
check  [line 123]

  void check( [int $size = 1]  )

Checks stream end state.

Checks stream end state.

Parameters:
int   $size:  Amount of bytes that are going to be read.

API Tags:
Access:  protected

Information Tags:
Version:  0.1.2
Throws:  E_OTS_OutOfBuffer When there is read attemp after end of stream.
Since:  0.1.2

[ Top ]
getBuffer  [line 91]

  string getBuffer( )

Returs properties stream.

Returs properties stream.


API Tags:
Return:  Properties stream.
Access:  public

Information Tags:
Version:  0.1.2
Since:  0.1.2

[ Top ]
getChar  [line 137]

  int getChar( )

Returns single byte.

Returns single byte.


API Tags:
Return:  Byte (char) value.
Access:  public

Information Tags:
Version:  0.1.2
Throws:  E_OTS_OutOfBuffer When there is read attemp after end of stream.
Since:  0.1.2

[ Top ]
getLong  [line 189]

  int getLong( )

Returns quater byte.

Returns quater byte.


API Tags:
Return:  Double word (long) value.
Access:  public

Information Tags:
Version:  0.1.2
Throws:  E_OTS_OutOfBuffer When there is read attemp after end of stream.
Since:  0.1.2

[ Top ]
getPos  [line 267]

  int getPos( )

Returns current read position.

Returns current read position.


API Tags:
Return:  Read position.
Access:  public

Information Tags:
Version:  0.1.2
Since:  0.1.2

[ Top ]
getShort  [line 163]

  int getShort( )

Returns double byte.

Returns double byte.


API Tags:
Return:  Word (short) value.
Access:  public

Information Tags:
Version:  0.1.2
Throws:  E_OTS_OutOfBuffer When there is read attemp after end of stream.
Since:  0.1.2

[ Top ]
getSize  [line 287]

  int getSize( )

Returns buffer size.

Returns buffer size.


API Tags:
Return:  Buffer length.
Access:  public

Information Tags:
Version:  0.1.2
Since:  0.1.2

[ Top ]
getString  [line 220]

  string getString( [int|bool $length = false]  )

Returns string from buffer.

Returns string from buffer. If length is not given then treats first short value from current buffer as string length.

Parameters:
int|bool   $length:  String length.

API Tags:
Return:  First substring.
Access:  public

Information Tags:
Version:  0.1.2
Throws:  E_OTS_OutOfBuffer When there is read attemp after end of stream.
Since:  0.1.2

[ Top ]
isValid  [line 112]

  bool isValid( )

Checks if there is anything left in stream.

Checks if there is anything left in stream.


API Tags:
Return:  False if pointer is at the end of stream.
Access:  public

Information Tags:
Version:  0.1.2
Since:  0.1.2

[ Top ]
putChar  [line 152]

  void putChar( int $char  )

Appends single byte to buffer.

Appends single byte to buffer.

Parameters:
int   $char:  Byte (char) value.

API Tags:
Access:  public

Information Tags:
Version:  0.1.2
Since:  0.1.2

[ Top ]
putLong  [line 204]

  void putLong( int $long  )

Appends quater byte to buffer.

Appends quater byte to buffer.

Parameters:
int   $long:  Double word (long) value.

API Tags:
Access:  public

Information Tags:
Version:  0.1.2
Since:  0.1.2

[ Top ]
putShort  [line 178]

  void putShort( int $short  )

Appends double byte to buffer.

Appends double byte to buffer.

Parameters:
int   $short:  Word (short) value.

API Tags:
Access:  public

Information Tags:
Version:  0.1.2
Since:  0.1.2

[ Top ]
putString  [line 243]

  void putString( string $string, [bool $dynamic = true]  )

Appends string to buffer.

Appends string to buffer.

Parameters:
string   $string:  Binary length.
bool   $dynamic:  Whether if string length is fixed or not (if it is dynamic then length will be inserted as short before string chunk).

API Tags:
Access:  public

Information Tags:
Version:  0.1.2
Since:  0.1.2

[ Top ]
reset  [line 257]

  void reset( )

Empties buffer.

Empties buffer.


API Tags:
Access:  public

Information Tags:
Version:  0.1.2
Since:  0.1.2

[ Top ]
setBuffer  [line 101]

  void setBuffer( string $buffer  )

Sets properties stream.

Sets properties stream.

Parameters:
string   $buffer:  Properties stream.

API Tags:
Access:  public

Information Tags:
Version:  0.1.2
Since:  0.1.2

[ Top ]
setPos  [line 277]

  void setPos( int $pos  )

Seeks current reading position.

Seeks current reading position.

Parameters:
int   $pos:  Read position.

API Tags:
Access:  public

Information Tags:
Version:  0.1.2
Since:  0.1.2

[ Top ]
skip  [line 298]

  void skip( int $n  )

Skips given amount of bytes.

Skips given amount of bytes.

Parameters:
int   $n:  Bytes to skip.

API Tags:
Access:  public

Information Tags:
Version:  0.1.2
Throws:  E_OTS_OutOfBuffer When there is read attemp after end of stream.
Since:  0.1.2

[ Top ]
__clone  [line 413]

  void __clone( )

Resets pointer of cloned object.

Resets pointer of cloned object.


API Tags:
Access:  public

Information Tags:
Version:  0.1.2
Since:  0.1.2

Redefined in descendants as:

[ Top ]
__get  [line 312]

  mixed __get( string $name  )

Magic PHP5 method.

Magic PHP5 method.

Parameters:
string   $name:  Property name.

API Tags:
Return:  Property value.
Access:  public

Information Tags:
Version:  0.1.2
Throws:  OutOfBoundsException For non-supported properties.
Throws:  E_OTS_OutOfBuffer When there is read attemp after end of stream.
Since:  0.1.2

Redefined in descendants as:

[ Top ]
__set  [line 361]

  void __set( string $name, mixed $value  )

Magic PHP5 method.

Magic PHP5 method.

Parameters:
string   $name:  Property name.
mixed   $value:  Property value.

API Tags:
Access:  public

Information Tags:
Version:  0.1.3
Version:  0.1.2
Throws:  OutOfBoundsException For non-supported properties.
Since:  0.1.2

Redefined in descendants as:

[ Top ]
__toString  [line 405]

  string __toString( )

Returns string representation of buffer object.

Returns string representation of buffer object.


API Tags:
Return:  Object's buffer.
Access:  public

Information Tags:
Version:  0.1.2
Since:  0.1.2

[ Top ]