コード例 #1
0
ファイル: CAeonRowValue.cpp プロジェクト: gmoromisato/Hexarc
void CAeonRowValue::SerializeKey (IByteStream &Stream, const CString &sKey, DWORD *retdwSize)

//	SerializeKey
//
//	Serializes a key and returns the serialized size.
//
//	DWORD	key size
//	BYTES[]	key (padded to DWORD align)

	{
	DWORD dwKeySize = sKey.GetLength();

	//	Write out the key length

	Stream.Write(&dwKeySize, sizeof(DWORD));

	//	Write out the key (add 1 for NULL termination)

	Stream.Write(sKey.GetParsePointer(), dwKeySize + 1);

	//	Save padding

	DWORD dwZero = 0;
	DWORD dwAlignedKeySize = AlignUp(dwKeySize + 1, (DWORD)sizeof(DWORD));
	Stream.Write(&dwZero, dwAlignedKeySize - (dwKeySize + 1));

	//	Done

	if (retdwSize)
		*retdwSize = sizeof(DWORD) + dwAlignedKeySize;
	}
コード例 #2
0
ファイル: CDatum.cpp プロジェクト: gmoromisato/Hexarc
bool CDatum::DeserializeTextUTF8 (IByteStream &Stream, CDatum *retDatum)

//	DeserializeTextUTF8
//
//	Loads straight UTF-8 into a single string value.

	{
	CStringBuffer Buffer;

	//	See if we have an encoding mark

	BYTE BOM[3];
	Stream.Read(BOM, sizeof(BOM));
	if (BOM[0] == 0xef && BOM[1] == 0xbb && BOM[2] == 0xbf)
		;	//	UTF-8

	//	Otherwise, not an encoding mark, so write it to the buffer

	else
		Buffer.Write(BOM, sizeof(BOM));

	//	Write the rest

	Buffer.Write(Stream, Stream.GetStreamLength());
	return CreateStringFromHandoff(Buffer, retDatum);
	}
コード例 #3
0
ファイル: CComplexBinary.cpp プロジェクト: kronosaur/Hexarc
void CComplexBinary::OnSerialize (CDatum::ESerializationFormats iFormat, IByteStream &Stream) const

//	OnSerialize
//
//	Serialize

	{
	DWORD dwLength = GetLength();

	Stream.Write(&dwLength, sizeof(DWORD));
	if (dwLength)
		Stream.Write(m_pData, dwLength);
	}
コード例 #4
0
ファイル: CComplexBinary.cpp プロジェクト: kronosaur/Hexarc
bool CComplexBinary::OnDeserialize (CDatum::ESerializationFormats iFormat, const CString &sTypename, IByteStream &Stream)

//	OnDeserialize
//
//	Deserialize

	{
	if (m_pData)
		{
		delete [] GetBuffer();
		m_pData = NULL;
		}

	DWORD dwLength;
	Stream.Read(&dwLength, sizeof(DWORD));

	if (dwLength > 0)
		{
		CComplexBinary Temp(Stream, dwLength);
		m_pData = Temp.m_pData;
		Temp.m_pData = NULL;
		}

	return true;
	}
コード例 #5
0
ファイル: IComplexDatum.cpp プロジェクト: kronosaur/Hexarc
void CComplexDateTime::Serialize (CDatum::ESerializationFormats iFormat, IByteStream &Stream) const

//	Serialize
//
//	Serialize to the given format.

	{
	switch (iFormat)
		{
		case CDatum::formatAEONScript:
		case CDatum::formatAEONLocal:
			{
			CString sDate = strPattern("#%d-%02d-%02dT%02d:%02d:%02d.%04d",
					m_DateTime.Year(),
					m_DateTime.Month(),
					m_DateTime.Day(),
					m_DateTime.Hour(),
					m_DateTime.Minute(),
					m_DateTime.Second(),
					m_DateTime.Millisecond());

			Stream.Write(sDate);
			break;
			}

		case CDatum::formatJSON:
			{
			CString sDate = strPattern("\"%d-%02d-%02dT%02d:%02d:%02d.%04d\"",
					m_DateTime.Year(),
					m_DateTime.Month(),
					m_DateTime.Day(),
					m_DateTime.Hour(),
					m_DateTime.Minute(),
					m_DateTime.Second(),
					m_DateTime.Millisecond());

			Stream.Write(sDate);
			break;
			}

		default:
			IComplexDatum::Serialize(iFormat, Stream);
			break;
		}
	}
コード例 #6
0
ファイル: CDatum.cpp プロジェクト: gmoromisato/Hexarc
bool CDatum::CreateBinary (IByteStream &Stream, int iSize, CDatum *retDatum)

