From 60bc64a90f70dda1ad232c5f073ad7989ccb299c Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Fri, 30 Nov 2018 23:13:21 +0000 Subject: [PATCH] LLSDxmlencode uint and ulong --- OpenSim/Framework/LLSDxmlEncode.cs | 64 +++++++++++++++++++++++++----- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/OpenSim/Framework/LLSDxmlEncode.cs b/OpenSim/Framework/LLSDxmlEncode.cs index ed0993d8ae..102955d6fb 100644 --- a/OpenSim/Framework/LLSDxmlEncode.cs +++ b/OpenSim/Framework/LLSDxmlEncode.cs @@ -147,11 +147,21 @@ namespace OpenSim.Framework else { sb.Append(""); - sb.Append(e.ToString()); + sb.Append(e.ToString()); sb.Append(""); } } + public static void AddElem(uint e, StringBuilder sb) + { + AddElem(uintToByteArray(e), sb); + } + + public static void AddElem(ulong e, StringBuilder sb) + { + AddElem(ulongToByteArray(e), sb); + } + public static void AddElem(float e, StringBuilder sb) { if(e == 0) @@ -266,7 +276,7 @@ namespace OpenSim.Framework else { sb.Append(""); - sb.Append(e.ToString(CultureInfo.InvariantCulture)); + sb.Append(e.ToString(CultureInfo.InvariantCulture)); sb.Append(""); } } @@ -414,7 +424,7 @@ namespace OpenSim.Framework else { sb.Append(""); - sb.Append(e.ToString()); + sb.Append(e.ToString()); sb.Append(""); } } @@ -430,7 +440,7 @@ namespace OpenSim.Framework else { sb.Append(""); // encode64 is default - sb.Append(Convert.ToBase64String(e,Base64FormattingOptions.None)); + sb.Append(Convert.ToBase64String(e,Base64FormattingOptions.None)); sb.Append(""); } } @@ -446,11 +456,21 @@ namespace OpenSim.Framework else { sb.Append(""); - sb.Append(e.ToString()); + sb.Append(e.ToString()); sb.Append(""); } } + public static void AddElem(string name, uint e, StringBuilder sb) + { + AddElem(name, uintToByteArray(e), sb); + } + + public static void AddElem(string name, ulong e, StringBuilder sb) + { + AddElem(name, ulongToByteArray(e), sb); + } + public static void AddElem(string name, float e, StringBuilder sb) { sb.Append(""); @@ -579,7 +599,7 @@ namespace OpenSim.Framework else { sb.Append(""); - sb.Append(e.ToString(CultureInfo.InvariantCulture)); + sb.Append(e.ToString(CultureInfo.InvariantCulture)); sb.Append(""); } } @@ -611,7 +631,7 @@ namespace OpenSim.Framework else { sb.Append(""); - EscapeToXML(e.ToString(), sb); + EscapeToXML(e, sb); sb.Append(""); } } @@ -627,7 +647,7 @@ namespace OpenSim.Framework else { sb.Append(""); - sb.Append(e); + sb.Append(e); sb.Append(""); } } @@ -720,6 +740,32 @@ namespace OpenSim.Framework break; } } - } + } + + public static byte[] ulongToByteArray(ulong uLongValue) + { + return new byte[8] + { + (byte)((uLongValue >> 56) & 0xff), + (byte)((uLongValue >> 48) & 0xff), + (byte)((uLongValue >> 40) & 0xff), + (byte)((uLongValue >> 32) & 0xff), + (byte)((uLongValue >> 24) & 0xff), + (byte)((uLongValue >> 16) & 0xff), + (byte)((uLongValue >> 8) & 0xff), + (byte)(uLongValue & 0xff) + }; + } + + public static byte[] uintToByteArray(uint value) + { + return new byte[4] + { + (byte)((value >> 24) & 0xff), + (byte)((value >> 16) & 0xff), + (byte)((value >> 8) & 0xff), + (byte)(value & 0xff) + }; + } } }