示例#1
0
        /// <summary>
        /// Writes the calculated prefix and the specified payload to the specified buffer.
        /// </summary>
        /// <param name="buffer">The buffer to use.</param>
        /// <param name="connectionStartTimestamp">The timestamp of the connection's establishment.</param>
        /// <param name="payloadwriter">The action which writes the payload to a buffer.</param>
        public static void WritePrefix(BitBuffer buffer, long connectionStartTimestamp, Action <BitBuffer> payloadwriter)
        {
            buffer.AdvanceWriter(32);
            buffer.Write(DoubleProtocol.PacketTimestamp(connectionStartTimestamp));
            payloadwriter(buffer);
            uint crc = Crc32.Get(buffer.Array, 4, buffer.Size - 4);

            byte[] array = buffer.Array;
            array[0] = (byte)crc;
            array[1] = (byte)(crc >> 8);
            array[2] = (byte)(crc >> 16);
            array[3] = (byte)(crc >> 24);
        }