diff --git a/OpenMetaverse.StructuredData/JSON/OSDJson.cs b/OpenMetaverse.StructuredData/JSON/OSDJson.cs index 02ce6982..79b146bb 100644 --- a/OpenMetaverse.StructuredData/JSON/OSDJson.cs +++ b/OpenMetaverse.StructuredData/JSON/OSDJson.cs @@ -1,11 +1,21 @@ using System; using System.Collections.Generic; +using System.IO; using LitJson; namespace OpenMetaverse.StructuredData { public static partial class OSDParser { + public static OSD DeserializeJson(Stream json) + { + using (StreamReader streamReader = new StreamReader(json)) + { + JsonReader reader = new JsonReader(streamReader); + return DeserializeJson(JsonMapper.ToObject(reader)); + } + } + public static OSD DeserializeJson(string json) { return DeserializeJson(JsonMapper.ToObject(json)); @@ -25,47 +35,55 @@ namespace OpenMetaverse.StructuredData return OSD.FromReal((double)json); case JsonType.String: string str = (string)json; - switch (str[0]) - { - case 'd': - if (str.StartsWith("date::")) - { - DateTime dt; - if (DateTime.TryParse(str.Substring(6), out dt)) - return OSD.FromDate(dt); - } - break; - case 'u': - if (str.StartsWith("uuid::")) - { - UUID id; - if (UUID.TryParse(str.Substring(6), out id)) - return OSD.FromUUID(id); - } - else if (str.StartsWith("uri::")) - { - try - { - Uri uri = new Uri(str.Substring(5)); - return OSD.FromUri(uri); - } - catch (UriFormatException) { } - } - break; - case 'b': - if (str.StartsWith("b64::")) - { - try - { - byte[] data = Convert.FromBase64String(str.Substring(5)); - return OSD.FromBinary(data); - } - catch (FormatException) { } - } - break; - } - return OSD.FromString((string)json); + if (String.IsNullOrEmpty(str)) + { + return new OSD(); + } + else + { + switch (str[0]) + { + case 'd': + if (str.StartsWith("date::")) + { + DateTime dt; + if (DateTime.TryParse(str.Substring(6), out dt)) + return OSD.FromDate(dt); + } + break; + case 'u': + if (str.StartsWith("uuid::")) + { + UUID id; + if (UUID.TryParse(str.Substring(6), out id)) + return OSD.FromUUID(id); + } + else if (str.StartsWith("uri::")) + { + try + { + Uri uri = new Uri(str.Substring(5)); + return OSD.FromUri(uri); + } + catch (UriFormatException) { } + } + break; + case 'b': + if (str.StartsWith("b64::")) + { + try + { + byte[] data = Convert.FromBase64String(str.Substring(5)); + return OSD.FromBinary(data); + } + catch (FormatException) { } + } + break; + } + + return OSD.FromString((string)json); + } case JsonType.Array: OSDArray array = new OSDArray(json.Count); for (int i = 0; i < json.Count; i++) diff --git a/OpenMetaverse/Imaging/OpenJPEG.cs b/OpenMetaverse/Imaging/OpenJPEG.cs index 0533125e..07abe67a 100644 --- a/OpenMetaverse/Imaging/OpenJPEG.cs +++ b/OpenMetaverse/Imaging/OpenJPEG.cs @@ -166,7 +166,7 @@ namespace OpenMetaverse.Imaging lock (OpenJPEGLock) { if (!DotNetAllocDecoded(ref marshalled)) - throw new Exception("LibslAllocDecoded failed"); + throw new Exception("DotNetAllocDecoded failed"); int n = image.Width * image.Height; @@ -182,7 +182,7 @@ namespace OpenMetaverse.Imaging // codec will allocate output buffer if (!DotNetEncode(ref marshalled, lossless)) - throw new Exception("LibslEncode failed"); + throw new Exception("DotNetEncode failed"); // copy output buffer encoded = new byte[marshalled.length];