Esempio n. 1
0
 protected DynamicContent(int capacity, bool binary = true)
 {
     if (binary)
     {
         bytebuf = BufferUtility.Rent(capacity);
     }
     else
     {
         charbuf = new char[capacity];
     }
 }
Esempio n. 2
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
        }