diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 3e6d8eff3e..4dafaef288 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -2021,6 +2021,56 @@ namespace OpenSim.Framework
return data;
}
+ ///
+ /// Convert a string to a byte format suitable for transport in an LLUDP packet. The output is truncated to MaxLength bytes if necessary.
+ ///
+ ///
+ /// If null or empty, then an bytes[0] is returned.
+ /// Using "\0" will return a conversion of the null character to a byte. This is not the same as bytes[0]
+ ///
+ ///
+ /// Arguments to substitute into the string via the {} mechanism.
+ ///
+ ///
+ public static byte[] StringToBytes(string str, int MaxLength, params object[] args)
+ {
+ return StringToBytes1024(string.Format(str, args), MaxLength);
+ }
+
+ ///
+ /// Convert a string to a byte format suitable for transport in an LLUDP packet. The output is truncated to MaxLength bytes if necessary.
+ ///
+ ///
+ /// If null or empty, then an bytes[0] is returned.
+ /// Using "\0" will return a conversion of the null character to a byte. This is not the same as bytes[0]
+ ///
+ ///
+ public static byte[] StringToBytes(string str, int MaxLength)
+ {
+ if (String.IsNullOrEmpty(str))
+ return Utils.EmptyBytes;
+
+ if (!str.EndsWith("\0"))
+ str += "\0";
+
+ // Because this is UTF-8 encoding and not ASCII, it's possible we
+ // might have gotten an oversized array even after the string trim
+ byte[] data = UTF8.GetBytes(str);
+
+ if (data.Length > MaxLength)
+ {
+ int cut = MaxLength -1 ;
+ if((data[cut] & 0x80 ) != 0 )
+ {
+ while(cut > 0 && (data[cut] & 0xc0) != 0xc0)
+ cut--;
+ }
+ Array.Resize(ref data, cut + 1);
+ data[cut] = 0;
+ }
+
+ return data;
+ }
///
/// Pretty format the hashtable contents to a single line.
///