internal static unsafe void TerminateImpl(Base64Info *ptr_info, UnsafeRefToNativeList <Char16> buff)
        {
            uint tmp = ptr_info->store;

            switch (ptr_info->bytePos)
            {
            case 0:
                // do nothing
                break;

            case 1:
                // two character padding needed
                buff.Add(Base64EncodeTable.Get((tmp & 0xfc) >> 2));
                buff.Add(Base64EncodeTable.Get((tmp & 0x03) << 4));
                buff.Add(Base64EncodeTable.Get(64));      // pad
                buff.Add(Base64EncodeTable.Get(64));      // pad
                break;

            case 2:
                // one character padding needed
                buff.Add(Base64EncodeTable.Get((tmp & 0xfc00) >> 10));
                buff.Add(Base64EncodeTable.Get((tmp & 0x03f0) >> 4));
                buff.Add(Base64EncodeTable.Get((tmp & 0x000f) << 2));
                buff.Add(Base64EncodeTable.Get(64));      // pad
                break;
            }
            ptr_info->store   = 0;
            ptr_info->bytePos = 0;
        }
        internal static unsafe void GetCharsImpl(Base64Info *ptr_info,
                                                 UnsafeRefToNativeList <Char16> buff,
                                                 byte *byte_ptr, int byte_len, bool splitData)
        {
            CheckLengthIsPositive(byte_len);

            uint store   = ptr_info->store;
            int  bytePos = ptr_info->bytePos;

            int charcount = 0;

            for (uint i = 0; i < byte_len; i++)
            {
                if (ptr_info->insertLF)
                {
                    if (charcount == Base64Const.LineBreakPos)
                    {
                        buff.Add(UTF16CodeSet.code_CR);
                        buff.Add(UTF16CodeSet.code_LF);
                        charcount = 0;
                    }
                }

                store = (store << 8) | byte_ptr[i];
                bytePos++;

                // encoding 3 bytes -> 4 chars
                if (bytePos == 3)
                {
                    buff.Add(Base64EncodeTable.Get((store & 0xfc0000) >> 18));
                    buff.Add(Base64EncodeTable.Get((store & 0x03f000) >> 12));
                    buff.Add(Base64EncodeTable.Get((store & 0x000fc0) >> 6));
                    buff.Add(Base64EncodeTable.Get((store & 0x00003f)));
                    charcount += 4;

                    store   = 0;
                    bytePos = 0;
                }
            }

            ptr_info->store   = store;
            ptr_info->bytePos = bytePos;

            if (!splitData)
            {
                TerminateImpl(ptr_info, buff);
            }
        }