public static function init() { self::$classCRC32Cache = new IdentityHashMap(); self::$CLASS_TO_SERIALIZER_INSTANCE = new IdentityHashMap(); self::$NO_SUCH_SERIALIZER = new SerializabilityUtilEx_NoSuchSerializer(); self::$SERIALIZED_PRIMITIVE_TYPE_NAMES = new HashMap(); self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES = new HashSet(); self::$SERIALIZED_PRIMITIVE_TYPE_NAMES->put(Boolean::typeClass()->getFullName(), "Z"); self::$SERIALIZED_PRIMITIVE_TYPE_NAMES->put(Byte::typeClass()->getFullName(), "B"); self::$SERIALIZED_PRIMITIVE_TYPE_NAMES->put(Character::typeClass()->getFullName(), "C"); self::$SERIALIZED_PRIMITIVE_TYPE_NAMES->put(Double::typeClass()->getFullName(), "D"); self::$SERIALIZED_PRIMITIVE_TYPE_NAMES->put(Float::typeClass()->getFullName(), "F"); self::$SERIALIZED_PRIMITIVE_TYPE_NAMES->put(Integer::typeClass()->getFullName(), "I"); self::$SERIALIZED_PRIMITIVE_TYPE_NAMES->put(Long::typeClass()->getFullName(), "J"); self::$SERIALIZED_PRIMITIVE_TYPE_NAMES->put(Short::typeClass()->getFullName(), "S"); self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Boolean::clazz()); self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Byte::clazz()); self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Character::clazz()); self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Double::clazz()); //TODO Exception class //self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Exception::clazz()); self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Float::clazz()); self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Integer::clazz()); self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Long::clazz()); self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Object::clazz()); self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Short::clazz()); self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(String::clazz()); self::$TYPES_WHOSE_IMPLEMENTATION_IS_EXCLUDED_FROM_SIGNATURES->add(Classes::classOf('Throwable')); }
private function validateTypeVersions(Clazz $instanceClass, SerializedInstanceReference $serializedInstRef) { $clientTypeSignature = $serializedInstRef->getSignature(); if (empty($clientTypeSignature)) { throw new SerializationException('Missin type signature for "' . $instanceClass->getFullName() . '"'); } $serverTypeSignature = SerializabilityUtilEx::getSerializationSignature($instanceClass, $this->serializationPolicy); if ($clientTypeSignature !== $serverTypeSignature) { throw new SerializationException('Invalid type signature for "' . $instanceClass->getFullName() . '"'); } }
private function serializeImpl($instance, Clazz $instanceClass) { assert(!is_null($instance)); $customSerializer = SerializabilityUtilEx::hasCustomFieldSerializer($instanceClass); if (!is_null($customSerializer)) { // Use custom field serializer $customFieldSerializer = SerializabilityUtilEx::loadCustomFieldSerializer($customSerializer); if (is_null($customFieldSerializer)) { $this->serializeWithCustomSerializer($customSerializer, $instance, $instanceClass); } else { $customFieldSerializer->serializeInstance($this, $instance); } } else { if ($instanceClass->isArray()) { $this->serializeArray($instanceClass, $instance); } else { if ($instanceClass->isEnum()) { $this->writeInt($instance); } else { // Regular class instance $this->serializeClass($instance, $instanceClass); } } } }