コード例 #1
0
void
DirEntity::PackDataObjects(BaseMessage& theMsgR, const DataObjectTypeSet& theSetR,
                           unsigned long theFlags)
{
	WTRACE("DirEntity::PackDataObjects");
	WDBG_LL("DirEntity::PackDataObject Packing data objects, size=" << theSetR.size());
	theMsgR.AppendShort(theSetR.size());

	bool packType = ((theFlags & WONMsg::GF_ADDDOTYPE) != 0);
	bool packData = ((theFlags & WONMsg::GF_ADDDODATA) != 0);
	DataObjectTypeSet::const_iterator anItr(theSetR.begin());
	for (; anItr != theSetR.end(); anItr++)
	{
		if (packType)
		{
			unsigned char aTypeLen = anItr->GetDataType().size();
			theMsgR.AppendByte(aTypeLen);
			theMsgR.AppendBytes(aTypeLen, anItr->GetDataType().data());
		}

		if (packData)
		{
			unsigned short aDataLen = anItr->GetData().size();
			theMsgR.AppendShort(aDataLen);
			theMsgR.AppendBytes(aDataLen, anItr->GetData().data());
		}
	}
}
コード例 #2
0
void
DirEntity::Pack(BaseMessage& theMsgR, unsigned long theGetFlags,
                const DataObjectTypeSet& theSetR) const
{
	WTRACE("DirEntity::Pack");
	WDBG_LL("DirEntity::Pack Packing entity, type=" << mType);

	// Add type if needed
	if (theGetFlags & WONMsg::GF_ADDTYPE)
		theMsgR.AppendByte(mType);

	// Entity specific fields
	switch (mType)
	{
	case DirEntity::ET_DIRECTORY:
		// Add dir path if needed
		if (theGetFlags & WONMsg::GF_DIRADDPATH)
			theMsgR.Append_PW_STRING(mPath);
		// Add dir name if needed
		if (theGetFlags & WONMsg::GF_DIRADDNAME)
			theMsgR.Append_PW_STRING(mName);
		// Add dir visibility if needed
		if (theGetFlags & WONMsg::GF_DIRADDVISIBLE)
			theMsgR.AppendByte(mVisible);
		break;
	case DirEntity::ET_SERVICE:
		// Add serv path if needed
		if (theGetFlags & WONMsg::GF_SERVADDPATH)
			theMsgR.Append_PW_STRING(mPath);
		// Add serv name if needed
		if (theGetFlags & WONMsg::GF_SERVADDNAME)
			theMsgR.Append_PW_STRING(mName);
		// Add serv netaddress if needed
		if (theGetFlags & WONMsg::GF_SERVADDNETADDR)
		{
			theMsgR.AppendByte(mNetAddress.size());
			theMsgR.AppendBytes(mNetAddress.size(), mNetAddress.data());
		}
		break;
	}

	// Add displayName if needed
	if (theGetFlags & WONMsg::GF_ADDDISPLAYNAME)
		theMsgR.Append_PW_STRING(mDisplayName);

	// Add lifespan if needed
	if (theGetFlags & WONMsg::GF_ADDLIFESPAN)
		theMsgR.AppendLong(mLifespan);

	// Add create date if needed
	if (theGetFlags & WONMsg::GF_ADDCREATED)
		theMsgR.AppendLong(mCreated);

	// Add touched date if needed
	if (theGetFlags & WONMsg::GF_ADDTOUCHED)
		theMsgR.AppendLong(mTouched);

	// Add CRC if needed
	if (theGetFlags & WONMsg::GF_ADDCRC)
		theMsgR.AppendLong(mCRC);

	// Add UserIds if needed
	if (theGetFlags & WONMsg::GF_ADDUIDS)
	{
		theMsgR.AppendLong(mCreateId);
		theMsgR.AppendLong(mTouchId);
	}

	// Add all data objects if needed
	if (theGetFlags & WONMsg::GF_ADDDATAOBJECTS)
		PackDataObjects(theMsgR, mDataObjects, theGetFlags);

	// Otherwise, add requested data objects (if any)
	else if (theSetR.size() > 0)
	{
		DataObjectTypeSet aPackSet;
		DataObjectTypeSet::const_iterator anItr(theSetR.begin());
		for (; anItr != theSetR.end(); anItr++)
		{
			DataObjectTypeSet::const_iterator aSrch(mDataObjects.find(*anItr));
			if (aSrch != mDataObjects.end())
				aPackSet.insert(*aSrch);
		}
		PackDataObjects(theMsgR, aPackSet, theGetFlags);
	}

	// Add ACLs if needed (deferred)
	if (theGetFlags & WONMsg::GF_ADDACLS)
		PackACLs(theMsgR);
}