You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by pe...@apache.org on 2003/09/26 00:22:01 UTC
cvs commit: xml-xerces/c/src/xercesc/internal XSerializeEngine.cpp XSerializeEngine.hpp
peiyongz 2003/09/25 15:22:01
Modified: c/src/xercesc/internal XSerializeEngine.cpp
XSerializeEngine.hpp
Log:
Introduction of readString/writeString
Revision Changes Path
1.5 +149 -2 xml-xerces/c/src/xercesc/internal/XSerializeEngine.cpp
Index: XSerializeEngine.cpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XSerializeEngine.cpp,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XSerializeEngine.cpp 25 Sep 2003 15:21:12 -0000 1.4
+++ XSerializeEngine.cpp 25 Sep 2003 22:22:00 -0000 1.5
@@ -57,6 +57,9 @@
/*
* $Id$
* $Log$
+ * Revision 1.5 2003/09/25 22:22:00 peiyongz
+ * Introduction of readString/writeString
+ *
* Revision 1.4 2003/09/25 15:21:12 peiyongz
* Loose the assert condition so that Serializable class need NOT to check the
* actual string length before read/write.
@@ -82,6 +85,13 @@
XERCES_CPP_NAMESPACE_BEGIN
+const bool XSerializeEngine::toWriteBufferLen = true;
+const bool XSerializeEngine::toReadBufferLen = true;
+ int XSerializeEngine::defaultBufferLen = 0;
+ int XSerializeEngine::defaultDataLen = 0;
+
+static const int noDataFollowed = -1;
+
static const XSerializeEngine::XSerializedObjectId_t fgNullObjectTag = 0; // indicating null ptrs
static const XSerializeEngine::XSerializedObjectId_t fgNewClassTag = 0xFFFFFFFF; // indicating new class
static const XSerializeEngine::XSerializedObjectId_t fgClassMask = 0x80000000; // indicates class tag
@@ -238,13 +248,14 @@
/***
*
- ***/
+***/
void XSerializeEngine::write(const XMLCh* const toWrite
, int writeLen)
{
write((XMLByte*)toWrite, (sizeof(XMLCh)/sizeof(XMLByte)) * writeLen);
}
+
void XSerializeEngine::write(const XMLByte* const toWrite
, int writeLen)
{
@@ -297,6 +308,63 @@
}
+/***
+ *
+ * Storage scheme (normal):
+ *
+ * <
+ * 1st integer: bufferLen (optional)
+ * 2nd integer: dataLen
+ * bytes following:
+ * >
+ *
+ * Storage scheme (special):
+ * <
+ * only integer: noDataFollowed
+ * >
+ */
+
+void XSerializeEngine::writeString(const XMLCh* const toWrite
+ , const int bufferLen
+ , bool toWriteBufLen)
+{
+ if (toWrite)
+ {
+ if (toWriteBufLen)
+ *this<<bufferLen;
+
+ int strLen = XMLString::stringLen(toWrite);
+ *this<<strLen;
+ write(toWrite, strLen);
+ }
+ else
+ {
+ *this<<noDataFollowed;
+ }
+
+}
+
+void XSerializeEngine::writeString(const XMLByte* const toWrite
+ , const int bufferLen
+ , bool toWriteBufLen)
+{
+
+ if (toWrite)
+ {
+ if (toWriteBufLen)
+ *this<<bufferLen;
+
+ int strLen = XMLString::stringLen((char*)toWrite);
+ *this<<strLen;
+ write(toWrite, strLen);
+ }
+ else
+ {
+ *this<<noDataFollowed;
+ }
+
+}
+
// ---------------------------------------------------------------------------
// Loading
// ---------------------------------------------------------------------------
@@ -432,6 +500,84 @@
memcpy(tempRead, fBufCur, readRemain);
fBufCur += readRemain;
}
+
+}
+
+/***
+ *
+ * Storage scheme (normal):
+ *
+ * <
+ * 1st integer: bufferLen (optional)
+ * 2nd integer: dataLen
+ * bytes following:
+ * >
+ *
+ * Storage scheme (special):
+ * <
+ * only integer: noDataFollowed
+ * >
+ */
+void XSerializeEngine::readString(XMLCh*& toRead
+ , int& bufferLen
+ , int& dataLen
+ , bool toReadBufLen)
+{
+ /***
+ * Check if any data written
+ ***/
+ *this>>bufferLen;
+ if (bufferLen == noDataFollowed)
+ {
+ toRead = 0;
+ bufferLen = 0;
+ dataLen = 0;
+ return;
+ }
+
+ if (toReadBufLen)
+ {
+ *this>>dataLen;
+ }
+ else
+ {
+ dataLen = bufferLen++;
+ }
+
+ toRead = (XMLCh*) fMemoryManager->allocate(bufferLen * sizeof(XMLCh));
+ read(toRead, dataLen);
+ toRead[dataLen] = 0;
+}
+
+void XSerializeEngine::readString(XMLByte*& toRead
+ , int& bufferLen
+ , int& dataLen
+ , bool toReadBufLen)
+{
+ /***
+ * Check if any data written
+ ***/
+ *this>>bufferLen;
+ if (bufferLen == noDataFollowed)
+ {
+ toRead = 0;
+ bufferLen = 0;
+ dataLen = 0;
+ return;
+ }
+
+ if (toReadBufLen)
+ {
+ *this>>dataLen;
+ }
+ else
+ {
+ dataLen = bufferLen++;
+ }
+
+ toRead = (XMLByte*) fMemoryManager->allocate(bufferLen * sizeof(XMLByte));
+ read(toRead, dataLen);
+ toRead[dataLen] = 0;
}
1.3 +92 -1 xml-xerces/c/src/xercesc/internal/XSerializeEngine.hpp
Index: XSerializeEngine.hpp
===================================================================
RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XSerializeEngine.hpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- XSerializeEngine.hpp 19 Sep 2003 04:29:11 -0000 1.2
+++ XSerializeEngine.hpp 25 Sep 2003 22:22:00 -0000 1.3
@@ -56,6 +56,9 @@
/*
* $Log$
+ * Revision 1.3 2003/09/25 22:22:00 peiyongz
+ * Introduction of readString/writeString
+ *
* Revision 1.2 2003/09/19 04:29:11 neilg
* fix compilation problems under GCC
*
@@ -219,6 +222,46 @@
/***
*
+ * Write a stream of XMLCh to the internal buffer.
+ *
+ * Write the bufferLen first if requested, then the length
+ * of the stream followed by the stream.
+ *
+ * Param
+ * toWrite: the stream of XMLCh to write
+ * bufferLen: the maximum size of the buffer
+ * toWriteBufLen: specify if the bufferLen need to be written or not
+ *
+ * Return:
+ *
+ ***/
+ void writeString(const XMLCh* const toWrite
+ , const int bufferLen = 0
+ , bool toWriteBufLen = false);
+
+ /***
+ *
+ * Write a stream of XMLByte to the internal buffer.
+ *
+ * Write the bufferLen first if requested, then the length
+ * of the stream followed by the stream.
+ *
+ * Param
+ * toWrite: the stream of XMLByte to write
+ * bufferLen: the maximum size of the buffer
+ * toWriteBufLen: specify if the bufferLen need to be written or not
+ *
+ * Return:
+ *
+ ***/
+ void writeString(const XMLByte* const toWrite
+ , const int bufferLen = 0
+ , bool toWriteBufLen = false);
+
+ static const bool toWriteBufferLen;
+
+ /***
+ *
* Read/Create object from the internal buffer.
*
* Param
@@ -272,6 +315,54 @@
***/
void read(XMLCh* const toRead
, int readLen);
+
+ /***
+ *
+ * Read a stream of XMLCh from the internal buffer.
+ *
+ * Read the bufferLen first if requested, then the length
+ * of the stream followed by the stream.
+ *
+ * Param
+ * toRead: the pointer to the buffer to hold the XMLCh stream
+ * bufferLen: the size of the buffer created
+ * dataLen: the length of the stream
+ * toReadBufLen: specify if the bufferLen need to be read or not
+ *
+ * Return:
+ *
+ ***/
+ void readString(XMLCh*& toRead
+ , int& bufferLen = defaultBufferLen
+ , int& dataLen = defaultDataLen
+ , bool toReadBufLen = false);
+
+ /***
+ *
+ * Read a stream of XMLByte from the internal buffer.
+ *
+ * Read the bufferLen first if requested, then the length
+ * of the stream followed by the stream.
+ *
+ * Param
+ * toRead: the pointer to the buffer to hold the XMLByte stream
+ * bufferLen: the size of the buffer created
+ * dataLen: the length of the stream
+ * toReadBufLen: specify if the bufferLen need to be read or not
+ *
+ * Return:
+ *
+ ***/
+ void readString(XMLByte*& toRead
+ , int& bufferLen = defaultBufferLen
+ , int& dataLen = defaultDataLen
+ , bool toReadBufLen = false);
+
+ static const bool toReadBufferLen;
+
+ static int defaultBufferLen;
+
+ static int defaultDataLen;
/***
*
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org