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); }
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; }