private byte[] HandlePacket_GetRankingIdByName(byte[] RequestContent)
        {
            var RankingName  = Encoding.UTF8.GetString(RequestContent, 0, RequestContent.Length - 1);
            int RankingIndex = ServerManager.ServerIndices[RankingName].IndexId;

            return(StructUtils.StructToBytes((int)RankingIndex));
        }
        /// <summary>
        ///
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="stream"></param>
        /// <param name="Struct"></param>
        /// <returns></returns>
        public static Stream WriteStruct <T>(this Stream stream, T Struct) where T : struct
        {
            var bytes = StructUtils.StructToBytes(Struct);

            stream.Write(bytes, 0, bytes.Length);
            return(stream);
        }
        private byte[] HandlePacket_GetRankingInfo(byte[] RequestContent)
        {
            var Request = StructUtils.BytesToStruct <GetRankingInfo_RequestStruct>(RequestContent);

            var Index    = ServerManager.ServerIndices[Request.RankingIndex];
            var Response = default(GetRankingInfo_ResponseStruct);

            Response = new GetRankingInfo_ResponseStruct()
            {
                Result      = 0,
                Length      = Index.Tree.Count,
                Direction   = Index.SortingDirection,
                TopScore    = 0,
                BottomScore = 0,
                MaxElements = -1,
                TreeHeight  = -1
                              //TreeHeight = Index.Tree.height
            };

            if (Index.Tree.Count > 0)
            {
                Response.TopScore    = Index.Tree.FrontElement.ScoreValue;
                Response.BottomScore = Index.Tree.BackElement.ScoreValue;
            }

            return(StructUtils.StructToBytes(Response));
        }
