Esempio n. 1
0
        private static void UnitTest()
        {
            var    testfileName = "unittest.data";
            Stream fOut         = new FileStream(testfileName, FileMode.Create, FileAccess.Write);

            bool  waar   = true;
            int   drie   = 3;
            bool  onwaar = false;
            float vloot  = 17.5f;

            PacketHelper.SafeWrite <bool>(fOut, waar, PacketSize.BoolSize);
            PacketHelper.SafeWrite <bool>(fOut, onwaar, PacketSize.BoolSize);
            PacketHelper.SafeWrite <int>(fOut, drie, PacketSize.IntSize);
            PacketHelper.SafeWrite <float>(fOut, vloot, PacketSize.FloatSize);
            PacketHelper.SafeWrite <bool>(fOut, waar, PacketSize.BoolSize);
            PacketHelper.SafeWrite <bool>(fOut, onwaar, PacketSize.BoolSize);

            fOut.Close();

            Stream fIn = new FileStream(testfileName, FileMode.Open, FileAccess.Read);

            waar = PacketHelper.SafeRead <bool>(fIn, PacketSize.BoolSize);
            if (waar != true)
            {
                throw new Exception("fout");
            }
            ;
            onwaar = PacketHelper.SafeRead <bool>(fIn, PacketSize.BoolSize);
            if (onwaar != false)
            {
                throw new Exception("fout");
            }
            ;
            drie = PacketHelper.SafeRead <int>(fIn, PacketSize.IntSize);
            if (drie != 3)
            {
                throw new Exception("fout");
            }
            ;
            vloot = PacketHelper.SafeRead <float>(fIn, PacketSize.FloatSize);
            if (vloot != 17.5f)
            {
                throw new Exception("fout");
            }
            ;
            waar = PacketHelper.SafeRead <bool>(fIn, PacketSize.BoolSize);
            if (waar != true)
            {
                throw new Exception("fout");
            }
            ;
            onwaar = PacketHelper.SafeRead <bool>(fIn, PacketSize.BoolSize);
            if (onwaar != false)
            {
                throw new Exception("fout");
            }
            ;

            fIn.Close();
        }
Esempio n. 2
0
        public void Save(string baseDir)
        {
            var    fileName = BS(baseDir) + Pathname();
            Stream fOut     = new FileStream(fileName, FileMode.Create, FileAccess.Write);

            PacketHelper.SafeWrite <int>(fOut, 211, PacketSize.IntSize); // Version Number

            PacketHelper.SafeWrite <PacketSessionData>(fOut, circuitInfo, PacketSize.PacketSessionDataSize);
            PacketHelper.SafeWrite <ParticipantData>(fOut, playerInfo, PacketSize.ParticipantDataSize);

            PacketHelper.SafeWrite <bool>(fOut, lap.complete, PacketSize.BoolSize);
            PacketHelper.SafeWrite <LapData>(fOut, lap.FirstTiming, PacketSize.LapDataSize);
            PacketHelper.SafeWrite <UInt32>(fOut, lap.lapTimeInMs, PacketSize.UInt32Size);
            PacketHelper.SafeWrite <bool>(fOut, lap.started, PacketSize.BoolSize);
            PacketHelper.SafeWrite <bool>(fOut, lap.valid, PacketSize.BoolSize);
            PacketHelper.SafeWrite <CarSetupData>(fOut, lap.Setup, PacketSize.CarSetupDataSize);

            PacketHelper.SafeWrite <int>(fOut, lap.lapMotion.Count, PacketSize.IntSize);
            foreach (var motiondata in lap.lapMotion)
            {
                PacketHelper.SafeWrite <MotionInContext>(fOut, motiondata, PacketSize.MotionInContextSize);
            }

            PacketHelper.SafeWrite <int>(fOut, lap.lapTelemetry.Count, PacketSize.IntSize);
            foreach (var lapTelemetry in lap.lapTelemetry)
            {
                PacketHelper.SafeWrite <TelemetryInContext>(fOut, lapTelemetry, PacketSize.TelemetryInContextSize);
            }

            PacketHelper.SafeWrite <int>(fOut, lap.lapData.Count, PacketSize.IntSize);
            foreach (var lapData in lap.lapData)
            {
                PacketHelper.SafeWrite <LapDataInContext>(fOut, lapData, PacketSize.LapDataInContextSize);
            }

            fOut.Close();
        }