using System;
using System.Collections.Generic;
using System.Text;
using OpenMetaverse;
namespace OpenMetaverse
{
public static class ClientHelpers
{
///
/// Converts a list of primitives to an object that can be serialized
/// with the LLSD system
///
/// Primitives to convert to a serializable object
/// An object that can be serialized with LLSD
public static StructuredData.OSD PrimListToOSD(List 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;
}
///
/// Deserializes OSD in to a list of primitives
///
/// Structure holding the serialized primitive list,
/// must be of the SDMap type
/// A list of deserialized primitives
public static List 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 prims = new List(map.Count);
foreach (KeyValuePair kvp in map)
{
Primitive prim = Primitive.FromOSD(kvp.Value);
prim.LocalID = UInt32.Parse(kvp.Key);
prims.Add(prim);
}
return prims;
}
}
}