public IRequest Deserialize(Stream stream) { using (StreamReader reader = new StreamReader(stream, Encoding.Unicode)) { RequestHeader header = DeserializeHeader(reader); IRequestMethod method = DeserializeMethod(reader, header.MethodSize, header.MethodType); return(new Request { Header = header, Method = method }); } }
public void Serialize(IRequestMethod method, Stream stream) { string requestMethod = JsonConvert.SerializeObject(method); string requestHeader = JsonConvert.SerializeObject(new RequestHeader { MethodSize = requestMethod.Length, MethodType = method.GetType() }); string fullRequest = requestHeader + "\r\n\r\n" + requestMethod; StreamWriter writer = new StreamWriter(stream, Encoding.Unicode); writer.Write(fullRequest); writer.Flush(); }