Changing marshaling method depending on condition

There is a method to marshal character information that differs depending on validity or invalidity of filed between character types. You can also have multi-methods of marshaling by taking leverage on switch/case characters or polymorphic objects. For easier understanding, we made an example of using swich/case as followed.

namespace Proud
{
enum UnitType
{
Zergling, // Zergling of STARCRAFT (Typical ground attack unit)
Queen, // Queen of STARCRAFT (Aerial unit with special ability)
Broodling, // Temporary units produced by Queen by using Broodling ability. Have a short lifetime.
};
struct Unit
{
UnitType m_type; // Type of unit
Vector2D m_position; // Position of unit
int m_energy; // Remaining magic energy of unit (or mana) -> valid to Queen only
float m_lifeTime; // Remaining lifetime of unit -> valid to Broodling only
int m_attackPower; // Attacking power of unit->vaild to Zergling only
};
CMessage& operator<<(CMessage& msg,const Unit& unit)
{
msg<<unit.m_type<<unit.m_position;
switch(unit.m_type)
{
case Zergling:
msg<<unit.m_attackPower;
break;
case Queen:
msg<<unit.m_energy;
break;
case Broodling:
msg<<unit.m_lifeTime;
break;
}
return msg;
}
CMessage& operator>>(CMessage& msg,Unit& unit)
{
msg>>unit.m_type>>unit.m_position;
switch(unit.m_type)
{
case Zergling:
msg>>unit.m_attackPower;
break;
case Queen:
msg>>unit.m_energy;
break;
case Broodling:
msg>>unit.m_lifeTime;
break;
}
return msg;
}
}