public override void Randomize() { int arraylength = -1; Random rand = new Random(); int strlength; byte[] strbuf, myByte; //bools arraylength = rand.Next(10); if (bools == null) { bools = new Messages.dynamic_reconfigure.BoolParameter[arraylength]; } else { Array.Resize(ref bools, arraylength); } for (int i = 0; i < bools.Length; i++) { //bools[i] bools[i] = new Messages.dynamic_reconfigure.BoolParameter(); bools[i].Randomize(); } //ints arraylength = rand.Next(10); if (ints == null) { ints = new Messages.dynamic_reconfigure.IntParameter[arraylength]; } else { Array.Resize(ref ints, arraylength); } for (int i = 0; i < ints.Length; i++) { //ints[i] ints[i] = new Messages.dynamic_reconfigure.IntParameter(); ints[i].Randomize(); } //strs arraylength = rand.Next(10); if (strs == null) { strs = new Messages.dynamic_reconfigure.StrParameter[arraylength]; } else { Array.Resize(ref strs, arraylength); } for (int i = 0; i < strs.Length; i++) { //strs[i] strs[i] = new Messages.dynamic_reconfigure.StrParameter(); strs[i].Randomize(); } //doubles arraylength = rand.Next(10); if (doubles == null) { doubles = new Messages.dynamic_reconfigure.DoubleParameter[arraylength]; } else { Array.Resize(ref doubles, arraylength); } for (int i = 0; i < doubles.Length; i++) { //doubles[i] doubles[i] = new Messages.dynamic_reconfigure.DoubleParameter(); doubles[i].Randomize(); } //groups arraylength = rand.Next(10); if (groups == null) { groups = new Messages.dynamic_reconfigure.GroupState[arraylength]; } else { Array.Resize(ref groups, arraylength); } for (int i = 0; i < groups.Length; i++) { //groups[i] groups[i] = new Messages.dynamic_reconfigure.GroupState(); groups[i].Randomize(); } }
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; //bools hasmetacomponents |= true; arraylength = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex); currentIndex += Marshal.SizeOf(typeof(System.Int32)); if (bools == null) { bools = new Messages.dynamic_reconfigure.BoolParameter[arraylength]; } else { Array.Resize(ref bools, arraylength); } for (int i = 0; i < bools.Length; i++) { //bools[i] bools[i] = new Messages.dynamic_reconfigure.BoolParameter(SERIALIZEDSTUFF, ref currentIndex); } //ints hasmetacomponents |= true; arraylength = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex); currentIndex += Marshal.SizeOf(typeof(System.Int32)); if (ints == null) { ints = new Messages.dynamic_reconfigure.IntParameter[arraylength]; } else { Array.Resize(ref ints, arraylength); } for (int i = 0; i < ints.Length; i++) { //ints[i] ints[i] = new Messages.dynamic_reconfigure.IntParameter(SERIALIZEDSTUFF, ref currentIndex); } //strs hasmetacomponents |= true; arraylength = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex); currentIndex += Marshal.SizeOf(typeof(System.Int32)); if (strs == null) { strs = new Messages.dynamic_reconfigure.StrParameter[arraylength]; } else { Array.Resize(ref strs, arraylength); } for (int i = 0; i < strs.Length; i++) { //strs[i] strs[i] = new Messages.dynamic_reconfigure.StrParameter(SERIALIZEDSTUFF, ref currentIndex); } //doubles hasmetacomponents |= true; arraylength = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex); currentIndex += Marshal.SizeOf(typeof(System.Int32)); if (doubles == null) { doubles = new Messages.dynamic_reconfigure.DoubleParameter[arraylength]; } else { Array.Resize(ref doubles, arraylength); } for (int i = 0; i < doubles.Length; i++) { //doubles[i] doubles[i] = new Messages.dynamic_reconfigure.DoubleParameter(SERIALIZEDSTUFF, ref currentIndex); } //groups hasmetacomponents |= true; arraylength = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex); currentIndex += Marshal.SizeOf(typeof(System.Int32)); if (groups == null) { groups = new Messages.dynamic_reconfigure.GroupState[arraylength]; } else { Array.Resize(ref groups, arraylength); } for (int i = 0; i < groups.Length; i++) { //groups[i] groups[i] = new Messages.dynamic_reconfigure.GroupState(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; //bools hasmetacomponents |= true; if (bools == null) { bools = new Messages.dynamic_reconfigure.BoolParameter[0]; } pieces.Add(BitConverter.GetBytes(bools.Length)); for (int i = 0; i < bools.Length; i++) { //bools[i] if (bools[i] == null) { bools[i] = new Messages.dynamic_reconfigure.BoolParameter(); } pieces.Add(bools[i].Serialize(true)); } //ints hasmetacomponents |= true; if (ints == null) { ints = new Messages.dynamic_reconfigure.IntParameter[0]; } pieces.Add(BitConverter.GetBytes(ints.Length)); for (int i = 0; i < ints.Length; i++) { //ints[i] if (ints[i] == null) { ints[i] = new Messages.dynamic_reconfigure.IntParameter(); } pieces.Add(ints[i].Serialize(true)); } //strs hasmetacomponents |= true; if (strs == null) { strs = new Messages.dynamic_reconfigure.StrParameter[0]; } pieces.Add(BitConverter.GetBytes(strs.Length)); for (int i = 0; i < strs.Length; i++) { //strs[i] if (strs[i] == null) { strs[i] = new Messages.dynamic_reconfigure.StrParameter(); } pieces.Add(strs[i].Serialize(true)); } //doubles hasmetacomponents |= true; if (doubles == null) { doubles = new Messages.dynamic_reconfigure.DoubleParameter[0]; } pieces.Add(BitConverter.GetBytes(doubles.Length)); for (int i = 0; i < doubles.Length; i++) { //doubles[i] if (doubles[i] == null) { doubles[i] = new Messages.dynamic_reconfigure.DoubleParameter(); } pieces.Add(doubles[i].Serialize(true)); } //groups hasmetacomponents |= true; if (groups == null) { groups = new Messages.dynamic_reconfigure.GroupState[0]; } pieces.Add(BitConverter.GetBytes(groups.Length)); for (int i = 0; i < groups.Length; i++) { //groups[i] if (groups[i] == null) { groups[i] = new Messages.dynamic_reconfigure.GroupState(); } pieces.Add(groups[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); }