Is it really necessary to decode the data to retrieve the length? The Node.js guys seem to have [a nice function](http://dxr.nodeapp.org/code/source/string_bytes.cc#128) for this.