//	CreateBinary
//
//	Creates a string datum containing binary data from the stream.
//	If iSize is -1 then we read as much as the stream has.
//	Otherwise  we read up to iSize.

	{
	//	LATER: Handle streams more than 2GB. Instead of asking how much space
	//	is left, maybe we should just ask to truncate the size that we're
	//	requesting.
	int iDataRemaining = Stream.GetStreamLength() - Stream.GetPos();
	int iBinarySize = (iSize < 0 ? iDataRemaining : Min(iDataRemaining, iSize));

	//	0-size

	if (iBinarySize == 0)
		{
		*retDatum = CDatum();
		return true;
		}

	//	Read the stream

	CComplexBinary *pBinary;
	try
		{
		pBinary = new CComplexBinary(Stream, iBinarySize);
		}
	catch (...)
		{
		return false;
		}

	//	Done

	*retDatum = CDatum(pBinary);

	//	Done

	return true;
	}
コード例 #7
0
ファイル: CAeonRowValue.cpp プロジェクト: gmoromisato/Hexarc
void CAeonRowValue::Serialize (IByteStream &Stream)

//	Serialize
//
//	Serialize the row (we always write out aligned to DWORD)

	{
	if (m_pFixedBlock)
		Stream.Write(m_pFixedBlock, GetFixedBlockSize());
	}
コード例 #8
0
ファイル: IMediaType.cpp プロジェクト: gmoromisato/Hexarc
bool CRawMediaType::EncodeToBuffer (IByteStream &Stream, DWORD dwOffset, DWORD dwSize) const

//	EncodeToBuffer

	{
	if (dwSize == 0xffffffff)
		Stream.Write(m_sBody);
	else
		{
		DWORD dwBodyLen = m_sBody.GetLength();
		if (dwOffset < dwBodyLen)
			{
			DWORD dwActualSize = Min(dwSize, dwBodyLen - dwOffset);
			Stream.Write(m_sBody.GetParsePointer() + dwOffset, dwSize);
			}
		}

	return true;
	}
コード例 #9
0
ファイル: IComplexDatum.cpp プロジェクト: kronosaur/Hexarc
void CComplexArray::Serialize (CDatum::ESerializationFormats iFormat, IByteStream &Stream) const

//	Serialize
//
//	Serialize to the given format.

	{
	int i;

	switch (iFormat)
		{
		case CDatum::formatAEONScript:
		case CDatum::formatAEONLocal:
			{
			Stream.Write("(", 1);

			for (i = 0; i < m_Array.GetCount(); i++)
				{
				if (i != 0)
					Stream.Write(" ", 1);

				m_Array[i].Serialize(iFormat, Stream);
				}

			Stream.Write(")", 1);
			break;
			}

		case CDatum::formatJSON:
			{
			Stream.Write("[", 1);

			for (int i = 0; i < m_Array.GetCount(); i++)
				{
				if (i != 0)
					Stream.Write(", ", 2);

				m_Array[i].Serialize(iFormat, Stream);
				}

			Stream.Write("]", 1);
			break;
			}

		default:
			IComplexDatum::Serialize(iFormat, Stream);
			break;
		}
	}
コード例 #10
0
ファイル: IComplexDatum.cpp プロジェクト: kronosaur/Hexarc
void IComplexDatum::WriteBinaryToStream (IByteStream &Stream, int iPos, int iLength, IProgressEvents *pProgress) const

//	WriteBinaryToStream
	
	{
	const CString &sData = CastCString();
	if (iPos >= sData.GetLength())
		return;

    if (pProgress)
        pProgress->OnProgressStart();

	if (iLength == -1)
		iLength = Max(0, sData.GetLength() - iPos);
	else
		iLength = Min(iLength, sData.GetLength() - iPos);

	Stream.Write(sData.GetPointer() + iPos, iLength); 

    if (pProgress)
        pProgress->OnProgressDone();
	}
コード例 #11
0
ファイル: CMnemosynthDb.cpp プロジェクト: gmoromisato/Hexarc
void CMnemosynthDb::DebugDump (IByteStream &Stream)

