/// <summary> /// Reads a <c>UpdatePosition</c> type PositionUpdate message. /// </summary> /// <param name="buffer">The byte array containing data.</param> /// <param name="length">The length of the message.</param> /// <returns>The PositionUpdate.</returns> public static PositionUpdate ReadUpdatePosition(byte[] buffer, int length) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (buffer.Length < length) { throw new ArgumentOutOfRangeException("buffer", buffer, "The buffer is not long enough to contain a message of the specified length."); } if (length < 16) { return(null); } float x = MessageProcessor.ReadSingle(buffer, 0); float y = MessageProcessor.ReadSingle(buffer, 4); Vector2 coordinate = new Vector2(x, y); float rotation = MessageProcessor.ReadSingle(buffer, 8); int id = MessageProcessor.ReadInt32(buffer, 12); PositionUpdate update = new PositionUpdate(UpdateType.UpdatePosition, coordinate, rotation, id); if (id > 200 || id < 0) { throw new ArgumentOutOfRangeException("Received message is not sane: " + update); } return(update); }
/// <summary> /// Reads an <see cref="ARViewUpdate"/> message from the given byte array. /// </summary> /// <param name="bytes">The byte array to read from.</param> /// <param name="length">The maximum amount of bytes to read.</param> /// <returns>The created <see cref="ARViewUpdate"/>.</returns> public static ARViewUpdate ReadARViewUpdate(byte[] bytes, int length) { Assert.IsNotNull(bytes); Assert.IsFalse(length < 28, "ARViewUpdate length needs to be at least 28"); Assert.IsFalse(bytes.Length < length, "byte array length is insufficient"); int id = MessageProcessor.ReadInt32(bytes, 0); Vector3 position = new Vector3( MessageProcessor.ReadSingle(bytes, 4), MessageProcessor.ReadSingle(bytes, 8), MessageProcessor.ReadSingle(bytes, 12)); Vector3 rotation = new Vector3( MessageProcessor.ReadSingle(bytes, 16), MessageProcessor.ReadSingle(bytes, 20), MessageProcessor.ReadSingle(bytes, 24)); return(new ARViewUpdate(id, position, rotation)); }
/// <summary> /// Reads a <c>UpdateRotation</c> type RotationUpdate message. /// </summary> /// <param name="buffer">The byte array containing data.</param> /// <param name="length">The length of the message.</param> /// <returns>The RotationUpdate.</returns> public static RotationUpdate ReadUpdateRotation(byte[] buffer, int length) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (buffer.Length < length) { throw new ArgumentOutOfRangeException("buffer", buffer, "The buffer is not long enough to contain a message of the specified length."); } if (length < 8) { return(null); } int id = MessageProcessor.ReadInt32(buffer, 0); float rotation = MessageProcessor.ReadSingle(buffer, 4); return(new RotationUpdate(UpdateType.UpdateRotation, rotation, id)); }
/// <summary> /// Reads a <c>UpdateRotation</c> type RotationUpdate message. /// </summary> /// <param name="buffer">The byte array containing data.</param> /// <param name="length">The length of the message.</param> /// <returns>The RotationUpdate.</returns> public static LevelUpdate ReadUpdateLevel(byte[] buffer, int length) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (buffer.Length < length) { throw new ArgumentOutOfRangeException("buffer", buffer, "The buffer is not long enough to contain a message of the specified length."); } if (length < 16) { return(null); } int index = MessageProcessor.ReadInt32(buffer, 0); int time = MessageProcessor.ReadInt32(buffer, 4); float width = MessageProcessor.ReadSingle(buffer, 8); float height = MessageProcessor.ReadSingle(buffer, 12); return(new LevelUpdate(index, new Vector2(width, height), time)); }