+/* {{{ proto int HttpMessage::count()
+ *
+ * Implements Countable.
+ *
+ * Returns the number of parent messages + 1.
+ */
+PHP_METHOD(HttpMessage, count)
+{
+ NO_ARGS {
+ long i;
+ http_message *msg;
+ getObject(http_message_object, obj);
+
+ for (i = 0, msg = obj->message; msg; msg = msg->parent, ++i);
+ RETURN_LONG(i);
+ }
+}
+/* }}} */
+
+/* {{{ proto string HttpMessage::serialize()
+ *
+ * Implements Serializable.
+ *
+ * Returns the serialized representation of the HttpMessage.
+ */
+PHP_METHOD(HttpMessage, serialize)
+{
+ NO_ARGS {
+ char *string;
+ size_t length;
+ getObject(http_message_object, obj);
+
+ http_message_serialize(obj->message, &string, &length);
+ RETURN_STRINGL(string, length, 0);
+ }
+}
+/* }}} */
+
+/* {{{ proto void HttpMessage::unserialize(string serialized)
+ *
+ * Implements Serializable.
+ *
+ * Re-constructs the HttpMessage based upon the serialized string.
+ */
+PHP_METHOD(HttpMessage, unserialize)
+{
+ int length;
+ char *serialized;
+ getObject(http_message_object, obj);
+
+ if (SUCCESS == zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &serialized, &length)) {
+ http_message_dtor(obj->message);
+ if (!http_message_parse_ex(obj->message, serialized, (size_t) length)) {
+ http_error(HE_ERROR, HTTP_E_RUNTIME, "Could not unserialize HttpMessage");
+ http_message_init(obj->message);
+ }
+ }
+}
+/* }}} */
+