Exemple #1
0
 private unsafe void WriteBuf(SketchBinaryWriter w, byte[] buf)
 {
     fixed(byte *pbuf = buf)
     {
         w.Write((IntPtr)pbuf, buf.Length);
     }
 }
Exemple #2
0
        static MemoryStream GetStreamWithData(params int[] ints)
        {
            var ret = new MemoryStream();

            using (var writer = new SketchBinaryWriter(ret)) {
                foreach (var i in ints)
                {
                    writer.Int32(i);
                }
            }
            ret.Position = 0;
            return(ret);
        }
Exemple #3
0
        public unsafe void TestSketchBinaryWriter()
        {
            byte[] b0    = MakeData(0);
            byte[] b10   = MakeData(10);
            byte[] b5000 = MakeData(5000);

            using (var astr = new MemoryStream())
                using (var bstr = new MemoryStream())
                    using (var aw = new BinaryWriter(astr, System.Text.Encoding.UTF8))
                    {
                        var        bw = new SketchBinaryWriter(bstr);
                        Quaternion q1 = new Quaternion(4.1f, 4.2f, 4.3f, 4.4f);
                        Quaternion q2 = new Quaternion(2.5f, 3.5f, 4.5f, 5.3f);

                        aw.Write(0x7123abcd);
                        aw.Write(0xdb1f117eu);
                        aw.Write(-0f);
                        aw.Write(-1f);
                        aw.Write(1e27f);
                        aw.Write(q1.x);
                        aw.Write(q1.y);
                        aw.Write(q1.z);
                        aw.Write(q1.w);
                        aw.Write(q2.x);
                        aw.Write(q2.y);
                        aw.Write(q2.z);
                        aw.Write(q2.w);
                        aw.Flush();
                        astr.Write(b0, 0, b0.Length);
                        astr.Write(b10, 0, b10.Length);
                        astr.Write(b5000, 0, b5000.Length);

                        bw.Int32(0x7123abcd);
                        bw.UInt32(0xdb1f117eu);
                        bw.Vec3(new Vector3(-0f, -1f, 1e27f));
                        bw.Quaternion(q1);
                        Quaternion *pq2 = &q2;
                        bw.Write((IntPtr)pq2, sizeof(Quaternion));
                        WriteBuf(bw, b0);
                        WriteBuf(bw, b10);
                        WriteBuf(bw, b5000);

                        Assert.AreEqual(astr.ToArray(), bstr.ToArray());
                    }
        }
Exemple #4
0
        public void TestListRoundTrip()
        {
            // Test a list going into and out of the stream.
            List <Vector3> lst = MathTestUtils.RandomVector3List(20);

            MemoryStream stream = new MemoryStream();

            using (var writer = new SketchBinaryWriter(stream)) {
                writer.WriteLengthPrefixed(lst);
                writer.BaseStream = null;
            }

            stream.Position = 0;
            List <Vector3> lst2 = new List <Vector3>();

            using (var reader = new SketchBinaryReader(stream)) {
                Assert.IsTrue(reader.ReadIntoExact(lst2, lst.Count));
            }
            Assert.AreEqual(lst, lst2);
        }
Exemple #5
0
        public void TestBaseStream()
        {
            // Quick test that BaseStream works as advertised

            MemoryStream stream = new MemoryStream();

            using (var writer = new SketchBinaryWriter(null)) {
                writer.BaseStream = stream;
                writer.Int32(12);
                Assert.IsTrue(stream.Position == 4);
                writer.BaseStream = null;
                Assert.Catch <Exception>(() => writer.Int32(12));
            }

            stream.Position = 0;
            using (var reader = new SketchBinaryReader(null)) {
                reader.BaseStream = stream;
                Assert.AreEqual(12, reader.Int32());
                reader.BaseStream = null;
                Assert.Catch <Exception>(() => reader.Int32());
            }
        }