示例#1
0
        static public CoreRequest CoreRequestFromBytes(MemoryByteStream stream)
        {
            byte type = stream.ReadByte();

            switch (type)
            {
            case _coreActionKeyPress:
            {
                byte keyCode = stream.ReadByte();
                bool keyDown = stream.ReadBool();

                return(CoreRequest.KeyPress(keyCode, keyDown));
            }

            case _coreActionReset:
            {
                return(CoreRequest.Reset());
            }

            case _coreActionLoadDisc:
            {
                byte   drive = stream.ReadByte();
                byte[] media = stream.ReadArray();

                return(CoreRequest.LoadDisc(drive, media));
            }

            case _coreActionLoadTape:
            {
                byte[] media = stream.ReadArray();

                return(CoreRequest.LoadTape(media));
            }

            case _coreActionRunUntil:
            {
                UInt64 stopTicks = stream.ReadUInt64();

                return(CoreRequest.RunUntil(stopTicks));
            }

            case _coreActionLoadCore:
            {
                byte[] state = stream.ReadArray();

                return(CoreRequest.LoadCore(new MemoryBlob(state)));
            }

            case _coreActionCoreVersion:
            {
                Int32 version = stream.ReadInt32();

                return(CoreRequest.CoreVersion(version));
            }

            case _coreActionCreateSnapshot:
            {
                Int32 snapshotId = stream.ReadInt32();

                return(CoreRequest.CreateSnapshot(snapshotId));
            }

            case _coreActionDeleteSnapshot:
            {
                Int32 snapshotId = stream.ReadInt32();

                return(CoreRequest.DeleteSnapshot(snapshotId));
            }

            case _coreActionRevertToSnapshot:
            {
                Int32 snapshotId = stream.ReadInt32();

                return(CoreRequest.RevertToSnapshot(snapshotId, null));
            }

            default:
                throw new Exception(String.Format("Unknown CoreRequest type {0}!", type));
            }
        }
示例#2
0
        static public CoreAction CoreActionFromBytes(MemoryByteStream stream)
        {
            byte type = stream.ReadByte();

            switch (type)
            {
            case _coreActionKeyPress:
            {
                UInt64 ticks   = stream.ReadUInt64();
                byte   keyCode = stream.ReadByte();
                bool   keyDown = stream.ReadBool();

                return(CoreAction.KeyPress(ticks, keyCode, keyDown));
            }

            case _coreActionReset:
            {
                UInt64 ticks = stream.ReadUInt64();

                return(CoreAction.Reset(ticks));
            }

            case _coreActionLoadDisc:
            {
                UInt64 ticks = stream.ReadUInt64();
                byte   drive = stream.ReadByte();
                byte[] media = stream.ReadArray();

                return(CoreAction.LoadDisc(ticks, drive, new MemoryBlob(media)));
            }

            case _coreActionLoadTape:
            {
                UInt64 ticks = stream.ReadUInt64();
                byte[] media = stream.ReadArray();

                return(CoreAction.LoadTape(ticks, new MemoryBlob(media)));
            }

            case _coreActionRunUntil:
            {
                UInt64 ticks     = stream.ReadUInt64();
                UInt64 stopTicks = stream.ReadUInt64();

                return(CoreAction.RunUntil(ticks, stopTicks, null));
            }

            case _coreActionLoadCore:
            {
                UInt64 ticks = stream.ReadUInt64();
                byte[] state = stream.ReadArray();

                return(CoreAction.LoadCore(ticks, new MemoryBlob(state)));
            }

            case _coreActionCoreVersion:
            {
                UInt64 ticks   = stream.ReadUInt64();
                Int32  version = stream.ReadInt32();

                return(CoreAction.CoreVersion(ticks, version));
            }

            case _coreActionCreateSnapshot:
            {
                UInt64 ticks      = stream.ReadUInt64();
                Int32  snapshotId = stream.ReadInt32();

                return(CoreAction.CreateSnapshot(ticks, snapshotId));
            }

            case _coreActionDeleteSnapshot:
            {
                UInt64 ticks      = stream.ReadUInt64();
                Int32  snapshotId = stream.ReadInt32();

                return(CoreAction.DeleteSnapshot(ticks, snapshotId));
            }

            case _coreActionRevertToSnapshot:
            {
                UInt64 ticks      = stream.ReadUInt64();
                Int32  snapshotId = stream.ReadInt32();

                return(CoreAction.RevertToSnapshot(ticks, snapshotId));
            }
            }

            throw new Exception(String.Format("Unknown CoreAction type {0}!", type));
        }