Пример #1
0
 public function writeObject($className, $objectFields, IProtocolFormatter $writer)
 {
     if (is_null($className)) {
         $writer->beginWriteObjectMap(count($objectFields));
     } else {
         $writer->beginWriteNamedObject($className, count($objectFields));
     }
     $keys = array_keys($objectFields);
     $fieldCount = count($objectFields);
     for ($i = 0; $i < $fieldCount; $i++) {
         $fieldName = $keys[$i];
         $writer->writeFieldName($fieldName);
         $writer->beginWriteFieldValue();
         try {
             MessageWriter::writeObject($objectFields[$fieldName], $writer);
         } catch (Exception $exception) {
             if (LOGGING) {
                 Log::logException(LoggingConstants::ERROR, "unable to serialize object's field " . $fieldName, $exception);
             }
         }
         $writer->endWriteFieldValue();
     }
     if (is_null($className)) {
         $writer->endWriteObjectMap();
     } else {
         $writer->endWriteNamedObject();
     }
 }
 function writeObject($className, $objectFields, IProtocolFormatter $writer)
 {
     unset($objectFields["_orbclassname"]);
     /*V3ReferenceCache*/
     $cache = $writer->GetReferenceCache();
     /*String*/
     $traitsClassId = $className;
     if ($traitsClassId == null) {
         $str = "";
         $keys = array_keys($objectFields);
         $fieldCount = count($objectFields);
         for ($i = 0; $i < $fieldCount; $i++) {
             $str .= $keys[$i] . "-";
         }
         $traitsClassId = $str;
     }
     if ($cache->HasTraits($traitsClassId)) {
         /*MemoryStream*/
         $stream = "";
         /*int*/
         $traitId = $cache->GetTraitsId($traitsClassId);
         $writer->directWriteBytes(Datatypes::OBJECT_DATATYPE_V3);
         $writer->directWriteVarInt(0x1 | $traitId << 2);
     } else {
         $writer->beginWriteNamedObject($className, count($objectFields));
         if ($className == null) {
             $cache->AddToTraitsCache($traitsClassId);
         }
         $keys = array_keys($objectFields);
         $fieldCount = count($objectFields);
         for ($i = 0; $i < $fieldCount; $i++) {
             $fieldName = $keys[$i];
             $writer->writeFieldName($fieldName);
         }
     }
     $keys = array_keys($objectFields);
     $fieldsCount = count($objectFields);
     for ($i = 0; $i < $fieldsCount; $i++) {
         $fieldName = $keys[$i];
         $writer->beginWriteFieldValue();
         try {
             MessageWriter::writeObject($objectFields[$fieldName], $writer);
         } catch (Exception $exception) {
             if (LOGGING) {
                 Log::log(LoggingConstants::ERROR, "unable to serialize object's field " . $fieldName, $exception);
             }
         }
         $writer->endWriteFieldValue();
     }
     $writer->endWriteNamedObject();
 }