static object StringSerialise(object o, Serialiser s) { if (s == null) { return(""); } Encoding e = new UnicodeEncoding(); if (s.Encode) { byte[] b = e.GetBytes((string)o); s._Write(b.Length); for (int j = 0; j < b.Length; j++) { s._Write((int)b[j]); } return(null); } int ln = s._Read(); byte[] bb = new byte[ln]; for (int k = 0; k < ln; k++) { bb[k] = (byte)s._Read(); } string r = e.GetString(bb, 0, ln); return(r); }
private static object StringSerialise(object o, Serialiser s) { if (s == null) { return((object)""); } Encoding encoding = (Encoding) new UnicodeEncoding(); if (s.Encode) { byte[] bytes = encoding.GetBytes((string)o); s._Write(bytes.Length); for (int index = 0; index < bytes.Length; ++index) { s._Write((int)bytes[index]); } return((object)null); } int count = s._Read(); byte[] bytes1 = new byte[count]; for (int index = 0; index < count; ++index) { bytes1[index] = (byte)s._Read(); } return((object)encoding.GetString(bytes1, 0, count)); }
private static object HashtableSerialise(object o, Serialiser s) { if (s == null) { return((object)new Hashtable()); } Hashtable hashtable = (Hashtable)o; if (s.Encode) { s._Write(hashtable.Count); foreach (DictionaryEntry dictionaryEntry in hashtable) { s.Serialise(dictionaryEntry.Key); s.Serialise(dictionaryEntry.Value); } return((object)null); } int num = s._Read(); for (int index1 = 0; index1 < num; ++index1) { object index2 = s.Deserialise(); object obj = s.Deserialise(); hashtable[index2] = obj; } return((object)hashtable); }
static object CharSerialise(object o,Serialiser s) { Encoding e = new UnicodeEncoding(); if (s.Encode) { byte[] b = e.GetBytes(new string((char)o,1)); s._Write((int)b[0]); s._Write((int)b[1]); return null; } byte[] bb = new byte[2]; bb[0] = (byte)s._Read(); bb[1] = (byte)s._Read(); string r = e.GetString(bb,0,2); return r[0]; }
static object HashtableSerialise(object o, Serialiser s) { if (s == null) { return(new Hashtable()); } Hashtable h = (Hashtable)o; if (s.Encode) { s._Write(h.Count); foreach (DictionaryEntry d in h) { s.Serialise(d.Key); s.Serialise(d.Value); } return(null); } int ct = s._Read(); for (int j = 0; j < ct; j++) { object k = s.Deserialise(); object v = s.Deserialise(); h[k] = v; } return(h); }
static object HashtableSerialise(object o, Serialiser s) { if (s == null) { return(new Hashtable()); } Hashtable h = (Hashtable)o; if (s.Encode) { s._Write(h.Count); foreach (var d in h) { #if SILVERLIGHT s.Serialise(d.Key); s.Serialise(d.Value); #else s.Serialise(((System.Collections.DictionaryEntry)d).Key); s.Serialise(((System.Collections.DictionaryEntry)d).Value); #endif } return(null); } int ct = s._Read(); for (int j = 0; j < ct; j++) { object k = s.Deserialise(); object v = s.Deserialise(); h[k] = v; } return(h); }
static object SymtypeSerialise(object o,Serialiser s) { if (s.Encode) { s._Write((int)o); return null; } return (CSymbol.SymType)s._Read(); }
static object UnicodeCategorySerialise(object o,Serialiser s) { if (s.Encode) { s._Write((int)o); return null; } return (UnicodeCategory)s._Read(); }
static object IntSerialise(object o,Serialiser s) { if (s.Encode) { s._Write((int)o); return null; } return s._Read(); }
private static object SymtypeSerialise(object o, Serialiser s) { if (!s.Encode) { return((object)(CSymbol.SymType)s._Read()); } s._Write((int)o); return((object)null); }
private static object BoolSerialise(object o, Serialiser s) { if (!s.Encode) { return((object)(s._Read() != 0)); } s._Write(!(bool)o ? 0 : 1); return((object)null); }
private static object UnicodeCategorySerialise(object o, Serialiser s) { if (!s.Encode) { return((object)(UnicodeCategory)s._Read()); } s._Write((int)o); return((object)null); }
private static object IntSerialise(object o, Serialiser s) { if (!s.Encode) { return((object)s._Read()); } s._Write((int)o); return((object)null); }
private static object CharSerialise(object o, Serialiser s) { Encoding encoding = (Encoding) new UnicodeEncoding(); if (s.Encode) { byte[] bytes = encoding.GetBytes(new string((char)o, 1)); s._Write((int)bytes[0]); s._Write((int)bytes[1]); return((object)null); } byte[] bytes1 = new byte[2] { (byte)s._Read(), (byte)s._Read() }; return((object)encoding.GetString(bytes1, 0, 2)[0]); }
static object BoolSerialise(object o,Serialiser s) { if (s.Encode) { s._Write(((bool)o)?1:0); return null; } int v = s._Read(); return v!=0; }
Console.WriteLine((int)a[k]); int[] b = new int[a.Count]; for (int k=0;k<a.Count;k++) b[k] = (int)a[k]; Serialiser dr = new Serialiser(b); Hashtable h = (Hashtable)dr.Deserialise(); foreach (DictionaryEntry d in h) Console.WriteLine((string)d.Key + "->" + (int)d.Value); }
obs[u] = r; r = os(r,this); // really deserialise it obs[u] = r; // we need to store it again for strings return r; } return os(null,this); } else throw new Exception("unknown type "+t); }
/* public class Test { static string curline = ""; static int pos = 0; static bool EOF = false; static void GetLine(TextReader f) { curline = f.ReadLine(); pos = 0; if (curline == null) EOF = true; } static int GetInt(TextReader f) { int v = 0; bool s = false;
{ v = v*10 + (c-'0'); continue; } throw new Exception("illegal character"); } throw new Exception("bad line"); } public static void Main(string[] args) { TextWriter x = new StreamWriter("out.txt"); Hashtable t = new Hashtable(); t["John"] = 12; t["Mary"] = 34; Serialiser sr = new Serialiser(x); Console.WriteLine("Encoding"); sr.Serialise(t); x.Close(); ArrayList a = new ArrayList(); TextReader y = new StreamReader("out.txt"); GetLine(y); while (!EOF) a.Add(GetInt(y)); y.Close();