public static T FromJson(string json) { TMemoryBuffer trans = new TMemoryBuffer(Encoding.UTF8.GetBytes(json)); TProtocol prot = new TSimpleJSONProtocol(trans); return(Proto <T> .Read(prot)); }
static void DumpThrift(string url, CookieCollection cookies) { List <webcrap.web.Cookie> list = new List <webcrap.web.Cookie>(); foreach (System.Net.Cookie cookie in cookies) { webcrap.web.Cookie c = new webcrap.web.Cookie { Name = cookie.Name, Value = cookie.Value, Version = cookie.Version, Path = cookie.Path, Domain = cookie.Domain, Port = cookie.Port, Comment = cookie.Comment, CommentUri = cookie.CommentUri?.AbsolutePath, Expired = cookie.Expired, Expires = cookie.Expires.ToUniversalTime().Ticks, HttpOnly = cookie.HttpOnly, Secure = cookie.Secure, Timestamp = cookie.TimeStamp.ToUniversalTime().Ticks }; list.Add(c); } var dict = new Dictionary <string, List <webcrap.web.Cookie> >(); dict.Add(url, list); Cookies cc = new Cookies { Cookies_ = dict }; TByteBuffer trans = new TByteBuffer(102400); TProtocol prot = new TSimpleJSONProtocol(trans); cc.Write(prot); string json = Encoding.UTF8.GetString(trans.GetBuffer(), 0, trans.Length); Console.WriteLine(json); Console.WriteLine(); TMemoryBuffer trans1 = new TMemoryBuffer(Encoding.UTF8.GetBytes(json)); TProtocol prot1 = new TSimpleJSONProtocol(trans1); Cookies cs = new Cookies(); cs.Read(prot1); TByteBuffer trans2 = new TByteBuffer(102400); TProtocol prot2 = new TSimpleJSONProtocol(trans2); cs.Write(prot2); string json2 = Encoding.UTF8.GetString(trans2.GetBuffer(), 0, trans2.Length); Console.WriteLine(json2); Console.WriteLine(); }
public static string GetJson(T value) { TMemoryBuffer trans = new TMemoryBuffer(); TProtocol prot = new TSimpleJSONProtocol(trans); Proto <T> .Write(prot, value); byte[] buffer = trans.GetBuffer(); return(Encoding.UTF8.GetString(buffer)); }