/// <summary> /// Writes the BitfieldMessage data to a byte array. /// </summary> /// <param name="buffer">The byte array that the message data will be written to.</param> /// <param name="offset">The position in the array at which the message begins.</param> /// <returns>An integer representing the the amount of bytes written in the array.</returns> public override int ToBytes(byte[] buffer, int offset) { var byteArray = new byte[(int)Math.Ceiling((double)Bitfield.Length / 8)]; Bitfield.CopyTo(byteArray, 0); int start = offset; offset += Write(buffer, offset, byteArray.Length + 1); offset += Write(buffer, offset, (byte)5); offset += Write(buffer, offset, byteArray); return(offset - start); }