MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / WriteObjectDynCreate

Method WriteObjectDynCreate

src/core/serializerimpl.cpp:165–236  ·  view source on GitHub ↗

////////////////////////////////////////////////////////////////////////// WriteObjectDynCreate //////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

163// WriteObjectDynCreate
164///////////////////////////////////////////////////////////////////////////////
165void cSerializerImpl::WriteObjectDynCreate(const iTypedSerializable* pObj)
166{
167 ASSERT(mbInit);
168 ASSERT(IsWriting());
169 cDebug d("cSerializerImpl::WriteObjectDynCreate");
170 // CurrentPos() only works with bidir archive
171 //d.TraceDetail("Entering... Archive Offset = %d\n", mpArchive->CurrentPos());
172 d.TraceDetail(_T(" Object Type = %s\n"), pObj->GetType().AsString());
173 // first, we write out the header, which consists of the following:
174 // uint32 crc of the object's type
175 // int32 version of stored data
176 // int32 size of the chunk (counting from this point; not including the previous int32
177 // int32 index into mRefCountObjTbl, or 0 if it isn't refrence counted.
178 // if the index already exists, then no data follows; a refrence
179 // should just be added to the existing object.
180 ASSERT(mpArchive != 0);
181
182 // get the ident for this class type
183 //
184 uint32 crc = util_GetCRC(pObj->GetType());
185
186 //
187 // make sure this type is registered, and figure out if it is refrence counted
188 //
189 SerRefCountMap::iterator i = mSerRefCountCreateMap.find(crc);
190 bool bRefCount = true;
191 if (i == mSerRefCountCreateMap.end())
192 {
193 //
194 // maybe it is not refrence counted...
195 //
196 SerMap::iterator si = mSerCreateMap.find(crc);
197 if (si == mSerCreateMap.end())
198 {
199 d.TraceError("Attempt to serialize unregistered type : %s\n", pObj->GetType().AsString());
200 ThrowAndAssert(eSerializerUnknownType(pObj->GetType().AsString(), mFileName, eSerializer::TY_FILE));
201 }
202 bRefCount = false;
203 }
204
205 mpArchive->WriteInt32(crc);
206 mpArchive->WriteInt32(pObj->Version());
207 // write a placeholder for the size; we will come back and fill in the right value later...
208 mpArchive->WriteInt32(0xffffffff);
209
210 if (bRefCount)
211 {
212 // see if the object has already been serialized...
213 int idx;
214 if ((idx = mRefCtObjTbl.Lookup(static_cast<const iSerRefCountObj*>(pObj))) == 0)
215 {
216 // it is not in the table yet; add it and serialize the object
217 idx = mRefCtObjTbl.Add(static_cast<const iSerRefCountObj*>(pObj));
218 d.TraceDetail("Object [%d] written for first time...\n", idx);
219 mpArchive->WriteInt32(idx);
220 pObj->Write(this);
221 }
222 else

Callers 7

WriteMethod · 0.80
WriteMethod · 0.80
WriteMethod · 0.80
WriteMethod · 0.80
WriteMethod · 0.80
TestFCOSpecHelperFunction · 0.80
TestSerRefCountObjFunction · 0.80

Calls 10

util_GetCRCFunction · 0.85
endMethod · 0.80
TraceDetailMethod · 0.60
TraceErrorMethod · 0.60
AsStringMethod · 0.45
findMethod · 0.45
WriteInt32Method · 0.45
LookupMethod · 0.45
AddMethod · 0.45
WriteMethod · 0.45

Tested by 4

WriteMethod · 0.64
WriteMethod · 0.64
TestFCOSpecHelperFunction · 0.64
TestSerRefCountObjFunction · 0.64