I'd suggest the following improvement:
```
      List<int> data = buf;
      for (i = 0; i < data.length; ++i) {
        if (data[i] == 0) {
          break;
      }
      List<int> headerBytes = data.sublist(0, i - 1);
      header = UTF8.decode(headerBytes);
```