//	DebugDump
//
//	Dumps the entire database

	{
	CSmartLock Lock(m_cs);

	int i, j;

	for (i = 0; i < m_Collections.GetCount(); i++)
		{
		SCollection *pCollection = &m_Collections[i];
		if (pCollection->Entries.GetCount() == 0)
			continue;

		//	Write out the collection name

		const CString &sCollectionName = m_Collections.GetKey(i);
		Stream.Write(sCollectionName);
		Stream.Write("\n", 1);

		//	Write out each entry in the collection

		for (j = 0; j < pCollection->Entries.GetCount(); j++)
			{
			//	Write the key

			const CString &sKey = pCollection->Entries.GetKey(j);
			Stream.Write("\t", 1);
			Stream.Write(sKey);
			Stream.Write("\n", 1);

			SEntry *pEntry = &pCollection->Entries[j];
			Stream.Write("\t\t", 2);
			pEntry->dValue.Serialize(CDatum::formatAEONScript, Stream);
			Stream.Write("\n", 1);
			}
		}
	}
コード例 #12
0
ファイル: CComplexBinary.cpp プロジェクト: kronosaur/Hexarc
CComplexBinary::CComplexBinary (IByteStream &Stream, int iLength)

//	CComplexBinary constructor

	{
	ASSERT(iLength >= 0);

	if (iLength == 0)
		m_pData = NULL;
	else
		{
		char *pPos = new char [sizeof(DWORD) + iLength + 1];

		*(DWORD *)pPos = iLength;
		pPos += sizeof(DWORD);

		m_pData = pPos;

		Stream.Read(pPos, iLength);
		pPos += iLength;

		*pPos = '\0';
		}
	}
コード例 #13
0
ファイル: CDatum.cpp プロジェクト: gmoromisato/Hexarc
void CDatum::WriteBinaryToStream (IByteStream &Stream, int iPos, int iLength, IProgressEvents *pProgress) const

//	WriteBinaryToStream
//
//	Writes a binary blob object to a stream.

	{
	switch (m_dwData & AEON_TYPE_MASK)
		{
		case AEON_TYPE_COMPLEX:
			raw_GetComplex()->WriteBinaryToStream(Stream, iPos, iLength, pProgress);
			break;

		default:
			{
			const CString &sData = *this;

			if (iPos >= sData.GetLength())
				return;

			if (iLength == -1)
				iLength = Max(0, sData.GetLength() - iPos);
			else
				iLength = Min(iLength, sData.GetLength() - iPos);

            if (pProgress)
                pProgress->OnProgressStart();

			Stream.Write(sData.GetPointer() + iPos, iLength);

            if (pProgress)
                pProgress->OnProgressDone();
			break;
			}
		}
	}
コード例 #14
0
ファイル: HTML.cpp プロジェクト: gmoromisato/Hexarc
void htmlWriteAttributeValue (const CString &sText, IByteStream &Output)

//	htmlWriteAttributeValue
//
//	Writes attribute value text, escaping all appropriate characters.

	{
	char *pPos = sText.GetParsePointer();
	char *pPosEnd = pPos + sText.GetLength();

	char *pStart = pPos;

	while (pPos < pPosEnd)
		{
		if (*pPos == '<')
			{
			Output.Write(pStart, pPos - pStart);
			pPos++;
			pStart = pPos;

			Output.Write("&lt;", 4);
			}
		else if (*pPos == '>')
			{
			Output.Write(pStart, pPos - pStart);
			pPos++;
			pStart = pPos;

			Output.Write("&gt;", 4);
			}
		else if (*pPos == '&')
			{
			Output.Write(pStart, pPos - pStart);
			pPos++;
			pStart = pPos;

			Output.Write("&amp;", 5);
			}
		else if (*pPos == '\"')
			{
			Output.Write(pStart, pPos - pStart);
			pPos++;
			pStart = pPos;

			Output.Write("&quot;", 6);
			}
		else if (*pPos == '\'')
			{
			Output.Write(pStart, pPos - pStart);
			pPos++;
			pStart = pPos;

			Output.Write("&apos;", 6);
			}
		else if (*pPos == '`')
			{
			Output.Write(pStart, pPos - pStart);
			pPos++;
			pStart = pPos;

			Output.Write("&#096;", 6);
			}
		else
            //  LATER: Should check for lower-ASCII characters
			pPos++;
		}

	Output.Write(pStart, pPos - pStart);
	}
コード例 #15
0
ファイル: HTML.cpp プロジェクト: gmoromisato/Hexarc
void htmlWriteText (char *pPos, char *pPosEnd, IByteStream &Output)

