/** * * @param Object $instance * @throws SerializationException */ public function writeObject($instance, MappedClass $type = null) { if ($instance === null) { // write a null string $this->writeString(null); return; } /*int*/ $objIndex = $this->getIndexForObject($instance); if ($objIndex >= 0) { // We've already encoded this object, make a backref // Transform 0-based to negative 1-based $this->writeInt(-($objIndex + 1)); return; } $this->saveIndexForObject($instance); // Serialize the type signature /*String*/ // $typeSignature = $this->getObjectTypeSignature($instance); // TODO: implement calculation of signature if ($type === null) { $type = GWTPHPContext::getMappedClassLoader()->findMappedClassByObject($instance); } $typeSignature = $type->getSignature() . '/' . $type->getCRC(); //$typeSignature = 'java.lang.Integer/3438268394';//$type->getCRC(); $this->writeString($typeSignature); // Now serialize the rest of the object $this->serialize($instance, $typeSignature, $type); }
/** * @param Object $value * @param MappedClass $type * @throws SerializationException */ public function serializeValue($value, MappedClass $type = null) { if ($type === null) { $type = GWTPHPContext::getMappedClassLoader()->findMappedClassByObject($value); } switch ($type->getSignature()) { case TypeSignatures::$BOOLEAN: $this->writeBoolean((bool) $value); break; case TypeSignatures::$BYTE: $this->writeByte($value); break; case TypeSignatures::$CHAR: $this->writeChar($value); break; case TypeSignatures::$DOUBLE: $this->writeDouble($value); break; case TypeSignatures::$FLOAT: $this->writeFloat($value); break; case TypeSignatures::$INT: $this->writeInt($value); break; case TypeSignatures::$LONG: $this->writeLong($value); break; case TypeSignatures::$SHORT: $this->writeShort($value); break; case "java.lang.String": $this->writeString($value); break; default: $this->writeObject($value, $type); } }