Fixed a couple of bugs in CustomUtf8Encoder

Two changes here:

1. We need to also write the length of the encoded string
2. A small bug with lastDp being a local variable in encodeStringToHeap