Use the idiom msgb_put(msg, 0) to get the data pointer, then encode the string into the msgb and then adjust the size.