opensim/OpenSim/Framework/Util.cs
/// <summary>
/// Convert a string to a byte format suitable for transport in an LLUDP packet.  The output is truncated to 1024 bytes if necessary.
/// </summary>
/// <param name="str">
/// 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]
/// </param>
/// <returns></returns>
Convert a string to a byte format suitable for transport in an LLUDP packet.  The output is truncated to 1024 bytes if necessary.
Convert a string to a byte format suitable for transport in an LLUDP packet . The output is truncated to 1024 bytes if necessary .
public static byte[] StringToBytes1024(string str)
        {
            if (String.IsNullOrEmpty(str)) { return Utils.EmptyBytes; }
            if (str.Length > 1023) str = str.Remove(1023);
            if (!str.EndsWith("\0")) { str += "\0"; }
            byte[] data = UTF8.GetBytes(str);
            if (data.Length > 1024)
            {
                Array.Resize<byte>(ref data, 1024);
                data[1023] = 0;
            }
            return data;
        }
public static byte [ ] StringToBytes1024 ( string str ) { if ( String . IsNullOrEmpty ( str ) ) { return Utils . EmptyBytes ; } if ( str . Length > 1023 ) str = str . Remove ( 1023 ) ; if ( ! str . EndsWith ( " \0 " ) ) { str += " \0 " ; } byte [ ] data = UTF8 . GetBytes ( str ) ; if ( data . Length > 1024 ) { Array . Resize < byte > ( ref data , 1024 ) ; data [ 1023 ] = 0 ; } return data ; }
Convert a string to a byte format suitable for transport in an LLUDP packet.
Convert a string to a byte format suitable for transport in an LLUDP packet .
// Because this is UTF-8 encoding and not ASCII, it's possible we // might have gotten an oversized array even after the string trim
None
str
string
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]
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 ]