Пример #1
0
        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();
        }
Пример #2
0
 private void PrintBuf()
 {
     byte[] buf = trans.GetBuffer();
     WriteLine(
         "{0}:{1}",
         trans.Length,
         string.Join(" ", Enumerable.Range(0, trans.Length).Select(i => buf[i].ToString())));
 }