/// <summary>
        /// Writes message data using given writer
        /// </summary>
        /// <param name="writer">
        ///     The writer.
        /// </param>
        /// <param name="getBuffer"></param>
        public void WriteTo(KafkaBinaryWriter writer)
        {
            Guard.NotNull(writer, "writer");
            writer.Seek(MagicOffset, SeekOrigin.Current);
            var beginningPosition = writer.CurrentPos;

            writer.Write(this.Magic);
            writer.Write(this.Attributes);
            writer.Write(this.KeyLength);
            if (KeyLength != -1)
            {
                writer.Write(this.Key);
            }
            writer.Write(Payload.Length);
            writer.Write(this.Payload);
            var crc = ComputeChecksum(writer.Buffer, (int)beginningPosition, Size - MagicOffset);

            writer.Seek(-Size, SeekOrigin.Current);
            writer.Write(crc);
            writer.Seek(Size - DefaultCrcLength, SeekOrigin.Current);
        }