More idiomatically, this might be:

    String padding = "0000".substring(lenStr.length);
    String payload = ''${padding}${lenStr}${msg}';