Index: /trunk/src/mesh/element.cc
===================================================================
--- /trunk/src/mesh/element.cc	(revision 248)
+++ /trunk/src/mesh/element.cc	(revision 249)
@@ -91,17 +91,17 @@
 
 	char * buf = new char[nbytes];
-	serialize(buf, nbytes);
+	if (buf != NULL)
+		serialize(buf);
+
 	return buf;
 }
 
 RP_ERROR
-RpElement::serialize(char* buf, int buflen)
-{
-	int nbytes = this->numBytes();
-
-	if (buf == NULL || buflen < (signed)(nbytes+2*sizeof(int))) {
-		RpAppendErr("RpNode::serialize: invalid buffer");
+RpElement::serialize(char* buf)
+{
+	if (buf == NULL) {
+		RpAppendErr("RpNode::serialize: null buffer");
 		RpPrintErr();
-		return RP_ERR_INVALID_ARRAY;
+		return RP_ERR_NULL_PTR;
 	}
 
@@ -123,6 +123,27 @@
 }
 
+// 
+// serialize only the nodes info
+// returns pointer to next char in buf
+//
+char*
+RpElement::serializeNodes(char* buf)
+{
+	int nbytes = m_nodes.size() * sizeof(int);
+
+	if (buf == NULL) {
+		RpAppendErr("RpNode::serialize: null buffer");
+		RpPrintErr();
+		return buf;
+	}
+
+	// copy all nodes
+	memcpy((void *)buf, (void *)&(m_nodes[0]), nbytes);
+
+	return (char*)(buf+nbytes);
+}
+
 RP_ERROR
-RpElement::deserialize(const char* buf)
+RpElement::deserializeNodes(const char* buf, int numNodes)
 {
 	if (buf == NULL) {
@@ -132,4 +153,23 @@
 	}
 
+	char* ptr = (char*)buf;
+
+	for (int i=0; i < numNodes; i++) {
+		memcpy((void *)&(m_nodes[i]), (void *)ptr, sizeof(int));
+		ptr += sizeof(int);
+	}
+
+	return RP_SUCCESS;
+}
+
+RP_ERROR
+RpElement::deserialize(const char* buf)
+{
+	if (buf == NULL) {
+		RpAppendErr("RpElement::deserialize: null buffer");
+                RpPrintErr();
+		return RP_ERR_NULL_PTR;
+	}
+
 	char * ptr = (char*)buf;
 
Index: /trunk/src/mesh/element.h
===================================================================
--- /trunk/src/mesh/element.h	(revision 248)
+++ /trunk/src/mesh/element.h	(revision 249)
@@ -43,5 +43,7 @@
 	// id(int), numNodes(int), list of ids(int *)
 	char* serialize();
-	RP_ERROR serialize(char* buf, int buflen);
+	char* serializeNodes(char* buf);
+	RP_ERROR serialize(char* buf);
+	RP_ERROR deserializeNodes(const char* buf, int numNodes);
 	RP_ERROR deserialize(const char* buf);
 
Index: /trunk/src/mesh/mesh.cc
===================================================================
--- /trunk/src/mesh/mesh.cc	(revision 248)
+++ /trunk/src/mesh/mesh.cc	(revision 249)
@@ -253,9 +253,32 @@
 }
 
+//
+// total number bytes in mesh object
+//
+// NOTE: this doesn't count the id
+//
+int RpMesh3d::numBytes()
+{
+	// numberOfNodes + all nodes + numberOfElements + numNodesInElement + nodes in elements
+
+	int nnie = (*m_elemList)[0].numNodes();
+	int num = 3*sizeof(int) + m_numNodes*3*sizeof(int) + m_numElements*nnie*sizeof(int);
+
+	return num;
+}
+
 // serialization
 char* 
-RpMesh3d::serialize()
-{
-	return NULL;
+RpMesh3d::serialize(int& numbytes)
+{
+	int nbytes = this->numBytes();
+
+	char * buf = new char[nbytes];
+	if (buf != NULL) {
+		serialize(buf, nbytes);
+		numbytes = nbytes;
+	}
+
+	return buf;
 }
 
@@ -263,4 +286,39 @@
 RpMesh3d::serialize(char* buf, int buflen)
 {
+	int nbytes = this->numBytes();
+	int nnie = (*m_elemList)[0].numNodes();
+	int i;
+
+	if (buf == NULL || buflen < nbytes) {
+		RpAppendErr("RpMesh3d::serialize: invalid buffer");
+		RpPrintErr();
+		return RP_ERR_INVALID_ARRAY;
+	}
+
+	char *ptr = buf;
+
+	// write number of nodes
+	memcpy((void *)ptr, (void *)&m_numNodes, sizeof(int));
+	ptr += sizeof(int);
+
+	// write all nodes
+	for (i=0; i < m_numNodes; i++) {
+		m_nodeList[i].serialize(ptr);
+		ptr += 3* sizeof(int);
+	}
+
+	// write number of elements
+	memcpy((void *)ptr, (void *)&m_numElements, sizeof(int));
+	ptr += sizeof(int);
+
+	// write number of nodes in each element
+	memcpy((void *)ptr, (void *)&nnie, sizeof(int));
+	ptr += sizeof(int);
+
+	// write all elements
+	for (i=0; i < m_numElements; i++) {
+		(*m_elemList)[i].serializeNodes(ptr);
+		ptr += nnie * sizeof(int);
+	}
 
 	return RP_SUCCESS;
@@ -270,4 +328,41 @@
 RpMesh3d::deserialize(const char* buf)
 {
+	int i;
+
+	if (buf == NULL) {
+		RpAppendErr("RpMesh3d::deserialize: null buffer");
+		RpPrintErr();
+		return RP_ERR_INVALID_ARRAY;
+	}
+
+	char *ptr = (char*)buf;
+	int nnie;
+
+	// read number of nodes
+	memcpy((void *)&m_numNodes, (void*)ptr, sizeof(int));
+	ptr += sizeof(int);
+
+	// read all nodes
+	for (i=0; i < m_numNodes; i++) {
+		m_nodeList[i].deserialize(ptr);
+		m_nodeList[i].id(i);
+		ptr += 3* sizeof(int);
+	}
+
+	// read number of elements
+	memcpy((void *)&m_numElements, (void*)ptr, sizeof(int));
+	ptr += sizeof(int);
+
+	// number of nodes in each element
+	memcpy((void *)&nnie, (void *)ptr, sizeof(int));
+	ptr += sizeof(int);
+
+	// read all elements
+	for (i=0; i < m_numElements; i++) {
+		(*m_elemList)[i].deserializeNodes(ptr, nnie);
+		(*m_elemList)[i].id(i);
+		ptr += nnie * sizeof(int);
+	}
+
 	return RP_SUCCESS;
 }
Index: /trunk/src/mesh/mesh.h
===================================================================
--- /trunk/src/mesh/mesh.h	(revision 248)
+++ /trunk/src/mesh/mesh.h	(revision 249)
@@ -46,5 +46,5 @@
 
 	// serialization
-	char* serialize();
+	char* serialize(int& numbytes);
 	RP_ERROR serialize(char* buf, int buflen);
 	RP_ERROR deserialize(const char* buf);
@@ -70,4 +70,6 @@
 	vector<RpNode3d> m_nodeList; // list of node objects
 	vector<RpElement> * m_elemList; // ptr to a list of RpElement objects
+
+	int numBytes();
 };
 
Index: /trunk/src/mesh/node2d.cc
===================================================================
--- /trunk/src/mesh/node2d.cc	(revision 248)
+++ /trunk/src/mesh/node2d.cc	(revision 249)
@@ -16,5 +16,5 @@
 
 	char * buf = new char[len];
-	serialize(buf, len);
+	serialize(buf);
 
 	return buf;
@@ -32,7 +32,7 @@
 //
 RP_ERROR 
-RpNode2d::serialize(char* buf, int buflen)
+RpNode2d::serialize(char* buf)
 {
-	if (buf == NULL || buflen < NodeDim*((signed)sizeof(int))) {
+	if (buf == NULL) {
 		RpAppendErr("RpElement::deserialize: null buffer");
 		RpPrintErr();
Index: /trunk/src/mesh/node2d.h
===================================================================
--- /trunk/src/mesh/node2d.h	(revision 248)
+++ /trunk/src/mesh/node2d.h	(revision 249)
@@ -38,5 +38,5 @@
 
 	char* serialize();
-	RP_ERROR serialize(char* buf, int buflen);
+	RP_ERROR serialize(char* buf);
 	RP_ERROR deserialize(const char* buf);
 
Index: /trunk/src/mesh/node3d.cc
===================================================================
--- /trunk/src/mesh/node3d.cc	(revision 248)
+++ /trunk/src/mesh/node3d.cc	(revision 249)
@@ -15,5 +15,5 @@
 
 	char * buf = new char[len];
-	serialize(buf, len);
+	serialize(buf);
 
 	return buf;
@@ -22,4 +22,6 @@
 //
 // actual function that does the serialization
+//     serialization order:
+//     	x y z x y z ...
 //
 // Input:
@@ -31,7 +33,7 @@
 //
 RP_ERROR 
-RpNode3d::serialize(char* buf, int buflen)
+RpNode3d::serialize(char* buf)
 {
-	if (buf == NULL || buflen < 3*((signed)sizeof(int))) {
+	if (buf == NULL) {
 		RpAppendErr("RpElement::deserialize: null buffer");
 		RpPrintErr();
Index: /trunk/src/mesh/node3d.h
===================================================================
--- /trunk/src/mesh/node3d.h	(revision 248)
+++ /trunk/src/mesh/node3d.h	(revision 249)
@@ -45,5 +45,5 @@
 
 	char* serialize();
-	RP_ERROR serialize(char* buf, int buflen);
+	RP_ERROR serialize(char* buf);
 	RP_ERROR deserialize(const char* buf);
 
