Po0ka
Member
I basically just need advices on how to serialize/deserialize a collection the right way.
Theorically i have an ArrayList<StuffClass>, it contains some "StuffClass" that i add/modify/delete from the list (easy stuffs).
The hard stuffs is when i want to serialize it.
My StuffClass contains: one "Type", two integers and a boolean.
1: Should i do something close to faction persistance?
ex:
If so the deserialize is kind of crappy:
2: Can we just "save" the collection aswell as it's content in one shot?
3: Can we save a class directly? (I would do a for loop and serializing each class)
Notes:
External files (XML, txt files, etc.) is not a valid option.
Thanks for any direction or small code samples.
Theorically i have an ArrayList<StuffClass>, it contains some "StuffClass" that i add/modify/delete from the list (easy stuffs).
The hard stuffs is when i want to serialize it.
My StuffClass contains: one "Type", two integers and a boolean.
1: Should i do something close to faction persistance?
ex:
Code:
List<Faction> factions = Faction.Factions;
for ( int i = 0; i < factions.Count; ++i )
{
writer.WriteEncodedInt( (int) PersistedType.Faction );
factions[i].State.Serialize( writer );
}
Code:
PersistedType type;
while ( (type = (PersistedType)reader.ReadEncodedInt()) != PersistedType.Terminator )
{
switch ( type )
{
case PersistedType.Faction: new FactionState( reader ); break;
case PersistedType.Town: new TownState( reader ); break;
}
}
2: Can we just "save" the collection aswell as it's content in one shot?
3: Can we save a class directly? (I would do a for loop and serializing each class)
Notes:
External files (XML, txt files, etc.) is not a valid option.
Thanks for any direction or small code samples.