예제 #1
0
파일: JObj.cs 프로젝트: UrienZhang/device
        public override string ToString()
        {
            JsonContent cnt = new JsonContent(false, 4096);

            try
            {
                cnt.PutFrom(this);
                return(cnt.ToString());
            }
            finally
            {
                BufferUtility.Return(cnt);
            }
        }
예제 #2
0
        public static string ToString <D>(D v, byte proj = 0x0f) where D : IData
        {
            JsonContent cnt = new JsonContent(false, 4 * 1024);

            try
            {
                cnt.Put(null, v, proj);
                return(cnt.ToString());
            }
            finally
            {
                BufferUtility.Return(cnt); // return buffer to pool
            }
        }
예제 #3
0
        void AddByte(byte b)
        {
            // ensure capacity
            int olen = bytebuf.Length; // old length

            if (count >= olen)
            {
                int    nlen = olen * 4; // new length
                byte[] obuf = bytebuf;
                bytebuf = BufferUtility.GetByteBuffer(nlen);
                Array.Copy(obuf, 0, bytebuf, 0, olen);
                BufferUtility.Return(obuf);
            }
            bytebuf[count++] = b;

            // calculate checksum
            ulong cs = checksum;

            cs      ^= b;                  // XOR
            checksum = cs >> 57 | cs << 7; // circular left shift 7 bit
        }
예제 #4
0
 public void Add(char c)
 {
     if (IsBinary) // byte-oriented
     {
         // UTF-8 encoding but without surrogate support
         if (c < 0x80)
         {
             // have at most seven bits
             AddByte((byte)c);
         }
         else if (c < 0x800)
         {
             // 2 char, 11 bits
             AddByte((byte)(0xc0 | (c >> 6)));
             AddByte((byte)(0x80 | (c & 0x3f)));
         }
         else
         {
             // 3 char, 16 bits
             AddByte((byte)(0xe0 | ((c >> 12))));
             AddByte((byte)(0x80 | ((c >> 6) & 0x3f)));
             AddByte((byte)(0x80 | (c & 0x3f)));
         }
     }
     else // char-oriented
     {
         // ensure capacity
         int olen = charbuf.Length; // old length
         if (count >= olen)
         {
             int    nlen = olen * 4; // new length
             char[] obuf = charbuf;
             charbuf = BufferUtility.GetCharBuffer(nlen);
             Array.Copy(obuf, 0, charbuf, 0, olen);
             BufferUtility.Return(obuf);
         }
         charbuf[count++] = c;
     }
 }