Overview  Package  Tree HessianPHP

HessianPHP.Protocol

Class ByteUtils

HessianPHP.Protocol.ByteUtils

class ByteUtils

This is a helper class designed to work with byte conversion and representation of numbers

Author:
Manolo Gómez
Version:
1.0

Field Summary
Method Summary
public stringgetIntBytes

Generates big endian byte representation of a number with a defined precision, 16 or 64 bits for example, default 32 bits.
This function is equivalent to do the transformation by hand with a fixed bit precision, as in (for a 32 bit representation):

$b32 = $value >> 24;
$b24 = ($value >> 16) & 0x000000FF;
$b16 = ($value >> 8) & 0x000000FF;
$b8 = $value & 0x000000FF;
$bytes .= pack('c',$b32);
$bytes .= pack('c',$b24);
$bytes .= pack('c',$b16);
$bytes .= pack('c',$b8);

public stringgetFloatBytes

Returns a string with the byte representation of a IEEE 754 double in 64 bit precision.

public booleanisLittleEndian

Test if this machine is a little endian architecture
Based in code from Open Sound Control (OSC) Client Library for PHP
Author: Andy W Schmeder <andy@a2hd.com>
Copyright 2003

public stringorderedByteString

Returns a sequence of bytes in big endian order, it orders the string depending on machine architecture (big endian or little endian).
Based in code from Open Sound Control (OSC) Client Library for PHP
Author: Andy W Schmeder <andy@a2hd.com>
Copyright 2003

Method Detail

getIntBytes()

public string getIntBytes(long number,
                          int precision = 32)

Generates big endian byte representation of a number with a defined precision, 16 or 64 bits for example, default 32 bits.
This function is equivalent to do the transformation by hand with a fixed bit precision, as in (for a 32 bit representation):

$b32 = $value >> 24;
$b24 = ($value >> 16) & 0x000000FF;
$b16 = ($value >> 8) & 0x000000FF;
$b8 = $value & 0x000000FF;
$bytes .= pack('c',$b32);
$bytes .= pack('c',$b24);
$bytes .= pack('c',$b16);
$bytes .= pack('c',$b8);

Parameters:
number - number to be transformed
precision - precision
Returns:
byte representation of long number

getFloatBytes()

public string getFloatBytes(double number)

Returns a string with the byte representation of a IEEE 754 double in 64 bit precision.

Works fine between PHP clients and servers but it uses a machine dependent byte packing representation (pack format "d"). WARNING: Due to incompatible double formats among different machines, this function is not guaranteed to return the number with extreme accuracy, specially with periodic fractions such as 1.3333... Take this in account.

Parameters:
number - number to be transformed
Returns:
byte representation

isLittleEndian()

public boolean isLittleEndian()

Test if this machine is a little endian architecture
Based in code from Open Sound Control (OSC) Client Library for PHP
Author: Andy W Schmeder <andy@a2hd.com>
Copyright 2003

Returns:
is little endian?

orderedByteString()

public string orderedByteString(string string)

Returns a sequence of bytes in big endian order, it orders the string depending on machine architecture (big endian or little endian).
Based in code from Open Sound Control (OSC) Client Library for PHP
Author: Andy W Schmeder <andy@a2hd.com>
Copyright 2003

Parameters:
string - sequence of bytes to order
Returns:
big endian ordered sequence of bytes

Overview  Package  Tree HessianPHP