public static String EncodeTable(TableValue Value) { // Figure out how to turn the table into text TableDigested DigestedTable = Value.DigestTable(); // Begin result bracket thing. StringBuilder Result = new StringBuilder("["); // Turn everything into text. foreach (var item in DigestedTable.AutoIntArray) { Result.Append(EncoderStream.EncodeValue(item)); Result.Append(';'); } foreach (var item in DigestedTable.ManualIntDictionary) { ValueBase v = item.Value; Result.Append(item.Key.ToString()); Result.Append(':'); Result.Append(EncoderStream.EncodeValue(v)); Result.Append(';'); } foreach (var item in DigestedTable.MiscKeyDictionary) { Result.Append(item.Key.EncodeIntoValue()); Result.Append(':'); ValueBase v = item.Value; Result.Append(EncoderStream.EncodeValue(v)); Result.Append(';'); } // Close the plain-text table and return it. Result.Append(']'); return(Result.ToString()); }
public TableDigested DigestTable() { TableDigested Result = new TableDigested(); int HighestIndex = 1; foreach (var item in Dictionary) { if (item.Key.GetValueType() == ValueType.Int) { int index = ((IntValue)item.Key).Value; if (index > HighestIndex) { HighestIndex = index; } Result.ManualIntDictionary.Add(index, item.Value); } else { Result.MiscKeyDictionary.Add(item.Key, item.Value); } } List <KeyValuePair <int, ValueBase> > SortedList = new List <KeyValuePair <int, ValueBase> >(Result.ManualIntDictionary); SortedList.Sort((KeyValuePair <int, ValueBase> a, KeyValuePair <int, ValueBase> b) => { return(a.Key - b.Key); }); // Move all of the values, stacked uninterrupted on the lowest index, to the auto int array. for (int i = 1; i <= HighestIndex; i++) { ValueBase CurrentValue = null; if (Result.ManualIntDictionary.TryGetValue(i, out CurrentValue)) { Result.ManualIntDictionary.Remove(i); Result.AutoIntArray.Add(CurrentValue); } else { break; } } return(Result); }