Fix serialization of decompressed lazy strings

This commit is contained in:
nzdev
2020-11-27 14:45:44 +13:00
parent e8195bfff0
commit f09fcfbdd4
2 changed files with 18 additions and 3 deletions

View File

@@ -13,6 +13,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
private byte[] _bytes;
private string _str;
private readonly object _locker;
private bool _isDecompressed;
/// <summary>
/// Constructor
@@ -22,7 +23,8 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
{
_locker = new object();
_bytes = bytes;
_str = null;
_str = null;
_isDecompressed = false;
}
public byte[] GetBytes()
@@ -31,6 +33,10 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
throw new InvalidOperationException("The bytes have already been expanded");
return _bytes;
}
public bool IsDecompressed()
{
return _isDecompressed;
}
public override string ToString()
{
@@ -41,6 +47,7 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
if (_bytes == null) throw new PanicException("Bytes have already been cleared");
_str = Encoding.UTF8.GetString(LZ4Pickler.Unpickle(_bytes));
_bytes = null;
_isDecompressed = true;
}
return _str;
}

View File

@@ -172,8 +172,16 @@ namespace Umbraco.Web.PublishedCache.NuCache.DataSource
}
else if (value is LazyCompressedString lazyCompressedString)
{
PrimitiveSerializer.Char.WriteTo(PrefixCompressedStringByteArray, stream);
PrimitiveSerializer.Bytes.WriteTo(lazyCompressedString.GetBytes(), stream);
if (lazyCompressedString.IsDecompressed())
{
PrimitiveSerializer.Char.WriteTo(PrefixString, stream);
PrimitiveSerializer.String.WriteTo(lazyCompressedString, stream);
}
else
{
PrimitiveSerializer.Char.WriteTo(PrefixCompressedStringByteArray, stream);
PrimitiveSerializer.Bytes.WriteTo(lazyCompressedString.GetBytes(), stream);
}
}
else if (value is sbyte signedByteValue)
{