/// <summary> /// Creates a user data header out of information elements. /// </summary> /// <param name="elements">The <see cref="T:GSMCommunication.PDUDecoder.SmartMessaging.InformationElement" /> instances to be stored in the header.</param> /// <returns>A byte array containing the user data header.</returns> /// <exception cref="T:System.ArgumentNullException">elements is null.</exception> /// <exception cref="T:System.ArgumentException">The sum of all elements is too large, size exceeds 255 bytes.</exception> public static byte[] CreateUserDataHeader(InformationElement[] elements) { if (elements != null) { List <byte> nums = new List <byte>(); nums.Add(0); int length = 0; InformationElement[] informationElementArray = elements; for (int i = 0; i < (int)informationElementArray.Length; i++) { InformationElement informationElement = informationElementArray[i]; byte[] byteArray = informationElement.ToByteArray(); nums.AddRange(byteArray); length = length + (int)byteArray.Length; } if (length <= 255) { nums[0] = (byte)length; return(nums.ToArray()); } else { throw new ArgumentException("The sum of all elements is too large, size exceeds 255 bytes."); } } else { throw new ArgumentNullException("elements"); } }
/// <summary> /// Creates a user data header out of information elements. /// </summary> /// <param name="element">The <see cref="T:GSMCommunication.PDUDecoder.SmartMessaging.InformationElement" /> instance to be stored in the header.</param> /// <returns>A byte array containing the user data header.</returns> /// <exception cref="T:System.ArgumentNullException">element is null.</exception> /// <exception cref="T:System.ArgumentException">Element is too large, size exceeds 255 bytes.</exception> public static byte[] CreateUserDataHeader(InformationElement element) { if (element != null) { byte[] byteArray = element.ToByteArray(); if ((int)byteArray.Length <= 255) { byte[] length = new byte[(int)byteArray.Length + 1]; length[0] = (byte)((int)byteArray.Length); byteArray.CopyTo(length, 1); return(length); } else { throw new ArgumentException("Element is to large, size exceeds 255 bytes."); } } else { throw new ArgumentNullException("element"); } }
/// <summary> /// Creates a user data header out of information elements. /// </summary> /// <param name="element">The <see cref="T:GSMCommunication.PDUDecoder.SmartMessaging.InformationElement" /> instance to be stored in the header.</param> /// <returns>A byte array containing the user data header.</returns> /// <exception cref="T:System.ArgumentNullException">element is null.</exception> /// <exception cref="T:System.ArgumentException">Element is too large, size exceeds 255 bytes.</exception> public static byte[] CreateUserDataHeader(InformationElement element) { if (element != null) { byte[] byteArray = element.ToByteArray(); if ((int)byteArray.Length <= 255) { byte[] length = new byte[(int)byteArray.Length + 1]; length[0] = (byte)((int)byteArray.Length); byteArray.CopyTo(length, 1); return length; } else { throw new ArgumentException("Element is to large, size exceeds 255 bytes."); } } else { throw new ArgumentNullException("element"); } }