/// <summary> /// /// </summary> /// <param name="bytController"></param> /// <param name="cntlMsgs"></param> /// <param name="strControllerData"></param> public static void DecodeControllerData(byte[] bytController, ref ControllerMessages cntlMsgs) { //UnityEngine.Debug.Log("Entered DecodeControllerData()"); int intMsgType = 0; MemoryStream stream = new MemoryStream(bytController); using (EndianAwareBinaryReader reader = new EndianAwareBinaryReader(stream, false)) { while (reader.BaseStream.Position < reader.BaseStream.Length) { intMsgType = reader.ReadInt32(); //UnityEngine.Debug.Log("intMsgType = " + intMsgType); if (intMsgType == ViewerConstants.MESSAGE_TOUCH_INPUT) { UnityEngine.Debug.Log("reading touch"); cntlMsgs.TouchMessage.X = reader.ReadSingle(); cntlMsgs.TouchMessage.Y = reader.ReadSingle(); cntlMsgs.TouchMessage.Timestamp = reader.ReadInt64(); cntlMsgs.TouchMessage.Pointer = reader.ReadInt32(); cntlMsgs.TouchMessage.Active = reader.ReadInt32(); } else if (intMsgType == ViewerConstants.MESSAGE_ACCELEROMETER_INPUT) { //UnityEngine.Debug.Log("reading accel"); cntlMsgs.AccelMessage.X = reader.ReadSingle(); cntlMsgs.AccelMessage.Y = reader.ReadSingle(); cntlMsgs.AccelMessage.Z = reader.ReadSingle(); cntlMsgs.AccelMessage.Timestamp = reader.ReadInt32(); } else if (intMsgType == ViewerConstants.MESSAGE_MAGNOTOMETER_INPUT) { //UnityEngine.Debug.Log("reading magnotometer"); cntlMsgs.MagnoMessage.X = reader.ReadSingle(); cntlMsgs.MagnoMessage.Y = reader.ReadSingle(); cntlMsgs.MagnoMessage.Z = reader.ReadSingle(); cntlMsgs.MagnoMessage.Timestamp = reader.ReadInt32(); } else if (intMsgType == ViewerConstants.MESSAGE_ATTITUDE_INPUT) { //UnityEngine.Debug.Log("reading attitude"); cntlMsgs.AttMessage.X = reader.ReadSingle(); cntlMsgs.AttMessage.Y = reader.ReadSingle(); cntlMsgs.AttMessage.Z = reader.ReadSingle(); cntlMsgs.AttMessage.Timestamp = reader.ReadInt32(); } else if (intMsgType == ViewerConstants.MESSAGE_TRACKBALL_INPUT) { UnityEngine.Debug.Log("reading trackball"); cntlMsgs.TrackMessage.X = reader.ReadSingle(); cntlMsgs.TrackMessage.Y = reader.ReadSingle(); } else if (intMsgType == ViewerConstants.MESSAGE_OPTIONS) { UnityEngine.Debug.Log("reading options"); cntlMsgs.OptionMessage.ScreenWidth = reader.ReadInt32(); cntlMsgs.OptionMessage.ScreenHeight = reader.ReadInt32(); } else if (intMsgType == ViewerConstants.MESSAGE_KEY) { UnityEngine.Debug.Log("reading keys"); cntlMsgs.KeyMessage.State = reader.ReadInt32(); cntlMsgs.KeyMessage.Key = reader.ReadInt32(); cntlMsgs.KeyMessage.Unicode = reader.ReadInt32(); } } } }
public object Deserialize(EndianAwareBinaryReader reader, SerializedType serializedType, int?length = null) { int?effectiveLength = null; var typeParent = TypeNode.Parent as TypeNode; if (length != null) { effectiveLength = length.Value; } else if (TypeNode.FieldLengthBinding != null) { object lengthValue = TypeNode.FieldLengthBinding.GetValue(this); effectiveLength = Convert.ToInt32(lengthValue); } else if (typeParent != null && typeParent.ItemLengthBinding != null) { object lengthValue = typeParent.ItemLengthBinding.GetValue((ValueNode)Parent); effectiveLength = Convert.ToInt32(lengthValue); } else if (TypeNode.FieldCountBinding != null) { object countValue = TypeNode.FieldCountBinding.GetValue(this); effectiveLength = Convert.ToInt32(countValue); } else if (serializedType == SerializedType.ByteArray || serializedType == SerializedType.SizedString) { checked { effectiveLength = (int)_remainder; } } object value; switch (serializedType) { case SerializedType.Int1: value = reader.ReadSByte(); break; case SerializedType.UInt1: value = reader.ReadByte(GetBitSize()); break; case SerializedType.Int2: value = reader.ReadInt16(); break; case SerializedType.UInt2: value = reader.ReadUInt16(); break; case SerializedType.Int4: value = reader.ReadInt32(); break; case SerializedType.UInt4: value = reader.ReadUInt32(); break; case SerializedType.Int8: value = reader.ReadInt64(); break; case SerializedType.UInt8: value = reader.ReadUInt64(); break; case SerializedType.Float4: value = reader.ReadSingle(); break; case SerializedType.Float8: value = reader.ReadDouble(); break; case SerializedType.ByteArray: { Debug.Assert(effectiveLength != null, "effectiveLength != null"); value = reader.ReadBytes(effectiveLength.Value); break; } case SerializedType.NullTerminatedString: { byte[] data = ReadNullTerminatedString(reader).ToArray(); value = Encoding.GetString(data, 0, data.Length); break; } case SerializedType.SizedString: { Debug.Assert(effectiveLength != null, "effectiveLength != null"); byte[] data = reader.ReadBytes(effectiveLength.Value); value = Encoding.GetString(data, 0, data.Length).TrimEnd('\0'); break; } case SerializedType.LengthPrefixedString: { value = reader.ReadString(); break; } default: throw new NotSupportedException(); } return(value); }