Ejemplo n.º 1
0
 /**
  * Get the encoded property value as a binary blob.
  *
  * @param string $value
  * @param bool $string
  * @return string
  */
 protected function encodePropValue($value, $string = false)
 {
     // An int must be properly padded. (then split and reversed). For a string, we just split the chars. This seems
     // to be the easiest way to handle UTF-8 characters instead of trying to work with their hex values.
     $chars = $string ? MBString::str_split($value) : array_reverse(str_split($this->dec2hex($value, 8), 2));
     $encoded = '';
     foreach ($chars as $char) {
         // Get the bits for the char. Using this method to ensure it is fully padded.
         $bits = sprintf('%08b', $string ? MBString::ord($char) : hexdec($char));
         $nibbleX = substr($bits, 0, 4);
         $nibbleY = substr($bits, 4, 4);
         // Construct the value with the header, high nibble, then low nibble.
         $value = self::NIBBLE_HEADER;
         foreach (['Y' => $nibbleY, 'X' => $nibbleX] as $nibbleType => $nibble) {
             $value .= $this->getNibbleWithControl($nibbleType, $nibble);
         }
         // Convert it back to a binary bit stream
         foreach ([0, 8, 16] as $start) {
             $encoded .= $this->packBitString(substr($value, $start, 8), 8);
         }
     }
     return $encoded;
 }
Ejemplo n.º 2
0
 /**
  * Decode and parse the binary dial-in data from the userParameters attribute (the data between 44 and 96 bytes).
  * 
  * @param string $binary
  */
 protected function decode($binary)
 {
     $hex = bin2hex($binary);
     $this->signature = MBString::chr(hexdec(substr($hex, 0, 2)));
     $this->userPrivilege = hexdec(substr($hex, 2, 2));
     $this->callbackPhoneNumber = substr($hex, 4, 48);
 }