Example #1
0
        public unsafe void MixedWrite()
        {
            byte[] data = new byte[256];

            fixed(byte *pData = data)
            {
                UnsafeBinaryMemoryWriter writer = new UnsafeBinaryMemoryWriter(pData);

                writer.Write("abcABCäöüÄÖÜßáÁàÀ♥♦♣♠");
                writer.Write((byte)66);
                writer.Write(0x48484848);
                writer.Write(0x84848484U);
                writer.Write("abcABCäöüÄÖÜßáÁàÀ♥♦♣♠");
            }

            using (MemoryStream ms = new MemoryStream(data))
                using (BinaryReader reader = new BinaryReader(ms))
                {
                    Assert.AreEqual(reader.ReadString(), "abcABCäöüÄÖÜßáÁàÀ♥♦♣♠", "BinaryMemoryReader String incompatible to BinaryReader.");
                    Assert.AreEqual(reader.ReadByte(), (byte)66, "BinaryMemoryReader Byte incompatible to BinaryReader.");
                    Assert.AreEqual(reader.ReadInt32(), 0x48484848, "BinaryMemoryReader Int incompatible to BinaryReader.");
                    Assert.AreEqual(reader.ReadUInt32(), 0x84848484U, "BinaryMemoryReader UInt incompatible to BinaryReader.");
                    Assert.AreEqual(reader.ReadString(), "abcABCäöüÄÖÜßáÁàÀ♥♦♣♠", "BinaryMemoryReader 2nd String incompatible to BinaryReader.");
                }
        }
Example #2
0
        public unsafe void UnsafeBinaryMemoryWriter_Initialize()
        {
            byte[] data = new byte[1];

            fixed(byte *pData = data)
            {
                UnsafeBinaryMemoryWriter writer = new UnsafeBinaryMemoryWriter(pData);

                writer.Write((byte)0x5A);
            }
        }
Example #3
0
        public unsafe void UnsafeBinaryMemoryWriter_Strings()
        {
            byte[] data = new byte[102400];

            fixed(byte *pData = data)
            {
                UnsafeBinaryMemoryWriter writer = new UnsafeBinaryMemoryWriter(pData);

                for (int count = 0; count < 10240; count++)
                {
                    writer.Write("ABCDEFGHI");
                }
            }
        }
Example #4
0
        public unsafe void UnsafeBinaryMemoryWriter_Short()
        {
            byte[] data = new byte[20480];

            fixed(byte *pData = data)
            {
                UnsafeBinaryMemoryWriter writer = new UnsafeBinaryMemoryWriter(pData);

                for (int count = 0; count < 10240; count++)
                {
                    writer.Write((short)0x5AA5);
                }
            }
        }
Example #5
0
        public unsafe void UnsafeBinaryMemoryWriter_Bytes()
        {
            byte[] data = new byte[10240];

            fixed(byte *pData = data)
            {
                UnsafeBinaryMemoryWriter writer = new UnsafeBinaryMemoryWriter(pData);

                for (int count = 0; count < 10240; count++)
                {
                    writer.Write((byte)0x5A);
                }
            }
        }
Example #6
0
        public unsafe void StringWrite()
        {
            foreach (int size in new int[] { 1, 127, 128, 16383, 16384, 2097151, 2097152, 268435455, 268435456, 300000000 })
            {
                byte[] data = new byte[size + 8];

                fixed(byte *pData = data)
                {
                    UnsafeBinaryMemoryWriter writer = new UnsafeBinaryMemoryWriter(pData);

                    writer.Write(new string('A', size));
                }

                using (MemoryStream ms = new MemoryStream(data))
                    using (BinaryReader reader = new BinaryReader(ms))
                        Assert.AreEqual(reader.ReadString(), new string('A', size), "UnsafeBinaryMemoryWriter String incompatible to BinaryWriter.");
            }
        }
Example #7
0
        public unsafe void DecimalWrite()
        {
            byte[] data = new byte[4096];

            fixed(byte *pData = data)
            {
                UnsafeBinaryMemoryWriter writer = new UnsafeBinaryMemoryWriter(pData);

                for (int count = 0; count < 256; count++)
                {
                    writer.Write(count * 12347822345.34m);
                }
            }

            using (MemoryStream ms = new MemoryStream(data))
                using (BinaryReader reader = new BinaryReader(ms))
                    for (int count = 0; count < 256; count++)
                    {
                        Assert.AreEqual(reader.ReadDecimal(), count * 12347822345.34m, "UnsafeBinaryMemoryWriter Decimal incompatible to BinaryWriter.");
                    }
        }
Example #8
0
        public unsafe void DoubleWrite()
        {
            byte[] data = new byte[2048];

            fixed(byte *pData = data)
            {
                UnsafeBinaryMemoryWriter writer = new UnsafeBinaryMemoryWriter(pData);

                for (int count = 0; count < 256; count++)
                {
                    writer.Write((double)count);
                }
            }

            using (MemoryStream ms = new MemoryStream(data))
                using (BinaryReader reader = new BinaryReader(ms))
                    for (int count = 0; count < 256; count++)
                    {
                        Assert.AreEqual(reader.ReadDouble(), count, "UnsafeBinaryMemoryWriter Double incompatible to BinaryWriter.");
                    }
        }
Example #9
0
        public unsafe void UIntWrite()
        {
            byte[] data = new byte[1024];

            fixed(byte *pData = data)
            {
                UnsafeBinaryMemoryWriter writer = new UnsafeBinaryMemoryWriter(pData);

                for (int count = 0; count < 256; count++)
                {
                    writer.Write((uint)count);
                }
            }

            using (MemoryStream ms = new MemoryStream(data))
                using (BinaryReader reader = new BinaryReader(ms))
                    for (int count = 0; count < 256; count++)
                    {
                        Assert.AreEqual(reader.ReadUInt32(), (uint)count, "UnsafeBinaryMemoryWriter UInt incompatible to BinaryWriter.");
                    }
        }
Example #10
0
        public unsafe void BooleanWrite()
        {
            byte[] data = new byte[256];

            fixed(byte *pData = data)
            {
                UnsafeBinaryMemoryWriter writer = new UnsafeBinaryMemoryWriter(pData);

                for (int count = 0; count < 256; count++)
                {
                    writer.Write(count % 2 == 0);
                }
            }

            using (MemoryStream ms = new MemoryStream(data))
                using (BinaryReader reader = new BinaryReader(ms))
                    for (int count = 0; count < 256; count++)
                    {
                        Assert.AreEqual(reader.ReadBoolean(), count % 2 == 0, "UnsafeBinaryMemoryWriter Boolean incompatible to BinaryWriter.");
                    }
        }