Beispiel #1
0
 function writeValue()
 {
     $args = func_get_args();
     $val = $args[0];
     $type = $args[1];
     if (count($args) >= 3) {
         $implicit = $args[2];
     } else {
         $implicit = FALSE;
     }
     $typeByte = new StringBuffer();
     if ($type === NATIVEOBJECT) {
         $typeByte->writeUInt8(OBJECTV, 0);
     } else {
         $typeByte->writeUInt8($type, 0);
     }
     if ($type === UNDEFINED || $type === TRUEVAL || $type === FALSEVAL || $type === NULLVAL || $type === NANV || $type === MINUSINFINITY || $type === INFINITY) {
         $this->append($typeByte);
         return 1;
     }
     $byteCount = 0;
     if (!$implicit) {
         $this->append($typeByte);
         $byteCount++;
     }
     if ($type === STRINGV) {
         if (count($this->stringIndex) === 0) {
             $this->writeString($val);
             return 1 + $byteCount + strlen($val);
         }
         $this->writeValue(array_search($val, $this->stringIndex), $this->stringIndexType, TRUE);
         return $byteCount + 1;
     } else {
         if ($type === (SIGNED | CHAR)) {
             $bytes = new StringBuffer();
             $bytes->writeInt8($val, 0);
             $this->append($bytes);
             return $byteCount + 1;
         } else {
             if ($type === CHAR) {
                 $bytes = new StringBuffer();
                 $bytes->writeUInt8($val, 0);
                 $this->append($bytes);
                 return $byteCount + 1;
             } else {
                 if ($type === (SIGNED | SHORT)) {
                     $bytes = new StringBuffer();
                     $bytes->writeInt16LE($val, 0);
                     $this->append($bytes);
                     return 2 + $byteCount;
                 } else {
                     if ($type === SHORT) {
                         $bytes = new StringBuffer();
                         $bytes->writeUInt16LE($val, 0);
                         $this->append($bytes);
                         return 2 + $byteCount;
                     } else {
                         if ($type === (SIGNED | INTV)) {
                             $bytes = new StringBuffer();
                             $bytes->writeInt32LE($val, 0);
                             $this->append($bytes);
                             return 4 + $byteCount;
                         } else {
                             if ($type === INTV) {
                                 $bytes = new StringBuffer();
                                 $bytes->writeUInt32LE($val, 0);
                                 $this->append($bytes);
                                 return 4 + $byteCount;
                             } else {
                                 if ($type === FLOATV) {
                                     $bytes = new StringBuffer();
                                     $bytes->writeFloatLE($val, 0);
                                     $this->append($bytes);
                                     return 4 + $byteCount;
                                 } else {
                                     if ($type === DOUBLEV) {
                                         $bytes = new StringBuffer();
                                         $bytes->writeDoubleLE($val, 0);
                                         $this->append($bytes);
                                         return 8 + $byteCount;
                                     } else {
                                         if ($type === VARARRAY) {
                                             $this->writeValue(count($val), type_check(count($val)));
                                             foreach ($val as $v) {
                                                 $this->writeValue($v, type_check($v));
                                             }
                                             return;
                                         } else {
                                             if ($type === OBJECTV) {
                                                 $index = match_layout($val, $this->stringIndex, $this->OLI);
                                                 $this->writeValue($index, $this->OLItype, TRUE);
                                                 for ($i = 0; $i < count($this->OLI[$index]); ++$i) {
                                                     $tmp = $val[$this->stringIndex[$this->OLI[$index][$i]]];
                                                     $this->writeValue($tmp, type_check($tmp));
                                                 }
                                                 return;
                                             } else {
                                                 if ($type === NATIVEOBJECT) {
                                                     $index = match_layout($val, $this->stringIndex, $this->OLI);
                                                     $this->writeValue($index, $this->OLItype, true);
                                                     for ($i = 0; $i < count($this->OLI[$index]); ++$i) {
                                                         $tmp = $val->{$this->stringIndex[$this->OLI[$index][$i]]};
                                                         $this->writeValue($tmp, type_check($tmp));
                                                     }
                                                     return;
                                                 } else {
                                                     if ($type === BUFFER) {
                                                         $len = strlen($val->buffer);
                                                         $this->writeValue($len, type_check($len));
                                                         for ($i = 0; $i < $len; ++$i) {
                                                             $this->writeValue(ord($val->buffer[$i]), CHAR, true);
                                                         }
                                                         return $byteCount + strlen($val->buffer);
                                                     } else {
                                                         if ($type === REGEXP) {
                                                             $this->writeString($val->pattern);
                                                             $this->writeString($val->modifier);
                                                             return $byteCount + 2 + strlen($val->pattern) + strlen($val->modifier);
                                                         } else {
                                                             if ($type === DATEVAL) {
                                                                 $this->writeValue($val->timestamp, DOUBLEV, true);
                                                                 return $byteCount + 8;
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }