Example #1
0
        public void SerializeMultiple()
        {
            HelperStruct hlp = new HelperStruct(-50, 98, true, -30);

            m_stream.Serialize(ref hlp.intVal, -100, 100);
            m_stream.Serialize(ref hlp.bytVal, 0, 100);
            m_stream.Serialize(ref hlp.bolVal);
            m_stream.Serialize(ref hlp.srtVal, -50, 0);

            m_stream.ResetRead();

            HelperStruct rep = new HelperStruct();

            m_stream.Serialize(ref rep.intVal, -100, 100);
            m_stream.Serialize(ref rep.bytVal, 0, 100);
            m_stream.Serialize(ref rep.bolVal);
            m_stream.Serialize(ref rep.srtVal, -50, 0);

            Assert.AreEqual(hlp, rep);
        }
Example #2
0
        public static void ReadHelper()
        {
            string[] lines = File.ReadAllLines(AppDomain.CurrentDomain.BaseDirectory + "helper.txt");

            int i = 1;

            while (ok && i < lines.Length)
            {
                HelperStruct helper = new HelperStruct();

                string[] cells = lines[i].Split('\t');

                if (cells.Length <= 3)
                {
                    ok = false;
                }
                else
                {
                    ok &= uint.TryParse(cells[0], out helper.id);
                    ok &= uint.TryParse(cells[2], out helper.bytes);

                    helper.description = cells[1];
                }

                helper.parameterTypes = new List <string> {
                };

                int bytesLeft = (int)helper.bytes;
                int index     = 3;

                while (ok && bytesLeft > 0)
                {
                    switch (cells[index])
                    {
                    case "byte":
                    case "ubyte":
                        bytesLeft -= 1;
                        break;

                    case "short":
                    case "ushort":
                        bytesLeft -= 2;
                        break;

                    case "int":
                    case "uint":
                    case "float":
                        bytesLeft -= 4;
                        break;

                    case "long":
                    case "ulong":
                    case "double":
                        bytesLeft -= 8;
                        break;

                    default:
                        ok = false;
                        break;
                    }

                    helper.parameterTypes.Add(cells[index]);

                    index++;
                }

                if (bytesLeft < 0)
                {
                    ok = false;
                }

                helpers.Add(helper);

                i++;
            }
        }