Exemplo n.º 1
0
 protected DynamicContent(int capacity, bool binary = true)
 {
     if (binary)
     {
         bytebuf = BufferUtility.Rent(capacity);
     }
     else
     {
         charbuf = new char[capacity];
     }
 }
Exemplo n.º 2
0
        public override string ToString()
        {
            var cnt = new JsonContent(4 * 1024, binary: false);

            try
            {
                cnt.Put(null, this);
                return(cnt.ToString());
            }
            finally
            {
                BufferUtility.Return(cnt.Buffer); // return buffer to pool
            }
        }
Exemplo n.º 3
0
        public static string ToString <D>(D v, byte proj = 0x0f) where D : IData
        {
            var cnt = new JsonContent(4 * 1024, binary: false);

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

            if (count >= olen)
            {
                int    nlen = olen * 2; // new doubled length
                byte[] obuf = bytebuf;
                bytebuf = BufferUtility.Rent(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
        }