Exemple #1
0
        public static Packet unPack(string s)
        {
            int    a      = s.Length - s.Replace("{", "").Replace("[", "").Length;
            int    b      = s.Length - s.Replace("}", "").Replace("]", "").Length;
            string checkS = s.Replace(Environment.NewLine, "").Trim();

            if (a != b || !checkS.Substring(0, 1).Equals("{") || !checkS.Substring(checkS.Length - 3, 1).Equals("}") ||
                !checkS.Contains("flavour") || !checkS.Contains("key"))
            {
                Console.WriteLine("Packet: invalid string");
                Console.WriteLine(s);
                Console.WriteLine("-- end print --");
                Console.WriteLine(checkS.Substring(checkS.Length - 2, 1).ToCharArray()[0]);
                //Console.WriteLine(checkS.Substring(checkS.Length - 3, 1));
                //Console.WriteLine("a: {0}, b: {1}", a, b);
                throw new InvalidDataException();
            }

            Flavour   f;
            PacketKey k = new PacketKey();
            ComData   d = new ComData();

            JSONDecoder jd = new JSONDecoder(s);

            jd.beginItem();

            string flav = jd.getField()[1].Trim();

            f = (Flavour)Enum.Parse(typeof(Flavour), flav);

            jd.getField();  // key
            k.fillFromJSON(jd);

            if (f != Flavour.ECHO)
            {
                jd.getField();  // data
                d.fillFromJSON(jd);
            }

            jd.endItem();

            return(new Packet(f, k, d));
        }
Exemple #2
0
 public PacketKey(PacketKey other)
 {
     value = other.value;
 }
Exemple #3
0
 private Packet(Flavour f, PacketKey k, ComData d) : this(f, k)
 {
     data = d;
 }
Exemple #4
0
 private Packet(Flavour f, PacketKey k)
 {
     flavour = f;
     key     = new PacketKey(k);
 }
Exemple #5
0
 public Packet(Flavour f)
 {
     flavour = f;
     key     = new PacketKey();
 }
Exemple #6
0
 public Packet(ComData d)
 {
     data    = d;
     flavour = Flavour.DATA;
     key     = new PacketKey();
 }
Exemple #7
0
 private Packet(Packet p)
 {
     flavour = p.flavour;
     key     = p.key;
     data    = p.data;
 }