Extracting a value from a MQTT message - SOLVED

I'm using Imroy's fork of pubsubclient, and instead of just printing the subscribed topic msg to the serial monitor, I want to convert the msg to an int, so that it can control functions within the sketch.

The MQTT messages will only contain numbers.

The code block which reads the incoming message is;

#define BUFFER_SIZE 100
void callback(const MQTT::Publish& pub) {
  Serial.print(pub.topic());
  Serial.print(" => ");
  if (pub.has_stream()) {
    uint8_t buf[BUFFER_SIZE];
    int read;
    while (read = pub.payload_stream()->read(buf, BUFFER_SIZE)) {
      Serial.write(buf, read);
    }
    pub.payload_stream()->stop();
    Serial.println("");
  } else
    Serial.println(pub.payload_string());
}

I've been trying to resolve this, and tried numerous options, but as I really don't fully understand this code block, I'm failing badly.

Any help would be appreciated.

If your string is null-terminated, you can you atoi() to convert it to an integer.
If your string is null-terminated but contains multiple numbers separated by a delimit, you can use strtok() to split them up and then use atoi().

Take a look at: Serial Input Basics to learn how to use strtok().

arduino_new:
If your string is null-terminated, you can you atoi() to convert it to an integer.
If your string is null-terminated but contains multiple numbers separated by a delimit, you can use strtok() to split them up and then use atoi().

How can I know for sure if the msg is null-terminated at all?
As I’m sending just numbers, I’m assuming that the resultant string will be just be a string containing that number?
For example; 65

I’ve tried using atoi() but get the following error message;
error: cannot convert ‘String’ to ‘const char*’ for argument ‘1’ to 'int atoi(const char*)'

String s;
int load;
//Read the incoming MQTT message
#define BUFFER_SIZE 100
void callback(const MQTT::Publish& pub) {
//  Serial.print(pub.topic());
//  Serial.print(" => ");
  if (pub.has_stream()) {
    uint8_t buf[BUFFER_SIZE];
    int read;
    while (read = pub.payload_stream()->read(buf, BUFFER_SIZE)) {
      Serial.write(buf, read);
    }
    pub.payload_stream()->stop();
    Serial.println("");
  } else
    s = pub.payload_string();
    load = atoi(s);
    Serial.println(load);
    if (load >= 7) {
      Serial.println("Greater than 7");
     // Do something
    } 
}

In case it helps anyone else... I now have this working ok thanks to help from someone outside of this Forum by using .toInt()

String loadstr;
unsigned int load;

#define BUFFER_SIZE 100
void callback(const MQTT::Publish& pub) {
  Serial.print(pub.topic());
  Serial.print(" => ");
  if (pub.has_stream()) {
    uint8_t buf[BUFFER_SIZE];
    int read;
    while (read = pub.payload_stream()->read(buf, BUFFER_SIZE)) {
      Serial.write(buf, read);
    }
    pub.payload_stream()->stop();
    Serial.println("");
  } else
    loadstr = pub.payload_string();
    load = loadstr.toInt();
}