const char hashtableID = 'h';
const char binaryID = 'b';
const char arrayID = 'a';
+ const char dateTimeID = 'd';
static Hashtable specialTypes;
static Hashtable idToType;
specialTypes.Add (typeof (ArrayList), new WriteObject (WriteArrayList));
specialTypes.Add (typeof (Hashtable), new WriteObject (WriteHashtable));
specialTypes.Add (typeof (Array), new WriteObject (WriteArray));
+ specialTypes.Add (typeof (DateTime), new WriteObject (WriteDateTime));
idToType = new Hashtable ();
idToType.Add (typeof (string), stringID);
}
break;
case binaryID:
- byte [] buffer = WebEncoding.Encoding.GetBytes (enclosed);
+ byte [] buffer = Convert.FromBase64String (enclosed);
MemoryStream ms = new MemoryStream (buffer);
BinaryFormatter fmt = new BinaryFormatter ();
obj = fmt.Deserialize (ms);
break;
+ case dateTimeID:
+ obj = new DateTime (Int64.Parse (enclosed));
+ break;
default:
throw new ArgumentException ("input");
}
output.Write('>');
}
+ private static void WriteDateTime (LosFormatter formatter, TextWriter output, object value)
+ {
+ if (value == null)
+ return;
+
+ output.Write (dateTimeID);
+ output.Write ('<');
+ output.Write (((DateTime) value).Ticks);
+ output.Write('>');
+ }
+
private static string EscapeSpecialChars (string str)
{
if (str.IndexOfAny (specialChars) == -1)
private void SerializeBinary (TextWriter output, object value)
{
WebTrace.PushContext ("LosFormatter.SerializeBinary");
- WebTrace.WriteLine ("not serializing value type: " + value.GetType ());
/* This is just for debugging purposes */
/*if (value is Array) {
Array array = (Array) value;
}
}
*/
- /*
+
BinaryFormatter fmt = new BinaryFormatter ();
MemoryStream stream = new MemoryStream ();
output.Write (binaryID);
output.Write ('<');
byte [] buffer = stream.GetBuffer ();
- output.Write (Convert.ToBase64String (stream.GetBuffer ()));
+ output.Write (Convert.ToBase64String (buffer));
output.Write ('>');
- */
+
WebTrace.PopContext ();
}