private unsafe void WriteBuf(SketchBinaryWriter w, byte[] buf) { fixed(byte *pbuf = buf) { w.Write((IntPtr)pbuf, buf.Length); } }
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()); } }