//	htmlWriteText
//
//	Writes text, escaping all appropriate HTML characters.
//
//	NOTE: This is only for the text content of HTML element; for escaping
//	attribute values, use htmlWriteAttributeValue

	{
	char *pStart = pPos;

	while (pPos < pPosEnd)
		{
		switch (*pPos)
			{
			case '<':
				Output.Write(pStart, (int)(pPos - pStart));
				pPos++;
				pStart = pPos;

				Output.Write("&lt;", 4);
				break;

			case '>':
				Output.Write(pStart, (int)(pPos - pStart));
				pPos++;
				pStart = pPos;

				Output.Write("&gt;", 4);
				break;

			case '&':
				Output.Write(pStart, (int)(pPos - pStart));
				pPos++;
				pStart = pPos;

				Output.Write("&amp;", 5);
				break;

			default:
				//	Most control codes (other than whitespace) are illegal,
				//	so we strip them out.

				if ((BYTE)*pPos <= 0x08
						|| *pPos == 0x0b
						|| *pPos == 0x0c
						|| ((BYTE)*pPos >= 0x0e && (BYTE)*pPos <= 0x1f))
					{
					Output.Write(pStart, (int)(pPos - pStart));
					pPos++;
					pStart = pPos;
					}

				//	Otherwise, keep parsing

				else
					pPos++;
				break;
			}
		}

	Output.Write(pStart, (int)(pPos - pStart));
	}
コード例 #16
0
ファイル: IComplexDatum.cpp プロジェクト: kronosaur/Hexarc
void CComplexStruct::Serialize (CDatum::ESerializationFormats iFormat, IByteStream &Stream) const

//	Serialize
//
//	Serialize to the given format.

	{
	int i;

	switch (iFormat)
		{
		case CDatum::formatAEONScript:
		case CDatum::formatAEONLocal:
			{
			Stream.Write("{", 1);

			for (i = 0; i < m_Map.GetCount(); i++)
				{
				if (i != 0)
					Stream.Write(" ", 1);

				//	Write the key

				CDatum Key(m_Map.GetKey(i));
				Key.Serialize(iFormat, Stream);

				//	Separator

				Stream.Write(":", 1);

				//	Write the value

				m_Map[i].Serialize(iFormat, Stream);
				}

			Stream.Write("}", 1);
			break;
			}

		case CDatum::formatJSON:
			{
			Stream.Write("{", 1);

			for (i = 0; i < m_Map.GetCount(); i++)
				{
				if (i != 0)
					Stream.Write(", ", 2);

				//	Write the key

				CDatum Key(m_Map.GetKey(i));
				Key.Serialize(iFormat, Stream);

				//	Separator

				Stream.Write(": ", 2);

				//	Write the value

				m_Map[i].Serialize(iFormat, Stream);
				}

			Stream.Write("}", 1);
			break;
			}

		default:
			IComplexDatum::Serialize(iFormat, Stream);
			break;
		}
	}
コード例 #17
0
ファイル: IComplexDatum.cpp プロジェクト: kronosaur/Hexarc
void IComplexDatum::Serialize (CDatum::ESerializationFormats iFormat, IByteStream &Stream) const

//	Serialize
//
//	Serialize the datum

	{
	DWORD dwFlags = OnGetSerializeFlags();

	switch (iFormat)
		{
		case CDatum::formatAEONScript:
		case CDatum::formatAEONLocal:
			{
			if (!(dwFlags & FLAG_SERIALIZE_NO_TYPENAME))
				{
				Stream.Write("[", 1);
				Stream.Write(GetTypename());
				Stream.Write(":", 1);
				}

			//	If this is object is serializable as a struct, then we do that.

			if (dwFlags & FLAG_SERIALIZE_AS_STRUCT)
				{
				CComplexStruct *pStruct = new CComplexStruct;

				OnSerialize(iFormat, pStruct);

				CDatum dDatum(pStruct);
				dDatum.Serialize(iFormat, Stream);
				}

			//	Otherwise, serialize as base64 encoding

			else
				{
				CBase64Encoder Encoder(&Stream);
				OnSerialize(iFormat, Encoder);
				Encoder.Close();
				}

			if (!(dwFlags & FLAG_SERIALIZE_NO_TYPENAME))
				Stream.Write("]", 1);
			break;
			}

		case CDatum::formatJSON:
			{
			if (!(dwFlags & FLAG_SERIALIZE_NO_TYPENAME))
				{
				Stream.Write("[\"AEON2011:", 11);
				Stream.Write(GetTypename());
				Stream.Write(":v1\", \"", 7);
				}

			//	LATER: Handle serialization/deserialization of struct-based objects

			CBase64Encoder Encoder(&Stream);
			OnSerialize(iFormat, Encoder);
			Encoder.Close();

			if (!(dwFlags & FLAG_SERIALIZE_NO_TYPENAME))
				Stream.Write("\"]", 2);
			break;
			}

		default:
			ASSERT(false);
		}
	}