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
This commit is contained in:
@@ -74,25 +74,46 @@ namespace OpenMetaverse.StructuredData
|
||||
private static readonly byte[] llsdBinaryHeadBytes = Encoding.ASCII.GetBytes(llsdBinaryHead);
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Deserializes binary LLSD
|
||||
/// </summary>
|
||||
/// <param name="binaryData"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="binaryData">Serialized data</param>
|
||||
/// <returns>OSD containting deserialized data</returns>
|
||||
public static OSD DeserializeLLSDBinary(byte[] binaryData)
|
||||
{
|
||||
return DeserializeLLSDBinary(binaryData, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes binary LLSD
|
||||
/// </summary>
|
||||
/// <param name="binaryData">Serialized data</param>
|
||||
/// <returns>OSD containting deserialized data</returns>
|
||||
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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// Deserializes binary LLSD
|
||||
/// </summary>
|
||||
/// <param name="stream"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="stream">Stream to read the data from</param>
|
||||
/// <returns>OSD containting deserialized data</returns>
|
||||
public static OSD DeserializeLLSDBinary(Stream stream)
|
||||
{
|
||||
return DeserializeLLSDBinary(stream, false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes binary LLSD
|
||||
/// </summary>
|
||||
/// <param name="stream">Stream to read the data from</param>
|
||||
/// <param name="headerOptional">Treat LLSD binary header as optional</param>
|
||||
/// <returns>OSD containting deserialized data</returns>
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user