示例#4
0
文件: DXT5Test.cs 项目: talestra/tov
        public void TestCompressDXT5()
        {
            var Colors1 = new ARGB_Rev[16]
            {
                "#E0D6A973",
                "#E0D6A900",
                "#E0D6A900",
                "#E0D6A900",
                "#E0D6A9BC",
                "#E0D6A95B",
                "#E0D6A95B",
                "#E0D6A95B",
                "#E3DAAED5",
                "#E0D6A9D5",
                "#E0D6A9D5",
                "#E0D6A9D5",
                "#E3DAAE8B",
                "#E6DEB4FF",
                "#E6DEB4FF",
                "#E6DEB4FF",
            };

            var Colors2 = new ARGB_Rev[16];
            var Block   = default(DXT5.AlphaColorBlock);

            //var Color1 = default(ARGB_Rev);
            //var Color2 = default(ARGB_Rev);

            CompressDXT.CompressBlockDXT5(Colors1, out Block, CompressDXT.CompressionMode.Normal);

            Console.WriteLine(StructUtils.StructToBytes(Block).ToHexString().ToUpper());

            Block.Decode(ref Colors2);

            Assert.AreEqual(
                "#E0D6A973,#E0D6A900,#E0D6A900,#E0D6A900,#E0D6A9BC,#E0D6A95B,#E0D6A95B,#E0D6A95B,#E3DAAED5,#E0D6A9D5,#E0D6A9D5,#E0D6A9D5,#E3DAAE8B,#E6DEB4FF,#E6DEB4FF,#E6DEB4FF",
                Colors1.ToStringArray(",")
                );
            Assert.AreEqual(
                "#DED6AC6D,#DED6AC00,#DED6AC00,#DED6AC00,#DED6ACB6,#DED6AC6D,#DED6AC6D,#DED6AC6D,#E0D8AEDA,#DED6ACDA,#DED6ACDA,#DED6ACDA,#E0D8AE91,#E6DEB4FF,#E6DEB4FF,#E6DEB4FF",
                Colors2.ToStringArray(",")
                );

            //CompressionSimpleDXT5.FindColorPair(Colors1, out Color1, out Color2);

            //CompressYCoCgDXT5.CompressBlock(Colors1, ref Block);
        }
        private byte[] HandlePacket_RemoveAllElements(byte[] RequestContent)
        {
            var Request = StructUtils.BytesToStruct <RemoveAllElements_RequestStruct>(RequestContent);

            uint Count = 0;

            {
                var RankingIndex = ServerManager.ServerIndices[Request.RankingIndexId];
                Count = (uint)RankingIndex.Tree.Count;
                RankingIndex.RemoveAllItems();
            }

            return(StructUtils.StructToBytes(new RemoveAllElements_ResponseStruct()
            {
                Result = 0,
                Count = Count,
            }));
        }
        async private Task <byte[]> HandlePacketAsync_RemoveAllElements(byte[] RequestContent)
        {
            var Request = StructUtils.BytesToStruct <RemoveAllElements_RequestStruct>(RequestContent);

            uint Count = 0;

            await EnqueueTaskAsync((uint)Request.RankingIndexId, () =>
            {
                var RankingIndex = ServerManager.ServerIndices[Request.RankingIndexId];
                Count            = (uint)RankingIndex.Tree.Count;
                RankingIndex.RemoveAllItems();
            });

            return(StructUtils.StructToBytes(new RemoveAllElements_ResponseStruct()
            {
                Result = 0,
                Count = Count,
            }));
        }
        private async Task <byte[]> HandlePacketAsync_GetElement(byte[] RequestContent)
        {
            var Request       = StructUtils.BytesToStruct <GetElement_RequestStruct>(RequestContent);
            int IndexPosition = -1;
            var UserScore     = default(ServerIndices.UserScore);

            await EnqueueTaskAsync((uint)Request.RankingIndex, () =>
            {
                var Ranking = ServerManager.ServerIndices[Request.RankingIndex];
                try
                {
                    UserScore     = Ranking.GetUserScore(Request.UserId);
                    IndexPosition = Ranking.Tree.GetItemPosition(UserScore);
                }
                catch
                {
                }
            });

            if (IndexPosition == -1 || UserScore == null)
            {
                return(StructUtils.StructToBytes(new GetElement_ResponseStruct()
                {
                    Position = -1,
                    UserId = 0,
                    ScoreValue = 0,
                    ScoreTimeStamp = 0,
                }));
            }
            else
            {
                return(StructUtils.StructToBytes(new GetElement_ResponseStruct()
                {
                    Position = IndexPosition,
                    UserId = UserScore.UserId,
                    ScoreValue = UserScore.ScoreValue,
                    ScoreTimeStamp = UserScore.ScoreTimeStamp,
                }));
            }
        }
        protected string handlePacket2(string packet)
        {
            //string[] parts = std.array.split(";", packet);
            char type = packet[0];

            if (type != 'm')
            {
                if (debugMaster)
                {
                    Console.WriteLine("recvData: %s", packet);
                }
                debugData = true;
            }
            else
            {
                debugData = false;
            }

            switch (type)
            {
            // A simple reply of "OK" indicates the target will support extended remote debugging.
            case '!':
                return("OK");

                break;

            // The detach is acknowledged with a reply packet of "OK" before the client
            // connection is closed and rsp.client_fd set to -1. The semantics of detach
            // require the target to resume execution, so the processor is unstalled
            // using set_stall_state (0).
            case 'D':
                return("OK");

                break;

            // This sets the thread number of subsequent operations.
            // Since thread numbers are of no relevance to this target,
            // a response of "OK" is always acceptable.
            case 'H':
                return("OK");

                break;

            // The kill request is used in extended mode before a restart or
            // request to run a new program (vRun packet). Since the CPU is
            // already stalled, it seems to have no additional semantic meaning.
            // Since it requires no reply it can be silently ignored.
            case 'k':
                return("OK");

                break;

            // Since this is a bare level target, there is no concept of separate threads.
            // The one thread is always active, so a reply of "OK" is always acceptable.
            case 'T':
                return("OK");

                break;

            // The response to the ? packet is provided by rsp_report_exception ().
            // This is always a S packet. The signal value (as a GDB target signal)
            // is held in rsp.sigval, and is presented as two hexadecimal digits.
            case '?':
                if (running)
                {
                    return(getSigvalPacket());
                }
                else
                {
                    return("E01");
                }
                break;

            case 'd':
                debugFlag = !debugFlag;
                return("OK");

                break;

            // Read all registers
            case 'g': {
                string o = "";
                foreach (var register in registers.ALL)
                {
                    o += hexEncode(StructUtils.StructToBytes(register));
                }
                return(o);
            } break;

            // Write all registers
            case 'G':
                break;

            // Read a register
            case 'p': {
                var regNum = Convert.ToUInt32(packet.Substring(1), 16);
                return(hexEncode(StructUtils.StructToBytes(registers.ALL[regNum])));
            } break;

            // Write a register
            case 'P': {
                string[] parts  = packet.Substring(1).Split('=');
                var      regNum = Convert.ToUInt32(parts[0], 16);
                var      value  = BitConverter.ToUInt32(hexDecode(parts[1]), 0);
                registers.ALL[regNum] = value;
                return("OK");
            } break;

            // http://www.embecosm.com/appnotes/ean4/html/ch04s07s07.html

            // Read from memory
            case 'm': {
                var parts = packet.Substring(1).Split(',');
                var addr  = Convert.ToUInt32(parts[0], 16);
                var size  = Convert.ToUInt32(parts[1], 16);
                var data  = new byte[size];
                for (int n = 0; n < data.Length; n++)
                {
                    data[n] = 0xFF;
                }
                return(hexEncode(data));
            } break;

            // Write to memory
            case 'M':
                break;

            // The functionality for the R packet is provided in rsp_restart ().
            // The start address of the current target is held in rsp.start_addr.
            // The program counter is set to this address using set_npc () (see Section 4.6.5).
            case 'R':
                break;

            // Continue
            case 'c': {
                //scope (exit) lastSigval = Sigval.Ok;
                lastSigval = Sigval.DebugException;
                return(getSigvalPacket());

                /*
                 * (new Thread({
                 *      Thread.sleep(dur!"msecs"(400));
                 *      lastSigval = Sigval.DebugException;
                 *      sendPacket(getSigvalPacket());
                 * })).start();
                 *
                 * lastSigval = Sigval.DebugException;
                 * sendPacket(getSigvalPacket());
                 *
                 * return "";
                 */
                //return "";
            }

            // Step
            case 's':
                return("T00");

                break;

            // Extended packets.
            case 'v': {
                string[] packetParts = packet.Split(';');
                switch (packetParts[0])
                {
                case "vRun": {
                    var args = new List <string>();
                    foreach (var argHex in packetParts.Slice(1))
                    {
                        args.Add(Encoding.ASCII.GetString(hexDecode(argHex)));
                    }
                    Console.WriteLine("%s", args);
                    try {
                        return("S00");
                    } finally {
                        lastSigval = Sigval.InvalidOpcode;
                    }
                    //return getSigvalPacket();
                    //return "";
                } break;

                case "vAttach":
                    break;

                case "vCont":
                    break;

                case "vCont?":
                    return("OK");

                    break;

                case "vFile":
                    break;

                case "vFlashErase":
                case "vFlashWrite":
                case "vFlashDone":
                    break;

                default:
                    throw(new Exception(String.Format("Unknown packet '{0}'", packet)));
                }
            } break;

            // Query.
            // http://www.manpagez.com/info/gdb/gdb_282.php
            case 'q':
            {
                Func <int, string> getNextThread = (cursor) =>
                {
                    if (threadCursor >= threads.Length)
                    {
                        return("l");
                    }
                    else
                    {
                        return("m%x".Sprintf(threads[threadCursor]));
                    }
                };

                switch (packet)
                {
                case "qfThreadInfo": threadCursor = 0; return(getNextThread(threadCursor++));

                case "qsThreadInfo": return(getNextThread(threadCursor++));

                case "qC": return("QC%x".Sprintf(threads[0]));

                default: throw(new Exception(String.Format("Unknown packet '{0}'", packet)));
                }
            }

            default:
                throw(new Exception(String.Format("Unknown packet '{0}'", packet[0])));
            }

            return("E01");
        }
