private void WriteFullFrame(byte[] buffer, int offset, int count, bool lastFrame, bool overflow)
        {
            // TODO add logic for "overflow" pages

            int segments = (count + 254) / 255;

            byte[] frameHeader = new byte[27 + segments];
            Array.Copy(OggHeader, frameHeader, OggHeader.Length);
            frameHeader[4] = 0x00;
            int frameType = 0;

            if (!isFirstFrameWitten)
            {
                frameType         |= FirstPageFlag;
                isFirstFrameWitten = true;
            }
            if (lastFrame)
            {
                frameType         |= LastPageFlag;
                isLastFrameWritten = true;
            }
            frameHeader[5] = (byte)frameType;
            Array.Copy(BitConverter.GetBytes(position), 0, frameHeader, 6, 8);
            Array.Copy(BitConverter.GetBytes(streamId), 0, frameHeader, 14, 4);
            Array.Copy(BitConverter.GetBytes(pageNumber), 0, frameHeader, 18, 4);
            // 22 - 26 crc32
            frameHeader[26] = (byte)segments;
            for (int i = 0; i < segments - 1; i++)
            {
                frameHeader[27 + i] = 255;
            }
            frameHeader[27 + segments - 1] = (byte)(count - (segments - 1) * 255);

            uint crc32 = CrcUtils.Crc32(0, frameHeader);

            crc32 = CrcUtils.Crc32(crc32, buffer, offset, count);

            Array.Copy(BitConverter.GetBytes(crc32), 0, frameHeader, 22, 4);

            baseStream.Write(frameHeader, 0, frameHeader.Length);
            baseStream.Write(buffer, offset, count);

            pageNumber++;
            position += (ulong)count;
        }
 private static uint Crc32(uint seed, byte[] data)
 {
     return(CrcUtils.Crc32(seed, data));
 }