invalid conversion from 'uint8_t* {aka unsigned char*}' to 'const char*' [-fperm

HI all, I wonder if anyone can help me with this problem . This is fragment from the example code for a ESP32 HUZZAH Feather.
File > examples > examples for adafruit esp feather > esp async UDP > asyncUDPserver

Serial.print(", Length: ");
Serial.print(packet.length());
Serial.print(", Data: ");
Serial.write(packet.data(), packet.length());
Serial.println();
//reply to the client
packet.printf("Got %u bytes of data", packet.length());
// attempt to parse what was received in packet.data()
String s = packet.data(); // error here.
//invalid conversion from 'uint8_t* {aka unsigned char*}' to 'const char*' [-fpermissive]

I am simply trying to get at the packet.data() so that I can work with it, extract substrings, etc but I am at a loss as to why I can't get the data into a simple string. I suspect i need to get it into a byte array but I don't know how to do this. I am a terrible beginner. I note that the Serial.write(packet.data(), packet.length()) statement above has no trouble accepting the packet.data().
Anyone able to help?
dazza000

char buf[packet.length()+1] = {};
memcpy(buf, packet.data());

String s = String(buf);

HI , thanks for the reply but...

char buf[packet.length()+1] = {};
memcpy(buf, packet.data()); // error here.
// too few arguments to function 'void* memcpy(void*, const void*, size_t)'
String s = String(buf);

can I ask what this means?
thanks
dazza000

aha
googling says memcpy() requires three arguments , a destination , a source, and a count of the elements in the source eg:
memcpy( arrB, arrA, 5 );

so I need:

memcpy(buf, packet.data(), packet.length());

Is that right?

I'm surprised that the message is an ERROR and not just a WARNING.

Does your packet have the null terminator included so you can treat it as a string? If not, expect to get some garbage at the end of the messages.

thanks John fo replying,

  1. Yes its an Error.

  2. I don't know if a null terminator is included in the packet . how do I find out.

  3. Is this a standard thing that happens with network functions, strings get turned into a different format to send and then have to be changed back into strings on receipt?

  4. The fix figured out from "arduino_new" (Sr Member) is now working flawlessly.

  5. Thanks to both of you!

Dazza000