in src/cas/internal_casserializer.cpp [598:686]
size_t CASSerializer::getBlob(uima::CAS & crCAS, void * buffer, size_t maxSize) {
UIMA_SERIALIZATION_TIMING( iv_timerFSHeap.reset() );
UIMA_SERIALIZATION_TIMING( iv_timerFSHeap.start() );
// get a heap of references
uima::internal::CASImpl const & crCASImpl = uima::internal::CASImpl::promoteCAS(crCAS);
uima::lowlevel::FSHeap const & crHeap = crCASImpl.getHeap();
uima::lowlevel::FSHeap::TyFSHeap const & tyTempHeap = crHeap.iv_clTemporaryHeap;
uima::lowlevel::FSHeap::TyStringHeap const & tyStringHeap = crHeap.iv_clTemporaryStringHeap;
uima::lowlevel::FSHeap::TyStringRefHeap const & tyStringRefHeap = crHeap.iv_clTemporaryStringRefHeap;
uima::lowlevel::FSHeap::Ty8BitHeap const & ty8BitHeap = crHeap.iv_clTemporary8BitHeap;
uima::lowlevel::FSHeap::Ty16BitHeap const & ty16BitHeap = crHeap.iv_clTemporary16BitHeap;
uima::lowlevel::FSHeap::Ty64BitHeap const & ty64BitHeap = crHeap.iv_clTemporary64BitHeap;
size_t uiFSHeapLength = tyTempHeap.getTopOfHeap();
size_t uiStringHeapLength = tyStringHeap.getTopOfHeap();
size_t uialignedStrLen = 2 * ((uiStringHeapLength + 1)/2);
size_t uiRefHeapLength = tyStringRefHeap.getTopOfHeap();
size_t uiIndexedFSLength = iv_vecIndexedFSs.size();
size_t ui8BitHeapLength = ty8BitHeap.getTopOfHeap();
size_t uialigned8BitHeapLength = 4 * ((ui8BitHeapLength+3)/4);
size_t ui16BitHeapLength = ty16BitHeap.getTopOfHeap();
size_t uialigned16BitHeapLength = 2 * ((ui16BitHeapLength+1)/2);
size_t ui64BitHeapLength = ty64BitHeap.getTopOfHeap();
size_t blobSize = 2*4 // key and version
+ (1 + uiFSHeapLength) * 4 // FSHeap length and data
+ 1*4 + (uialignedStrLen * 2) // StringHeap length and data
+ (1 + uiRefHeapLength) * 4 // StringRefheap length and data
+ (1 + uiIndexedFSLength) * 4 // Indexed FS length and data
+ (1*4 + uialigned8BitHeapLength) // 8 Bit Heap length and data
+ (1*4 + uialigned16BitHeapLength*2 ) //16 Bit Heap length and data
+ (1*4 + ui64BitHeapLength*8 ); //64 Bit Heap length and data
if (blobSize > maxSize) {
return 0; // can't serialize into given buffer
}
// copy all data into the blob buffer
int* intPtr = (int*) buffer;
#if defined(WORDS_BIGENDIAN)
char key[] = "UIMA";
#else
char key[] = "AMIU";
#endif
int version = 1;
intPtr[0] = ((int*)key)[0];
intPtr[1] = version;
intPtr[2] = uiFSHeapLength;
assert (blobSize > (size_t)((intPtr + 3 + uiFSHeapLength) - (int*)buffer));
memcpy(intPtr+3, tyTempHeap.getHeapStart(), 4*uiFSHeapLength);
intPtr += 3 + uiFSHeapLength;
intPtr[0] = uialignedStrLen;
assert (blobSize > (size_t)((intPtr + 1 + uiStringHeapLength/2) - (int*)buffer));
memcpy(intPtr+1, tyStringHeap.getHeapStart(), 2*uiStringHeapLength);
intPtr += 1 + uialignedStrLen/2;
intPtr[0] = uiRefHeapLength;
assert (blobSize > (size_t)((intPtr + 1 + uiRefHeapLength) - (int*)buffer));
memcpy(intPtr+1, tyStringRefHeap.getHeapStart(), 4*uiRefHeapLength);
intPtr += 1 + uiRefHeapLength;
intPtr[0] = uiIndexedFSLength;
assert (blobSize >= (size_t)((intPtr + 1 + uiIndexedFSLength) - (int*)buffer));
memcpy(intPtr+1, &iv_vecIndexedFSs[0], 4*uiIndexedFSLength);
intPtr += 1 + uiIndexedFSLength;
intPtr[0] = uialigned8BitHeapLength;
assert (blobSize > (size_t)((intPtr + 1 + uialigned8BitHeapLength/4) - (int*)buffer));
memcpy(intPtr+1, ty8BitHeap.getHeapStart(), ui8BitHeapLength);
intPtr += 1 + uialigned8BitHeapLength/4;
intPtr[0] = uialigned16BitHeapLength;
assert (blobSize > (size_t)((intPtr + 1 + ui16BitHeapLength/2) - (int*)buffer));
memcpy(intPtr+1, ty16BitHeap.getHeapStart(), 2*ui16BitHeapLength);
intPtr += 1 + uialigned16BitHeapLength/2;
intPtr[0] = ui64BitHeapLength;
assert (blobSize > (size_t)((intPtr + 1 + ui64BitHeapLength*2) - (int*)buffer));
memcpy(intPtr+1, ty64BitHeap.getHeapStart(), 8*ui64BitHeapLength);
UIMA_SERIALIZATION_TIMING( iv_timerFSHeap.stop() );
return blobSize;
}