diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-13 09:50:10 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-13 09:50:10 +0100 |
commit | 9df186180f25313d2182ef7a0bb807875888892c (patch) | |
tree | 723d667aef52ef4e57ea252bb780145f651490aa /src | |
parent | 01fa31d24d6669ee30ccb897a0a7f438bcbe59f0 (diff) |
added serializable class (but not yet implemented it)
Diffstat (limited to 'src')
-rw-r--r-- | src/classbase.cpp | 41 | ||||
-rw-r--r-- | src/includes.h | 1 |
2 files changed, 40 insertions, 2 deletions
diff --git a/src/classbase.cpp b/src/classbase.cpp index 03c5512..0e39ae1 100644 --- a/src/classbase.cpp +++ b/src/classbase.cpp @@ -1004,6 +1004,36 @@ zend_object_iterator *ClassBase::getIterator(zend_class_entry *entry, zval *obje } /** + * Method that is called to serialize an object + * @param object The object to be serialized + * @param buffer Buffer in which to store the data + * @param buf_len Size of the bufffer + * @param data ?? + * @return int + */ +int ClassBase::serialize(zval *object, unsigned char **buffer, zend_uint *buf_len, zend_serialize_data *data) +{ + std::cout << "serialize is called" << std::endl; + + return SUCCESS; +} + +/** + * Method that is called to unserialize an object + * @param object The object to be unserialized + * @param entry The class entry to which is belongs + * @param buffer Buffer holding the unserialized data + * @param data All the unserialize data + * @return int + */ +int ClassBase::unserialize(zval **object, zend_class_entry *entry, const unsigned char *buffer, zend_uint buf_len, zend_unserialize_data *data) +{ + std::cout << "unserialize is called" << std::endl; + + return SUCCESS; +} + +/** * Destructor */ ClassBase::~ClassBase() @@ -1081,10 +1111,17 @@ void ClassBase::initialize(const std::string &prefix) // we need a special constructor entry.create_object = &ClassBase::createObject; - // and a special function for retrieving the iterator (but only if this is - // a traversable class) + // for traversable classes we install a special method to get the iterator if (traversable()) entry.get_iterator = &ClassBase::getIterator; + // for serializable classes, we install callbacks for serializing and unserializing + if (serializable()) + { + // add handlers to serialize and unserialize + entry.serialize = &ClassBase::serialize; + entry.unserialize = &ClassBase::unserialize; + } + // register the class _entry = zend_register_internal_class(&entry TSRMLS_CC); diff --git a/src/includes.h b/src/includes.h index 021c943..5f273bd 100644 --- a/src/includes.h +++ b/src/includes.h @@ -60,6 +60,7 @@ #include "../include/base.h" #include "../include/countable.h" #include "../include/arrayaccess.h" +#include "../include/serializable.h" #include "../include/iterator.h" #include "../include/traversable.h" #include "../include/classtype.h" |