PHP Class PHPDaemon\Utils\Binary

Author: Vasily Zorin ([email protected])
Inheritance: use trait PHPDaemon\Traits\ClassWatchdog, use trait PHPDaemon\Traits\StaticObjectWatchdog
Datei anzeigen Open project: kakserpom/phpdaemon Class Usage Examples

Public Methods

Method Description
LV ( string $str, integer $len = 1, boolean $lrev = false ) : string Build length-value binary snippet
LVnull ( string $str ) : string Build nul-terminated string, with 2-byte of length
b2i ( string $str, boolean $l = false ) : integer Convert bytes into integer
bitmap2bytes ( string $bitmap, integer $check_len ) : string | false Convert bitmap into bytes
byte ( integer $int ) : string Build byte
bytes2int ( string $str, boolean $l = false ) : integer Convert bytes into integer
dword ( integer $int ) : string Build double word (4 bytes) big-endian
dwordl ( integer $int ) : string Build double word (4 bytes) little endian
flags2bitarray ( array $flags, integer $len = 4 ) : string Convert array of flags into bit array
getByte ( &$p ) : integer Parse byte, and remove it
getChar ( &$p ) : string Get single-byte character
getDWord ( &$p, boolean $l = false ) : integer Get double word (4 bytes)
getLV ( &$p, integer $l = 1, boolean $nul = false, boolean $lrev = false ) : string Parse length-value structure
getQword ( &$p, boolean $l = false ) : integer Parse quadro word (8 bytes)
getStrQWord ( &$p, boolean $l = false ) : string Get quadro word (8 bytes)
getStrWord ( &$p, boolean $l = false ) : string Get word (2 bytes)
getString ( &$str ) : string Parse nul-terminated string
getWord ( &$p, boolean $l = false ) : integer Parse word (2 bytes)
getbitmap ( integer $byte ) : string Get bitmap
i2b ( integer $len, integer $int, boolean $l = false ) : string Converts integer to binary string
int2bytes ( integer $len, integer $int, boolean $l = false ) : string Converts integer to binary string
labels ( string $q ) : string Build structure of labels
parseLabels ( &$data, string $orig = null ) : string Parse structure of labels
qword ( integer $int ) : string Build quadro word (8 bytes) big endian
qwordl ( integer $int ) : string Build quadro word (8 bytes) little endian
word ( integer $int ) : string Build word (2 bytes) big-endian
wordl ( integer $int ) : string Build word (2 bytes) little-endian

Method Details

LV() public static method

Build length-value binary snippet
public static LV ( string $str, integer $len = 1, boolean $lrev = false ) : string
$str string Data
$len integer Number of bytes to encode length. Default is 1
$lrev boolean Reverse?
return string

LVnull() public static method

Build nul-terminated string, with 2-byte of length
public static LVnull ( string $str ) : string
$str string Data
return string

b2i() public static method

Convert bytes into integer
public static b2i ( string $str, boolean $l = false ) : integer
$str string Bytes
$l boolean Little endian? Default is false
return integer

bitmap2bytes() public static method

Convert bitmap into bytes
public static bitmap2bytes ( string $bitmap, integer $check_len ) : string | false
$bitmap string Bitmap
$check_len integer Check length?
return string | false

byte() public static method

Build byte
public static byte ( integer $int ) : string
$int integer Byte number
return string

bytes2int() public static method

Convert bytes into integer
public static bytes2int ( string $str, boolean $l = false ) : integer
$str string Bytes
$l boolean Little endian? Default is false
return integer

dword() public static method

Build double word (4 bytes) big-endian
public static dword ( integer $int ) : string
$int integer Integer
return string

dwordl() public static method

Build double word (4 bytes) little endian
public static dwordl ( integer $int ) : string
$int integer Integer
return string

flags2bitarray() public static method

Convert array of flags into bit array
public static flags2bitarray ( array $flags, integer $len = 4 ) : string
$flags array Flags
$len integer Length. Default is 4
return string

getByte() public static method

Parse byte, and remove it
public static getByte ( &$p ) : integer
return integer

getChar() public static method

Get single-byte character
public static getChar ( &$p ) : string
return string

getDWord() public static method

Get double word (4 bytes)
public static getDWord ( &$p, boolean $l = false ) : integer
$l boolean Little endian?
return integer

getLV() public static method

Parse length-value structure
public static getLV ( &$p, integer $l = 1, boolean $nul = false, boolean $lrev = false ) : string
$l integer Number of length bytes
$nul boolean Nul-terminated? Default is false
$lrev boolean Length is little endian?
return string

getQword() public static method

Parse quadro word (8 bytes)
public static getQword ( &$p, boolean $l = false ) : integer
$l boolean Little endian?
return integer

getStrQWord() public static method

Get quadro word (8 bytes)
public static getStrQWord ( &$p, boolean $l = false ) : string
$l boolean Little endian?
return string

getStrWord() public static method

Get word (2 bytes)
public static getStrWord ( &$p, boolean $l = false ) : string
$l boolean Little endian?
return string

getString() public static method

Parse nul-terminated string
public static getString ( &$str ) : string
return string

getWord() public static method

Parse word (2 bytes)
public static getWord ( &$p, boolean $l = false ) : integer
$l boolean Little endian?
return integer

getbitmap() public static method

Get bitmap
public static getbitmap ( integer $byte ) : string
$byte integer Byte
return string

i2b() public static method

Converts integer to binary string
public static i2b ( integer $len, integer $int, boolean $l = false ) : string
$len integer Length
$int integer Integer
$l boolean Optional. Little endian. Default value - false
return string Resulting binary string

int2bytes() public static method

Converts integer to binary string
public static int2bytes ( integer $len, integer $int, boolean $l = false ) : string
$len integer Length
$int integer Integer
$l boolean Optional. Little endian. Default value - false
return string Resulting binary string

labels() public static method

Build structure of labels
public static labels ( string $q ) : string
$q string Dot-separated labels list
return string

parseLabels() public static method

Parse structure of labels
public static parseLabels ( &$data, string $orig = null ) : string
$orig string Original packet
return string Dot-separated labels list

qword() public static method

Build quadro word (8 bytes) big endian
public static qword ( integer $int ) : string
$int integer Integer
return string

qwordl() public static method

Build quadro word (8 bytes) little endian
public static qwordl ( integer $int ) : string
$int integer Integer
return string

word() public static method

Build word (2 bytes) big-endian
public static word ( integer $int ) : string
$int integer Integer
return string

wordl() public static method

Build word (2 bytes) little-endian
public static wordl ( integer $int ) : string
$int integer Integer
return string