/// <summary> /// Deserializes a <see cref="ArgCollection" /> instance from a byte array previously /// generated by a call to <see cref="ToBytes" />. /// </summary> /// <param name="input">The input array.</param> /// <returns>The deserialized <see cref="ArgCollection" /> instance.</returns> /// <exception cref="ArgumentException">Thrown if <paramref name="input" /> is <c>null</c>.</exception> /// <exception cref="FormatException">Thrown if the input data is not valid.</exception> public static ArgCollection FromBytes(byte[] input) { using (var ms = new EnhancedMemoryStream(input)) { return(new ArgCollection(ms)); } }
/// <summary> /// Serializes a <see cref="ArgCollection" /> instance to a byte array. /// </summary> /// <param name="input">The input <see cref="ArgCollection" />.</param> /// <returns>The serialized byte array.</returns> /// <exception cref="ArgumentException">Thrown if <paramref name="input" /> is <c>null</c>.</exception> public static byte[] ToBytes(ArgCollection input) { using (var ms = new EnhancedMemoryStream()) { input.Write(ms); return(ms.ToArray()); } }
/// <summary> /// Reads the text from the HTTP response stream passed. /// </summary> /// <param name="stream">The response stream.</param> /// <returns>The text read.</returns> private static string ReadText(Stream stream) { var ms = new EnhancedMemoryStream(); ms.CopyFrom(stream, -1); ms.Position = 0; return(ms.ReadAllText(Encoding.ASCII).Trim()); }