public static byte[] SerializeObject(object customType)
        {
            var Stream = new MemoryStreamWriter();
            var Obj    = (CharacterData)customType;

            Obj.Serialize(Stream);
            return(Stream.Buffer.ToArray());
        }
示例#2
0
        public static byte[] SerializeObject(object customType)
        {
            var Stream = new MemoryStreamWriter();
            var Obj    = (PacketLogInResult)customType;

            Obj.Serialize(Stream);
            return(Stream.Buffer.ToArray());
        }
示例#3
0
        public static void Print(this ITestOutputHelper output, MemoryStreamWriter stdOut, MemoryStreamWriter stdErr)
        {
            output.WriteLine("----[ STD OUT ]----");
            output.WriteLine(stdOut.GetString());

            output.WriteLine(string.Empty);
            output.WriteLine(string.Empty);

            output.WriteLine("----[ STD ERR ]----");
            output.WriteLine(stdErr.GetString());
        }
        /// <summary>
        /// 送信
        /// </summary>
        /// <param name="SendPacket">送信するパケット</param>
        public void Send(Packet SendPacket)
        {
            MemorySizeCaliculator SizeCaliculator = new MemorySizeCaliculator();

            SizeCaliculator.Serialize(SendPacket);

            MemoryStreamWriter StreamWriter = new MemoryStreamWriter();
            PacketHeader       Header       = new PacketHeader(SendPacket.PacketId, (byte)SizeCaliculator.Size);

            StreamWriter.Serialize(Header);
            StreamWriter.Serialize(SendPacket);

            SendEvent(StreamWriter.Buffer.ToArray());
        }
示例#5
0
        /// <summary>
        /// Creates a <see cref="VirtualConsole"/> that uses in-memory output and error streams.
        /// Use the exposed streams to easily get the current output.
        /// </summary>
        public static (VirtualConsole console, MemoryStreamWriter output, MemoryStreamWriter error) CreateBuffered(bool isOutputRedirected             = true,
                                                                                                                   bool isErrorRedirected              = true,
                                                                                                                   CancellationToken cancellationToken = default)
        {
            // Memory streams don't need to be disposed
            var output = new MemoryStreamWriter(Console.OutputEncoding);
            var error  = new MemoryStreamWriter(Console.OutputEncoding);

            var console = new VirtualConsole(output: output, isOutputRedirected: isOutputRedirected,
                                             error: error, isErrorRedirected: isErrorRedirected,
                                             cancellationToken: cancellationToken);

            return(console, output, error);
        }
示例#6
0
        public void Benchmark()
        {
            const int benchmarkNum = 200000; // MemoryStream starts to choke after ~1GB
            var data = new byte[2048];
            var cmd = Command.Publish("test", data);

            var writer = new MemoryStreamWriter();

            var stopwatch = Stopwatch.StartNew();
            for (int i = 0; i < benchmarkNum; i++)
            {
                cmd.WriteTo(writer);
            }
            stopwatch.Stop();

            Console.WriteLine(string.Format("{0:#,0} commands written in {1:mm\\:ss\\.fff}; Avg: {2:#,0}/s",
                benchmarkNum, stopwatch.Elapsed, benchmarkNum / stopwatch.Elapsed.TotalSeconds));
        }
示例#7
0
 public void WriteCsvLine()
 {
     using (var w = new MemoryStreamWriter())
     {
         var culture = CultureInfos.Norwegian;
         w.WriteCsvLine(culture, "a b c", 3.14);
         w.WriteCsvLine(culture, "def\r\nghi", "3,14\r\n2.5");
         w.WriteCsvLine(culture, "a \"b\" c", "a ;b c");
         w.WriteCsvLine(culture, "\"abc\"", ";");
         w.WriteCsvLine(culture, string.Empty, string.Empty);
         w.WriteCsvLine(culture, (object)null, null);
         w.WriteCsvLine(culture, (object)null);
         w.WriteCsvLine(culture, true, false);
         var output   = w.ToString();
         var expected = CsvParserTests.TestString1;
         Assert.AreEqual(expected, output);
     }
 }
示例#8
0
 public void WriteCsvLine()
 {
     using (var w = new MemoryStreamWriter())
     {
         var culture = CultureInfos.Norwegian;
         w.WriteCsvLine(culture, "a b c", 3.14);
         w.WriteCsvLine(culture, "def\r\nghi", "3,14\r\n2.5");
         w.WriteCsvLine(culture, "a \"b\" c", "a ;b c");
         w.WriteCsvLine(culture, "\"abc\"", ";");
         w.WriteCsvLine(culture, string.Empty, string.Empty);
         w.WriteCsvLine(culture, (object)null, null);
         w.WriteCsvLine(culture, (object)null);
         w.WriteCsvLine(culture, true, false);
         var output = w.ToString();
         var expected = CsvParserTests.TestString1;
         Assert.AreEqual(expected, output);
     }
 }
示例#9
0
        public void Benchmark()
        {
            const int benchmarkNum = 200000; // MemoryStream starts to choke after ~1GB
            var       data         = new byte[2048];
            var       cmd          = Command.Publish("test", data);

            var writer = new MemoryStreamWriter();

            var stopwatch = Stopwatch.StartNew();

            for (var i = 0; i < benchmarkNum; i++)
            {
                cmd.WriteTo(writer);
            }
            stopwatch.Stop();

            Console.WriteLine(string.Format("{0:#,0} commands written in {1:mm\\:ss\\.fff}; Avg: {2:#,0}/s",
                                            benchmarkNum, stopwatch.Elapsed, benchmarkNum / stopwatch.Elapsed.TotalSeconds));
        }