These two lines don't seem correct to me for non-UTF-8 AbstractString types:
|
resize!(buffer, l + sizeof(val)) |
|
unsafe_copyto!(pointer(buffer, l+1), pointer(val,1), sizeof(val)) |
Indeed this will copy the contents of the string even if it uses a different encoding from existing data.