How to increase the mqtt publish packet remaining length

size_t topic_len = strlen(topic);
size_t data_len = strlen(data);
size_t total_length = topic_len + data_len;
uint8_t *bufp = new uint8_t[total_length + 4];
bufp[i] = 0x30; //control field; 0x30
bufp[++i] = total_length + 2;//remaining length
bufp[++i] = 0x00; //length
bufp[++i] = topic_len;
for (uint16_t j = 0; j != topic_len; j++)
bufp[++i] = topic[j];
//buf[++i] = 0x00; //length
//buf[++i] = data_len;
for (uint16_t j = 0; j != data_len; j++)
bufp[++i] = data[j];
// for (int o = 0; o < total_length + 4; o++)
// cout << o << (char)bufp[o] << endl;
net.flush();
Serial.println(net.write(bufp, total_length + 4));

how to change the packet length if the total_length+2 is greater then 127

Refer this code here,
http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Table_2.4_Size