LIBOMV-576 Merged ClientHelpers and Helpers classes, ClientHelpers methods can once again be directly accessed through the static Helpers class.

git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@3130 52acb1d6-8a22-11de-b505-999d5b087335
This commit is contained in:
Jim Radford
2009-10-07 03:47:02 +00:00
parent acdb971f13
commit 3f3c4e182f
6 changed files with 47 additions and 58 deletions

View File

@@ -1,50 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
using OpenMetaverse;
namespace OpenMetaverse
{
public static class ClientHelpers
{
/// <summary>
/// Converts a list of primitives to an object that can be serialized
/// with the LLSD system
/// </summary>
/// <param name="prims">Primitives to convert to a serializable object</param>
/// <returns>An object that can be serialized with LLSD</returns>
public static StructuredData.OSD PrimListToOSD(List<Primitive> prims)
{
StructuredData.OSDMap map = new OpenMetaverse.StructuredData.OSDMap(prims.Count);
for (int i = 0; i < prims.Count; i++)
map.Add(prims[i].LocalID.ToString(), prims[i].GetOSD());
return map;
}
/// <summary>
/// Deserializes OSD in to a list of primitives
/// </summary>
/// <param name="osd">Structure holding the serialized primitive list,
/// must be of the SDMap type</param>
/// <returns>A list of deserialized primitives</returns>
public static List<Primitive> OSDToPrimList(StructuredData.OSD osd)
{
if (osd.Type != StructuredData.OSDType.Map)
throw new ArgumentException("LLSD must be in the Map structure");
StructuredData.OSDMap map = (StructuredData.OSDMap)osd;
List<Primitive> prims = new List<Primitive>(map.Count);
foreach (KeyValuePair<string, StructuredData.OSD> kvp in map)
{
Primitive prim = Primitive.FromOSD(kvp.Value);
prim.LocalID = UInt32.Parse(kvp.Key);
prims.Add(prim);
}
return prims;
}
}
}

View File

@@ -301,8 +301,8 @@ namespace OpenMetaverse
}
catch (Exception ex)
{
//Logger.Log(String.Format("Zerodecoding error: i={0}, srclen={1}, bodylen={2}, zerolen={3}\n{4}\n{5}",
// i, srclen, bodylen, zerolen, Utils.BytesToHexString(src, srclen, null), ex), LogLevel.Error);
Logger.Log(String.Format("Zerodecoding error: i={0}, srclen={1}, bodylen={2}, zerolen={3}\n{4}\n{5}",
i, srclen, bodylen, zerolen, Utils.BytesToHexString(src, srclen, null), ex), LogLevel.Error);
throw new IndexOutOfRangeException(String.Format("Zerodecoding error: i={0}, srclen={1}, bodylen={2}, zerolen={3}\n{4}\n{5}",
i, srclen, bodylen, zerolen, Utils.BytesToHexString(src, srclen, null)), ex.InnerException);
}
@@ -479,6 +479,45 @@ namespace OpenMetaverse
}
return null;
}
}
/// <summary>
/// Converts a list of primitives to an object that can be serialized
/// with the LLSD system
/// </summary>
/// <param name="prims">Primitives to convert to a serializable object</param>
/// <returns>An object that can be serialized with LLSD</returns>
public static StructuredData.OSD PrimListToOSD(List<Primitive> prims)
{
StructuredData.OSDMap map = new OpenMetaverse.StructuredData.OSDMap(prims.Count);
for (int i = 0; i < prims.Count; i++)
map.Add(prims[i].LocalID.ToString(), prims[i].GetOSD());
return map;
}
/// <summary>
/// Deserializes OSD in to a list of primitives
/// </summary>
/// <param name="osd">Structure holding the serialized primitive list,
/// must be of the SDMap type</param>
/// <returns>A list of deserialized primitives</returns>
public static List<Primitive> OSDToPrimList(StructuredData.OSD osd)
{
if (osd.Type != StructuredData.OSDType.Map)
throw new ArgumentException("LLSD must be in the Map structure");
StructuredData.OSDMap map = (StructuredData.OSDMap)osd;
List<Primitive> prims = new List<Primitive>(map.Count);
foreach (KeyValuePair<string, StructuredData.OSD> kvp in map)
{
Primitive prim = Primitive.FromOSD(kvp.Value);
prim.LocalID = UInt32.Parse(kvp.Key);
prims.Add(prim);
}
return prims;
}
}
}

View File

@@ -328,7 +328,7 @@ namespace PrimWorkshop
textures = 0;
// Write the LLSD to the hard drive in XML format
string output = OSDParser.SerializeLLSDXmlString(ClientHelpers.PrimListToOSD(primList));
string output = OSDParser.SerializeLLSDXmlString(Helpers.PrimListToOSD(primList));
try
{
// Create a temporary directory
@@ -499,7 +499,7 @@ namespace PrimWorkshop
// Decode the .prims file
string raw = File.ReadAllText(primFile);
OSD osd = OSDParser.DeserializeLLSDXml(raw);
return ClientHelpers.OSDToPrimList(osd);
return Helpers.OSDToPrimList(osd);
}
catch (Exception e)
{

View File

@@ -275,7 +275,7 @@ namespace PrimWorkshop
if (osd != null && osd.Type == OSDType.Map)
{
List<Primitive> primList = ClientHelpers.OSDToPrimList(osd);
List<Primitive> primList = Helpers.OSDToPrimList(osd);
Prims = new List<FacetedMesh>(primList.Count);
for (int i = 0; i < primList.Count; i++)

View File

@@ -100,7 +100,7 @@ namespace OpenMetaverse.TestClient
Logger.Log(uuid.ToString(), Helpers.LogLevel.Warning, Client);
}
string output = OSDParser.SerializeLLSDXmlString(ClientHelpers.PrimListToOSD(prims));
string output = OSDParser.SerializeLLSDXmlString(Helpers.PrimListToOSD(prims));
try { File.WriteAllText(file, output); }
catch (Exception e) { return e.Message; }

View File

@@ -63,7 +63,7 @@ namespace OpenMetaverse.TestClient
try { xml = File.ReadAllText(filename); }
catch (Exception e) { return e.Message; }
try { prims = ClientHelpers.OSDToPrimList(OSDParser.DeserializeLLSDXml(xml)); }
try { prims = Helpers.OSDToPrimList(OSDParser.DeserializeLLSDXml(xml)); }
catch (Exception e) { return "Failed to deserialize " + filename + ": " + e.Message; }
// Build an organized structure from the imported prims