public static void encodeString(String str, Serializer out) {
        if (str == null || str.isEmpty()) {
            out.putInt(null, 0);
        } else {
            byte[] nameBytes = Utf8.toBytes(str);
            out.putInt(null, nameBytes.length);
            out.put(null, nameBytes);
        }
    }
Writes the given string to the given byte buffer in such a way that it can be decoded using {@link
#decodeString(com.yahoo.vespa.objects.Deserializer)}.

@param str The string to encode.
@param out The byte buffer to write to.
documentapi/src/main/java/com/yahoo/documentapi/messagebus/protocol/AbstractRoutableFactory.java