in clicache/src/DataOutput.cpp [469:691]
void DataOutput::WriteObject(Object^ obj)
{
if (obj == nullptr)
{
WriteByte((int8_t)DSCode::NullObj);
return;
}
if (m_ispdxSerialization && obj->GetType()->IsEnum)
{
//need to set
int enumVal = Internal::PdxHelper::GetEnumValue(obj->GetType()->FullName, Enum::GetName(obj->GetType(), obj), obj->GetHashCode(), m_cache);
WriteByte(static_cast<int8_t>(DSCode::PDX_ENUM));
WriteByte(enumVal >> 24);
WriteArrayLen(enumVal & 0xFFFFFF);
return;
}
DSCode typeId = static_cast<DSCode>(m_cache->TypeRegistry->GetDsCodeForManagedType(obj->GetType()));
switch (typeId)
{
case DSCode::CacheableByte:
{
WriteByte(static_cast<unsigned char>(typeId));
WriteByte((Byte)obj);
return;
}
case DSCode::CacheableBoolean:
{
WriteByte(static_cast<unsigned char>(typeId));
WriteBoolean((bool)obj);
return;
}
case DSCode::CacheableCharacter:
{
WriteByte(static_cast<unsigned char>(typeId));
WriteObject((Char)obj);
return;
}
case DSCode::CacheableDouble:
{
WriteByte(static_cast<unsigned char>(typeId));
WriteDouble((Double)obj);
return;
}
case DSCode::CacheableASCIIString:
{
//CacheableString^ cStr = CacheableString::Create((String^)obj);
//// TODO: igfser mapping between generic and non generic
//WriteObjectInternal(cStr);
WriteStringWithType((String^)obj);
return;
}
case DSCode::CacheableFloat:
{
WriteByte(static_cast<unsigned char>(typeId));
WriteFloat((float)obj);
return;
}
case DSCode::CacheableInt16:
{
WriteByte(static_cast<unsigned char>(typeId));
WriteInt16((Int16)obj);
return;
}
case DSCode::CacheableInt32:
{
WriteByte(static_cast<unsigned char>(typeId));
WriteInt32((Int32)obj);
return;
}
case DSCode::CacheableInt64:
{
WriteByte(static_cast<unsigned char>(typeId));
WriteInt64((Int64)obj);
return;
}
case DSCode::CacheableDate:
{
//CacheableDate^ cd = gcnew CacheableDate((DateTime)obj);
// TODO: igfser mapping between generic and non generic
//WriteObjectInternal(cd);
WriteByte(static_cast<unsigned char>(typeId));
WriteDate((DateTime)obj);
return;
}
case DSCode::CacheableBytes:
{
WriteByte(static_cast<unsigned char>(typeId));
WriteBytes((array<Byte>^)obj);
return;
}
case DSCode::CacheableDoubleArray:
{
WriteByte(static_cast<unsigned char>(typeId));
WriteObject((array<Double>^)obj);
return;
}
case DSCode::CacheableFloatArray:
{
WriteByte(static_cast<unsigned char>(typeId));
WriteObject((array<float>^)obj);
return;
}
case DSCode::CacheableInt16Array:
{
WriteByte(static_cast<unsigned char>(typeId));
WriteObject((array<Int16>^)obj);
return;
}
case DSCode::CacheableInt32Array:
{
WriteByte(static_cast<unsigned char>(typeId));
WriteObject((array<Int32>^)obj);
return;
}
case DSCode::CacheableInt64Array:
{
WriteByte(static_cast<unsigned char>(typeId));
WriteObject((array<Int64>^)obj);
return;
}
case DSCode::BooleanArray:
{
WriteByte(static_cast<unsigned char>(typeId));
WriteObject((array<bool>^)obj);
return;
}
case DSCode::CharArray:
{
WriteByte(static_cast<unsigned char>(typeId));
WriteObject((array<char>^)obj);
return;
}
case DSCode::CacheableStringArray:
{
WriteByte(static_cast<unsigned char>(typeId));
WriteObject((array<String^>^)obj);
return;
}
case DSCode::CacheableHashTable:
case DSCode::CacheableHashMap:
case DSCode::CacheableIdentityHashMap:
{
WriteByte(static_cast<unsigned char>(typeId));
WriteDictionary((System::Collections::IDictionary^)obj);
return;
}
case DSCode::CacheableVector:
{
//CacheableVector^ cv = gcnew CacheableVector((System::Collections::IList^)obj);
//// TODO: igfser mapping between generic and non generic
//WriteObjectInternal(cv);
WriteByte(static_cast<unsigned char>(DSCode::CacheableVector));
WriteList((System::Collections::IList^)obj);
return;
}
case DSCode::CacheableLinkedList:
{
//CacheableArrayList^ cal = gcnew CacheableArrayList((System::Collections::IList^)obj);
//// TODO: igfser mapping between generic and non generic
//WriteObjectInternal(cal);
WriteByte(static_cast<unsigned char>(DSCode::CacheableLinkedList));
System::Collections::ICollection^ linkedList = (System::Collections::ICollection^)obj;
this->WriteArrayLen(linkedList->Count);
for each (Object^ o in linkedList)
this->WriteObject(o);
return;
}
case DSCode::CacheableArrayList:
{
//CacheableArrayList^ cal = gcnew CacheableArrayList((System::Collections::IList^)obj);
//// TODO: igfser mapping between generic and non generic
//WriteObjectInternal(cal);
WriteByte(static_cast<unsigned char>(DSCode::CacheableArrayList));
WriteList((System::Collections::IList^)obj);
return;
}
case DSCode::CacheableStack:
{
CacheableStack^ cs = gcnew CacheableStack((System::Collections::ICollection^)obj);
// TODO: igfser mapping between generic and non generic
WriteObjectInternal(cs);
return;
}
default:
{
if (auto pdxObj = dynamic_cast<IPdxSerializable^>(obj))
{
WriteByte(static_cast<int8_t>(DSCode::PDX));
Internal::PdxHelper::SerializePdx(this, pdxObj);
return;
}
else
{
//pdx serialization and is array of object
if (m_ispdxSerialization && obj->GetType()->IsArray)
{
WriteByte(static_cast<unsigned char>(DSCode::CacheableObjectArray));
WriteDotNetObjectArray(obj);
return;
}
if (auto ct = dynamic_cast<ISerializable^>(obj)) {
WriteObjectInternal(ct);
return;
}
if (m_cache->TypeRegistry->PdxSerializer)
{
auto pdxObj = gcnew PdxWrapper(obj);
WriteByte(static_cast<int8_t>(DSCode::PDX));
Internal::PdxHelper::SerializePdx(this, pdxObj);
return;
}
}
throw gcnew System::Exception("DataOutput not found appropriate type to write it for object: " + obj->GetType());
}
}
}