public override void Deserialize(byte[] SERIALIZEDSTUFF, ref int currentIndex) { int arraylength = -1; bool hasmetacomponents = false; object __thing; int piecesize = 0; byte[] thischunk, scratch1, scratch2; IntPtr h; //robots hasmetacomponents |= false; arraylength = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex); currentIndex += Marshal.SizeOf(typeof(System.Int32)); if (robots == null) { robots = new int[arraylength]; } else { Array.Resize(ref robots, arraylength); } for (int i = 0; i < robots.Length; i++) { //robots[i] piecesize = Marshal.SizeOf(typeof(int)); h = IntPtr.Zero; if (SERIALIZEDSTUFF.Length - currentIndex != 0) { h = Marshal.AllocHGlobal(piecesize); Marshal.Copy(SERIALIZEDSTUFF, currentIndex, h, piecesize); } if (h == IntPtr.Zero) { throw new Exception("Alloc failed"); } robots[i] = (int)Marshal.PtrToStructure(h, typeof(int)); Marshal.FreeHGlobal(h); currentIndex += piecesize; } //path hasmetacomponents |= true; arraylength = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex); currentIndex += Marshal.SizeOf(typeof(System.Int32)); if (path == null) { path = new Messages.wpf_msgs.Point2[arraylength]; } else { Array.Resize(ref path, arraylength); } for (int i = 0; i < path.Length; i++) { //path[i] path[i] = new Messages.wpf_msgs.Point2(SERIALIZEDSTUFF, ref currentIndex); } }
public override byte[] Serialize(bool partofsomethingelse) { int currentIndex = 0, length = 0; bool hasmetacomponents = false; byte[] thischunk, scratch1, scratch2; List <byte[]> pieces = new List <byte[]>(); GCHandle h; //robots hasmetacomponents |= false; if (robots == null) { robots = new int[0]; } pieces.Add(BitConverter.GetBytes(robots.Length)); for (int i = 0; i < robots.Length; i++) { //robots[i] scratch1 = new byte[Marshal.SizeOf(typeof(int))]; h = GCHandle.Alloc(scratch1, GCHandleType.Pinned); Marshal.StructureToPtr(robots[i], h.AddrOfPinnedObject(), false); h.Free(); pieces.Add(scratch1); } //path hasmetacomponents |= true; if (path == null) { path = new Messages.wpf_msgs.Point2[0]; } pieces.Add(BitConverter.GetBytes(path.Length)); for (int i = 0; i < path.Length; i++) { //path[i] if (path[i] == null) { path[i] = new Messages.wpf_msgs.Point2(); } pieces.Add(path[i].Serialize(true)); } //combine every array in pieces into one array and return it int __a_b__f = pieces.Sum((__a_b__c) => __a_b__c.Length); int __a_b__e = 0; byte[] __a_b__d = new byte[__a_b__f]; foreach (var __p__ in pieces) { Array.Copy(__p__, 0, __a_b__d, __a_b__e, __p__.Length); __a_b__e += __p__.Length; } return(__a_b__d); }
public override void Deserialize(byte[] SERIALIZEDSTUFF, ref int currentIndex) { int arraylength = -1; bool hasmetacomponents = false; object __thing; int piecesize = 0; byte[] thischunk, scratch1, scratch2; IntPtr h; //topleft topleft = new Messages.wpf_msgs.Point2(SERIALIZEDSTUFF, ref currentIndex); //bottomright bottomright = new Messages.wpf_msgs.Point2(SERIALIZEDSTUFF, ref currentIndex); //width piecesize = Marshal.SizeOf(typeof(Single)); h = IntPtr.Zero; if (SERIALIZEDSTUFF.Length - currentIndex != 0) { h = Marshal.AllocHGlobal(piecesize); Marshal.Copy(SERIALIZEDSTUFF, currentIndex, h, piecesize); } if (h == IntPtr.Zero) { throw new Exception("Alloc failed"); } width = (Single)Marshal.PtrToStructure(h, typeof(Single)); Marshal.FreeHGlobal(h); currentIndex += piecesize; //height piecesize = Marshal.SizeOf(typeof(Single)); h = IntPtr.Zero; if (SERIALIZEDSTUFF.Length - currentIndex != 0) { h = Marshal.AllocHGlobal(piecesize); Marshal.Copy(SERIALIZEDSTUFF, currentIndex, h, piecesize); } if (h == IntPtr.Zero) { throw new Exception("Alloc failed"); } height = (Single)Marshal.PtrToStructure(h, typeof(Single)); Marshal.FreeHGlobal(h); currentIndex += piecesize; }
public override byte[] Serialize(bool partofsomethingelse) { int currentIndex = 0, length = 0; bool hasmetacomponents = false; byte[] thischunk, scratch1, scratch2; List <byte[]> pieces = new List <byte[]>(); GCHandle h; //topleft if (topleft == null) { topleft = new Messages.wpf_msgs.Point2(); } pieces.Add(topleft.Serialize(true)); //bottomright if (bottomright == null) { bottomright = new Messages.wpf_msgs.Point2(); } pieces.Add(bottomright.Serialize(true)); //width scratch1 = new byte[Marshal.SizeOf(typeof(Single))]; h = GCHandle.Alloc(scratch1, GCHandleType.Pinned); Marshal.StructureToPtr(width, h.AddrOfPinnedObject(), false); h.Free(); pieces.Add(scratch1); //height scratch1 = new byte[Marshal.SizeOf(typeof(Single))]; h = GCHandle.Alloc(scratch1, GCHandleType.Pinned); Marshal.StructureToPtr(height, h.AddrOfPinnedObject(), false); h.Free(); pieces.Add(scratch1); //combine every array in pieces into one array and return it int __a_b__f = pieces.Sum((__a_b__c) => __a_b__c.Length); int __a_b__e = 0; byte[] __a_b__d = new byte[__a_b__f]; foreach (var __p__ in pieces) { Array.Copy(__p__, 0, __a_b__d, __a_b__e, __p__.Length); __a_b__e += __p__.Length; } return(__a_b__d); }
public override void Randomize() { int arraylength = -1; Random rand = new Random(); int strlength; byte[] strbuf, myByte; //topleft topleft = new Messages.wpf_msgs.Point2(); topleft.Randomize(); //bottomright bottomright = new Messages.wpf_msgs.Point2(); bottomright.Randomize(); //width width = (float)(rand.Next() + rand.NextDouble()); //height height = (float)(rand.Next() + rand.NextDouble()); }
public override void Randomize() { int arraylength = -1; Random rand = new Random(); int strlength; byte[] strbuf, myByte; //robots arraylength = rand.Next(10); if (robots == null) { robots = new int[arraylength]; } else { Array.Resize(ref robots, arraylength); } for (int i = 0; i < robots.Length; i++) { //robots[i] robots[i] = rand.Next(); } //path arraylength = rand.Next(10); if (path == null) { path = new Messages.wpf_msgs.Point2[arraylength]; } else { Array.Resize(ref path, arraylength); } for (int i = 0; i < path.Length; i++) { //path[i] path[i] = new Messages.wpf_msgs.Point2(); path[i].Randomize(); } }