'Trying to modify const data: Compile error: passing 'const Device::FFT' as 'this' argument of 'void Device::FFT::DataBEtoLE()' discards qualifiers

I have a data array which is populated from the network device in big endian format. The processor on the host is an intel processor, therefore by default little endian.

I have written a member function (DataBEtoLE) inside a class named FFT of which is wrapped in a namespace named Device of which converts the data array recieved from the network device to the byte order (little endian) on the host.

processBufferData receives a const void* data array of which is parsed and then processed within Device::Message. What I then want to do is take the data received and convert it from little endian to big endian which is what the DataBEtoLE function does.

However, when trying to compile the following (simplified) code, I recieve the following error:

Compile error: passing 'const Device::FFT' as 'this' argument of 'void Device::FFT::DataBEtoLE()' discards qualifiers

I suspect this has something to do with a const conflict as the message being recieved is a const, and I am trying to modify that, but I am not sure how to get around this.

My code is as follows:

#include <arpa/inet.h>

using namespace std;
namespace Device {
    class FFT {
        private:
            uint16_t data[16384];

        public:
            void DataBEtoLE() {
                for(int i = 0; i < sizeof(data)/sizeof(data[0]); i++){
                    data[i] = ntohs(data[i]);
                }
            }
    };

    union Message {
        FFT fft;
    };
}

void FFTProcessor (const Device::Message& message);

void processBufferData (const void* data) {
    const Device::Message* message = (const Device::Message*)data;

    message->fft.DataBEtoLE();     // compile error is here
    FFTProcessor(*message);
}

void FFTProcessor (const Device::Message& message) {    
    // do stuff with modified device data here
}

int main(){
    uint8_t* buffer = new uint8_t[16384];

    processBufferData(buffer);

    return 0;
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source