Beispiel #1
0
        public void Bytes()
        {
            var bytes = Encoding.ASCII.GetBytes("turtle");

            var ns          = NetString.Create(bytes).ToByteArray();
            var parsedBytes = ns.ParseNetstring()[0].ToArray();

            assertArraysEqual(bytes, parsedBytes);
        }
Beispiel #2
0
        private void testRoundTrip(string str, Encoding enc)
        {
            var ns    = NetString.Create(str, enc);
            var bytes = ns.ToByteArray();

            var parsedBytes = bytes.ParseNetstring();
            var parsedStr   = enc.GetString(parsedBytes[0].Array, parsedBytes[0].Offset, parsedBytes[0].Count);

            Assert.AreEqual(str, parsedStr);
        }
Beispiel #3
0
        public void Concat()
        {
            var enc  = Encoding.UTF8;
            var str1 = "turtles in the sky with diamonds";
            var str2 = "喫茶店に行きました。";

            var ns = NetString.Concat(NetString.Create(str1, enc), NetString.Create(str2, enc)).ToByteArray();
            var b  = ns.ParseNetstring()[0].ParseNetstring();

            Assert.AreEqual(str1, b[0].ToString(enc));

            b = b[1].ParseNetstring();
            Assert.AreEqual(str2, b[0].ToString(enc));
        }