This function has the same behavior as encode_string(), except it takes a "struct chunk" instead of a "char *" on input.