diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-13 10:25:21 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-13 10:25:21 +0100 |
commit | 3bb0e31416994b0a36b784c8278b1c5f33999b1d (patch) | |
tree | 994c27d37b4580457fad429590f012b009e364ac /src | |
parent | 9df186180f25313d2182ef7a0bb807875888892c (diff) |
finalized implementation of serialize/unserialize methods
Diffstat (limited to 'src')
-rw-r--r-- | src/classbase.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/classbase.cpp b/src/classbase.cpp index 0e39ae1..e922855 100644 --- a/src/classbase.cpp +++ b/src/classbase.cpp @@ -1013,8 +1013,19 @@ zend_object_iterator *ClassBase::getIterator(zend_class_entry *entry, zval *obje */ int ClassBase::serialize(zval *object, unsigned char **buffer, zend_uint *buf_len, zend_serialize_data *data) { - std::cout << "serialize is called" << std::endl; + // get the serializable object + Serializable *serializable = dynamic_cast<Serializable*>(cpp_object(object)); + // call the serialize method on the object + auto value = serializable->serialize(); + + // allocate the buffer, and copy the data into it (the zend engine will + // (hopefully) clean up the data for us - the default serialize method does + // it like this too) + *buffer = (unsigned char*)estrndup(value.c_str(), value.size()); + *buf_len = value.size(); + + // done return SUCCESS; } @@ -1028,8 +1039,16 @@ int ClassBase::serialize(zval *object, unsigned char **buffer, zend_uint *buf_le */ 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; + // create the PHP object + object_init_ex(*object, entry); + // turn this into a serializale + Serializable *serializable = dynamic_cast<Serializable*>(cpp_object(*object)); + + // call the unserialize method on it + serializable->unserialize(buffer, buf_len); + + // done return SUCCESS; } |