From 9d0a95ea953d71651b2c24efd3a4368c275895a4 Mon Sep 17 00:00:00 2001 From: Latif Khalifa Date: Fri, 15 Oct 2010 01:00:48 +0000 Subject: [PATCH] LIBOMV-875 (Allow LLSD/binary header to be optional) Added optional second paramater "headersOptional" which when set to true will not throw an exception when deserializing headerless binary LLSD. Default behavior unchanged. git-svn-id: http://libopenmetaverse.googlecode.com/svn/libopenmetaverse/trunk@3452 52acb1d6-8a22-11de-b505-999d5b087335 --- .../LLSD/BinaryLLSD.cs | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/OpenMetaverse.StructuredData/LLSD/BinaryLLSD.cs b/OpenMetaverse.StructuredData/LLSD/BinaryLLSD.cs index 9d1096ef..ade84b67 100644 --- a/OpenMetaverse.StructuredData/LLSD/BinaryLLSD.cs +++ b/OpenMetaverse.StructuredData/LLSD/BinaryLLSD.cs @@ -74,25 +74,46 @@ namespace OpenMetaverse.StructuredData private static readonly byte[] llsdBinaryHeadBytes = Encoding.ASCII.GetBytes(llsdBinaryHead); /// - /// + /// Deserializes binary LLSD /// - /// - /// + /// Serialized data + /// OSD containting deserialized data public static OSD DeserializeLLSDBinary(byte[] binaryData) + { + return DeserializeLLSDBinary(binaryData, false); + } + + /// + /// Deserializes binary LLSD + /// + /// Serialized data + /// OSD containting deserialized data + public static OSD DeserializeLLSDBinary(byte[] binaryData, bool headerOptional) { MemoryStream stream = new MemoryStream(binaryData); - OSD osd = DeserializeLLSDBinary(stream); + OSD osd = DeserializeLLSDBinary(stream, headerOptional); stream.Close(); return osd; } /// - /// + /// Deserializes binary LLSD /// - /// - /// + /// Stream to read the data from + /// OSD containting deserialized data public static OSD DeserializeLLSDBinary(Stream stream) + { + return DeserializeLLSDBinary(stream, false); + } + + /// + /// Deserializes binary LLSD + /// + /// Stream to read the data from + /// Treat LLSD binary header as optional + /// OSD containting deserialized data + public static OSD DeserializeLLSDBinary(Stream stream, bool headerOptional) { if (!stream.CanSeek) throw new OSDException("Cannot deserialize binary LLSD from unseekable streams"); @@ -100,7 +121,8 @@ namespace OpenMetaverse.StructuredData SkipWhiteSpace(stream); if (!FindString(stream, llsdBinaryHead) && !FindString(stream, llsdBinaryHead2)) - throw new OSDException("Failed to decode binary LLSD"); + if (!headerOptional) + throw new OSDException("Failed to decode binary LLSD"); SkipWhiteSpace(stream);