/// <summary> /// Deserialize from file to AvroHttpRequest object. /// </summary> /// <param name="fileName">Name of the file.</param> /// <returns>AvroHttpRequest.</returns> public static AvroHttpRequest FromFile(string fileName) { var str = File.ReadAllText(fileName); AvroHttpRequest avroHttprequest = JsonConvert.DeserializeObject <AvroHttpRequest>(str); return(avroHttprequest); }
/// <summary> /// Serialize AvroHttpRequest object into bytes /// </summary> /// <param name="obj">The object.</param> /// <returns>System.Byte[].</returns> public static byte[] ToBytes(AvroHttpRequest obj) { var serializer = AvroSerializer.Create<AvroHttpRequest>(); using (MemoryStream stream = new MemoryStream()) { serializer.Serialize(stream, obj); return stream.GetBuffer(); } }
/// <summary> /// Serialize AvroHttpRequest in to file /// </summary> /// <param name="avroHttprequest">The avro httprequest.</param> /// <param name="fileName">Name of the file.</param> public static void ToFile(AvroHttpRequest avroHttprequest, string fileName) { var bytes = ToBytes(avroHttprequest); using (var file = File.OpenWrite(fileName)) { file.Write(bytes, 0, bytes.Length); } }
/// <summary> /// Serialize AvroHttpRequest object into bytes /// </summary> /// <param name="obj">The object.</param> /// <returns>System.Byte[].</returns> public static byte[] ToBytes(AvroHttpRequest obj) { var serializer = AvroSerializer.Create <AvroHttpRequest>(); using (MemoryStream stream = new MemoryStream()) { serializer.Serialize(stream, obj); return(stream.GetBuffer()); } }
/// <summary> /// Creates an Avro HTTP request for unit tests. /// </summary> /// <returns>AvroHttpRequest.</returns> private AvroHttpRequest CreateAvroHttpRequest() { AvroHttpRequest r = new AvroHttpRequest(); r.Header = new List<HeaderEntry>(); HeaderEntry he1 = new HeaderEntry(); he1.key = "a"; he1.value = "xxx"; HeaderEntry he2 = new HeaderEntry(); he2.key = "b"; he2.value = "yyy"; r.Header.Add(he1); r.Header.Add(he2); r.HttpMethod = "POST"; r.InputStream = ByteUtilities.StringToByteArrays("test binary stream data"); r.PathInfo = "/reef/evaluators"; r.QueryString = "id=12&id=34&a=b"; r.RequestUrl = "http://localhost:8080/reef/evaluators?id=12&id=34&a=b"; return r; }
/// <summary> /// Convert from AvroHttpRequest to Json string /// </summary> /// <param name="httpRequest">The HTTP request.</param> /// <returns>System.String.</returns> public static string ToJson(AvroHttpRequest httpRequest) { return JsonConvert.SerializeObject(httpRequest); }
/// <summary> /// Convert from AvroHttpRequest to Json string /// </summary> /// <param name="httpRequest">The HTTP request.</param> /// <returns>System.String.</returns> public static string ToJson(AvroHttpRequest httpRequest) { return(JsonConvert.SerializeObject(httpRequest)); }