public override void Randomize() { Random rand = new Random(); int strlength; byte[] strbuf, myByte; //goal_id goal_id = new Messages.actionlib_msgs.GoalID(); goal_id.Randomize(); //status myByte = new byte[1]; rand.NextBytes(myByte); status = myByte[0]; //text strlength = rand.Next(100) + 1; strbuf = new byte[strlength]; rand.NextBytes(strbuf); //fill the whole buffer with random bytes for (int __x__ = 0; __x__ < strlength; __x__++) { if (strbuf[__x__] == 0) //replace null chars with non-null random ones { strbuf[__x__] = (byte)(rand.Next(254) + 1); } } strbuf[strlength - 1] = 0; //null terminate text = Encoding.ASCII.GetString(strbuf); }
public override void Deserialize(byte[] serializedMessage, ref int currentIndex) { int piecesize = 0; //goal_id goal_id = new Messages.actionlib_msgs.GoalID(serializedMessage, ref currentIndex); //status status = serializedMessage[currentIndex++]; //text text = ""; piecesize = BitConverter.ToInt32(serializedMessage, currentIndex); currentIndex += 4; text = Encoding.ASCII.GetString(serializedMessage, currentIndex, piecesize); currentIndex += piecesize; }
public override byte[] Serialize(bool partofsomethingelse) { byte[] thischunk, scratch1, scratch2; List <byte[]> pieces = new List <byte[]>(); //goal_id if (goal_id == null) { goal_id = new Messages.actionlib_msgs.GoalID(); } pieces.Add(goal_id.Serialize(true)); //status pieces.Add(new[] { (byte)status }); //text if (text == null) { text = ""; } scratch1 = Encoding.ASCII.GetBytes((string)text); thischunk = new byte[scratch1.Length + 4]; scratch2 = BitConverter.GetBytes(scratch1.Length); Array.Copy(scratch1, 0, thischunk, 4, scratch1.Length); Array.Copy(scratch2, thischunk, 4); pieces.Add(thischunk); // 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); }