示例#9
0
 public void WriteStruct <TType>(uint Address, TType Value) where TType : struct => WriteBytes(Address, StructUtils.StructToBytes(Value));
示例#10
0
 protected byte[] HandlePacket_GetServerInfo(byte[] RequestContent)
 {
     return(StructUtils.StructToBytes(ServerManager.ServerInfo));
 }
示例#11
0
        /// <summary>
        /// Obtains information about the server:
        /// - IndexCount
        /// - TotalNumberOfElements
        /// - CurrentPrivateMemory
        /// - CurrentVirtualMemory
        /// - PeakVirtualMemory
        /// </summary>
        /// <param name="RequestContent">Content of the request.</param>
        /// <returns>A ServerManager.ServerInfoStruct as a byte array.</returns>
#if NET_4_5
        async protected Task <byte[]> HandlePacketAsync_GetServerInfo(byte[] RequestContent)
        {
            return(StructUtils.StructToBytes(ServerManager.ServerInfo));
        }
示例#12
0
 public static Stream WriteStruct <T>(this Stream Stream, T Struct) where T : struct
 {
     byte[] Bytes = StructUtils.StructToBytes(Struct);
     Stream.Write(Bytes, 0, Bytes.Length);
     return(Stream);
 }
示例#13
0
        static public void WriteStructAsync <TType>(this Stream Stream, TType Value) where TType : struct
        {
            var Data = StructUtils.StructToBytes(Value);

            Stream.Write(Data, 0, Data.Length);
        }
示例#14
0
 static public async Task WriteStructAsync <TType>(this Stream Stream, TType Value) where TType : struct
 {
     var Data = StructUtils.StructToBytes(Value);
     await Stream.WriteAsync(Data, 0, Data.Length);
 }
示例#15
0
 protected byte[] HandlePacket_GetVersion(byte[] RequestContent)
 {
     return(StructUtils.StructToBytes(ServerManager.Version));
 }