提交 58c1ae0a 编写于 作者: M Matt Warren

non recursive serialization

上级 b5ba57ca
......@@ -26,7 +26,7 @@ internal XmlSyntaxDiagnosticInfo(int offset, int width, XmlParseErrorCode code,
protected override void WriteTo(ObjectWriter writer)
{
base.WriteTo(writer);
writer.WriteCompressedUInt((uint)_xmlErrorCode);
writer.WriteUInt32((uint)_xmlErrorCode);
}
protected override Func<ObjectReader, object> GetReader()
......@@ -37,7 +37,7 @@ protected override void WriteTo(ObjectWriter writer)
private XmlSyntaxDiagnosticInfo(ObjectReader reader)
: base(reader)
{
_xmlErrorCode = (XmlParseErrorCode)reader.ReadCompressedUInt();
_xmlErrorCode = (XmlParseErrorCode)reader.ReadUInt32();
}
#endregion
......
......@@ -204,7 +204,7 @@ public static SyntaxNode DeserializeFrom(Stream stream, CancellationToken cancel
throw new InvalidOperationException(CSharpResources.TheStreamCannotBeReadFrom);
}
using (var reader = new ObjectReader(stream, defaultData: GetDefaultObjectReaderData(), binder: s_defaultBinder))
using (var reader = new StreamObjectReader(stream, defaultData: GetDefaultObjectReaderData(), binder: s_defaultBinder))
{
var root = (Syntax.InternalSyntax.CSharpSyntaxNode)reader.ReadValue();
return root.CreateRed();
......
......@@ -46,6 +46,11 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</Content>
<Compile Include="Serialization\DataKind.cs" />
<Compile Include="Serialization\StreamObjectReader.cs" />
<Compile Include="Serialization\StreamObjectWriter.cs" />
<Compile Include="Serialization\VariantKind.cs" />
<Compile Include="Serialization\Variant.cs" />
<Compile Include="Syntax\InternalSyntax\GreenNodeExtensions.cs" />
<Compile Include="Syntax\InternalSyntax\SyntaxListPool.cs" />
<Compile Include="Syntax\SyntaxList.SeparatedWithManyWeakChildren.cs" />
......@@ -556,7 +561,6 @@
<Compile Include="Serialization\ObjectBinder.cs" />
<Compile Include="Serialization\ObjectReader.cs" />
<Compile Include="Serialization\ObjectReaderData.cs" />
<Compile Include="Serialization\ObjectReaderWriterBase.cs" />
<Compile Include="Serialization\ObjectWriter.cs" />
<Compile Include="Serialization\ObjectWriterData.cs" />
<Compile Include="Serialization\RecordingObjectBinder.cs" />
......
......@@ -141,12 +141,12 @@ void IObjectWritable.WriteTo(ObjectWriter writer)
protected virtual void WriteTo(ObjectWriter writer)
{
writer.WriteValue(_messageProvider);
writer.WriteCompressedUInt((uint)_errorCode);
writer.WriteUInt32((uint)_errorCode);
writer.WriteInt32((int)_effectiveSeverity);
writer.WriteInt32((int)_defaultSeverity);
int count = _arguments?.Length ?? 0;
writer.WriteCompressedUInt((uint)count);
writer.WriteUInt32((uint)count);
if (count > 0)
{
......@@ -170,11 +170,11 @@ protected virtual void WriteTo(ObjectWriter writer)
protected DiagnosticInfo(ObjectReader reader)
{
_messageProvider = (CommonMessageProvider)reader.ReadValue();
_errorCode = (int)reader.ReadCompressedUInt();
_errorCode = (int)reader.ReadUInt32();
_effectiveSeverity = (DiagnosticSeverity)reader.ReadInt32();
_defaultSeverity = (DiagnosticSeverity)reader.ReadInt32();
var count = (int)reader.ReadCompressedUInt();
var count = (int)reader.ReadUInt32();
if (count == 0)
{
_arguments = Array.Empty<object>();
......
......@@ -72,7 +72,7 @@ private LocalizableResourceString(ObjectReader reader)
_nameOfLocalizableResource = reader.ReadString();
_resourceManager = new ResourceManager(_resourceSource);
var length = (int)reader.ReadCompressedUInt();
var length = (int)reader.ReadUInt32();
if (length == 0)
{
_formatArguments = Array.Empty<string>();
......@@ -99,7 +99,7 @@ void IObjectWritable.WriteTo(ObjectWriter writer)
writer.WriteValue(_resourceSource);
writer.WriteString(_nameOfLocalizableResource);
var length = (uint)_formatArguments.Length;
writer.WriteCompressedUInt(length);
writer.WriteUInt32(length);
for (int i = 0; i < length; i++)
{
writer.WriteString(_formatArguments[i]);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Roslyn.Utilities
{
internal enum DataKind : byte
{
Null,
Type,
TypeRef, // type ref id as 4 bytes
TypeRef_B, // type ref id as 1 byte
TypeRef_S, // type ref id as 2 bytes
Object_W, // IObjectWritable
ObjectRef, // object ref id as 4 bytes
ObjectRef_B, // object ref id as 1 byte
ObjectRef_S, // object ref id as 2 bytes
StringUtf8, // string in UTF8 encoding
StringUtf16, // string in UTF16 encoding
StringRef, // string ref id as 4-bytes
StringRef_B, // string ref id as 1-byte
StringRef_S, // string ref id as 2-bytes
Boolean_T, // boolean true
Boolean_F, // boolean false
Char,
Int8,
Int16,
Int32, // int encoded as 4 bytes
Int32_B, // int encoded as 1 byte
Int32_S, // int encoded as 2 bytes
Int32_0, // int 0
Int32_1, // int 1
Int32_2, // int 2
Int32_3, // int 3,
Int32_4, // int 4,
Int32_5, // int 5,
Int32_6, // int 6,
Int32_7, // int 7,
Int32_8, // int 8,
Int32_9, // int 9,
Int32_10, // int 10,
Int64,
UInt8,
UInt16,
UInt32, // uint encoded as 4 bytes
UInt32_B, // uint encoded as 1 byte
UInt32_S, // uint encoded as 2 bytes
UInt32_0, // uint 0
UInt32_1, // uint 1
UInt32_2, // uint 2
UInt32_3, // uint 3,
UInt32_4, // uint 4,
UInt32_5, // uint 5,
UInt32_6, // uint 6,
UInt32_7, // uint 7,
UInt32_8, // uint 8,
UInt32_9, // uint 9,
UInt32_10, // uint 10,
UInt64,
Float4,
Float8,
Decimal,
DateTime,
Enum,
Array, // array with # elements encoded as compressed int
Array_0, // array with zero elements
Array_1, // array with one element
Array_2, // array with two elements
Array_3, // array with three elements
ValueArray, // value array with # elements encoded as a compressed int
ValueArray_0,
ValueArray_1,
ValueArray_2,
ValueArray_3,
BooleanType, // boolean type marker
StringType, // string type marker
End // end of object serialization
}
}
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
namespace Roslyn.Utilities
{
internal class ObjectReaderWriterBase
{
// we have s_typeMap and s_reversedTypeMap since there is no bidirectional map in compiler
protected static readonly ImmutableDictionary<Type, DataKind> s_typeMap = ImmutableDictionary.CreateRange<Type, DataKind>(
new KeyValuePair<Type, DataKind>[]
{
KeyValuePair.Create(typeof(bool), DataKind.BooleanType),
KeyValuePair.Create(typeof(char), DataKind.Char),
KeyValuePair.Create(typeof(string), DataKind.StringType),
KeyValuePair.Create(typeof(sbyte), DataKind.Int8),
KeyValuePair.Create(typeof(short), DataKind.Int16),
KeyValuePair.Create(typeof(int), DataKind.Int32),
KeyValuePair.Create(typeof(long), DataKind.Int64),
KeyValuePair.Create(typeof(byte), DataKind.UInt8),
KeyValuePair.Create(typeof(ushort), DataKind.UInt16),
KeyValuePair.Create(typeof(uint), DataKind.UInt32),
KeyValuePair.Create(typeof(ulong), DataKind.UInt64),
KeyValuePair.Create(typeof(float), DataKind.Float4),
KeyValuePair.Create(typeof(double), DataKind.Float8),
KeyValuePair.Create(typeof(decimal), DataKind.Decimal),
});
protected static readonly ImmutableDictionary<DataKind, Type> s_reverseTypeMap = s_typeMap.ToImmutableDictionary(kv => kv.Value, kv => kv.Key);
internal enum DataKind : byte
{
Null,
Type,
TypeRef, // type ref id as 4 bytes
TypeRef_B, // type ref id as 1 byte
TypeRef_S, // type ref id as 2 bytes
Object_W, // IObjectWritable
ObjectRef, // object ref id as 4 bytes
ObjectRef_B, // object ref id as 1 byte
ObjectRef_S, // object ref id as 2 bytes
StringUtf8, // string in UTF8 encoding
StringUtf16, // string in UTF16 encoding
StringRef, // string ref id as 4-bytes
StringRef_B, // string ref id as 1-byte
StringRef_S, // string ref id as 2-bytes
Boolean_T, // boolean true
Boolean_F, // boolean false
Char,
Int8,
Int16,
Int32, // int32 encoded as 4 bytes
Int32_B, // int32 encoded as 1 byte
Int32_S, // int32 encoded as 2 bytes
Int32_Z, // int32 zero
Int64,
UInt8,
UInt16,
UInt32,
UInt64,
Float4,
Float8,
Decimal,
DateTime,
Enum,
Array, // array with # elements encoded as compressed int
Array_0, // array with zero elements
Array_1, // array with one element
Array_2, // array with two elements
Array_3, // array with three elements
BooleanType, // boolean type marker
StringType // string type marker
}
internal static readonly byte ByteMarkerMask = 3 << 6;
internal static readonly byte Byte1Marker = 0;
internal static readonly byte Byte2Marker = 1 << 6;
internal static readonly byte Byte4Marker = 2 << 6;
}
}
......@@ -45,11 +45,12 @@ public void Dispose()
if (_valueToIdMap.Count > 1024)
{
DictionaryPool.ForgetTrackedObject(_valueToIdMap);
return;
}
_valueToIdMap.Clear();
DictionaryPool.Free(_valueToIdMap);
else
{
_valueToIdMap.Clear();
DictionaryPool.Free(_valueToIdMap);
}
}
public bool TryGetId(object value, out int id)
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis;
using System;
using System.Diagnostics;
using System.Reflection;
namespace Roslyn.Utilities
{
internal struct Variant
{
public readonly VariantKind Kind;
private readonly decimal _image;
private readonly object _instance;
private Variant(VariantKind kind, decimal image, object instance = null)
{
Kind = kind;
_image = image;
_instance = instance;
}
public static readonly Variant Null = new Variant(VariantKind.Null, image: 0, instance: null);
public static Variant FromBoolean(bool value)
{
return new Variant(VariantKind.Boolean, value ? 1 : 0);
}
public static Variant FromSByte(sbyte value)
{
return new Variant(VariantKind.SByte, value);
}
public static Variant FromByte(byte value)
{
return new Variant(VariantKind.Byte, value);
}
public static Variant FromInt16(short value)
{
return new Variant(VariantKind.Int16, value);
}
public static Variant FromUInt16(ushort value)
{
return new Variant(VariantKind.UInt16, value);
}
public static Variant FromInt32(int value)
{
return new Variant(VariantKind.Int32, value);
}
public static Variant FromInt64(long value)
{
return new Variant(VariantKind.Int64, value);
}
public static Variant FromUInt32(uint value)
{
return new Variant(VariantKind.UInt32, value);
}
public static Variant FromUInt64(ulong value)
{
return new Variant(VariantKind.UInt64, value);
}
public static Variant FromSingle(float value)
{
return new Variant(VariantKind.Float4, BitConverter.DoubleToInt64Bits(value));
}
public static Variant FromDouble(double value)
{
return new Variant(VariantKind.Float8, BitConverter.DoubleToInt64Bits(value));
}
public static Variant FromChar(char value)
{
return new Variant(VariantKind.Char, value);
}
public static Variant FromString(string value)
{
return new Variant(VariantKind.String, image: 0, instance: value);
}
public static Variant FromDateTime(DateTime value)
{
return new Variant(VariantKind.DateTime, value.ToBinary());
}
public static Variant FromDecimal(Decimal value)
{
return new Variant(VariantKind.Decimal, value);
}
public static Variant FromBoxedEnum(object value)
{
return new Variant(VariantKind.BoxedEnum, image: 0, instance: value);
}
public static Variant FromType(Type value)
{
return new Variant(VariantKind.Type, image: 0, instance: value);
}
public static Variant FromArray(Array array)
{
return new Variant(VariantKind.Array, image: 0, instance: array);
}
public static Variant FromArrayHeader(Array array)
{
return new Variant(VariantKind.ArrayHeader, image: 0, instance: array);
}
public static Variant FromObject(object value)
{
return new Variant(VariantKind.Object, image: 0, instance: value);
}
public static Variant FromObjectHeader(object value, uint memberCount)
{
return new Variant(VariantKind.ObjectHeader, image: memberCount, instance: value);
}
public bool AsBoolean()
{
Debug.Assert(Kind == VariantKind.Boolean);
return _image != 0;
}
public sbyte AsSByte()
{
Debug.Assert(Kind == VariantKind.SByte);
return (sbyte)_image;
}
public byte AsByte()
{
Debug.Assert(Kind == VariantKind.Byte);
return (byte)_image;
}
public short AsInt16()
{
Debug.Assert(Kind == VariantKind.Int16);
return (short)_image;
}
public ushort AsUInt16()
{
Debug.Assert(Kind == VariantKind.UInt16);
return (ushort)_image;
}
public int AsInt32()
{
Debug.Assert(Kind == VariantKind.Int32);
return (int)_image;
}
public uint AsUInt32()
{
Debug.Assert(Kind == VariantKind.UInt32);
return (uint)_image;
}
public long AsInt64()
{
Debug.Assert(Kind == VariantKind.Int64);
return (long)_image;
}
public ulong AsUInt64()
{
Debug.Assert(Kind == VariantKind.UInt64);
return (ulong)_image;
}
public decimal AsDecimal()
{
Debug.Assert(Kind == VariantKind.Decimal);
return _image;
}
public float AsSingle()
{
Debug.Assert(Kind == VariantKind.Float4);
return (float)BitConverter.Int64BitsToDouble((long)_image);
}
public double AsDouble()
{
Debug.Assert(Kind == VariantKind.Float8);
return BitConverter.Int64BitsToDouble((long)_image);
}
public char AsChar()
{
Debug.Assert(Kind == VariantKind.Char);
return (char)_image;
}
public string AsString()
{
Debug.Assert(Kind == VariantKind.String);
return (string)_instance;
}
public DateTime AsDateTime()
{
Debug.Assert(Kind == VariantKind.DateTime);
return DateTime.FromBinary((long)_image);
}
public object AsObject()
{
Debug.Assert(Kind == VariantKind.Object);
return _instance;
}
public object AsObjectHeader()
{
uint memberCount;
return AsObjectHeader(out memberCount);
}
public object AsObjectHeader(out uint memberCount)
{
Debug.Assert(Kind == VariantKind.ObjectHeader);
memberCount = (uint)_image;
return _instance;
}
public object AsBoxedEnum()
{
Debug.Assert(Kind == VariantKind.BoxedEnum);
return _instance;
}
public Type AsType()
{
Debug.Assert(Kind == VariantKind.Type);
return (Type)_instance;
}
public Array AsArray()
{
Debug.Assert(Kind == VariantKind.Array);
return (Array)_instance;
}
public Array AsArrayHeader()
{
Debug.Assert(Kind == VariantKind.ArrayHeader);
return (Array)_instance;
}
public static Variant FromBoxedObject(object value)
{
if (value == null)
{
return Variant.Null;
}
else
{
var type = value.GetType();
var typeInfo = type.GetTypeInfo();
if (typeInfo.IsEnum)
{
return FromBoxedEnum(value);
}
else if (type == typeof(bool))
{
return FromBoolean((bool)value);
}
else if (type == typeof(int))
{
return FromInt32((int)value);
}
else if (type == typeof(string))
{
return FromString((string)value);
}
else if (type == typeof(short))
{
return FromInt16((short)value);
}
else if (type == typeof(long))
{
return FromInt64((long)value);
}
else if (type == typeof(char))
{
return FromChar((char)value);
}
else if (type == typeof(sbyte))
{
return FromSByte((sbyte)value);
}
else if (type == typeof(byte))
{
return FromByte((byte)value);
}
else if (type == typeof(ushort))
{
return FromUInt16((ushort)value);
}
else if (type == typeof(uint))
{
return FromUInt32((uint)value);
}
else if (type == typeof(ulong))
{
return FromUInt64((ulong)value);
}
else if (type == typeof(decimal))
{
return FromDecimal((decimal)value);
}
else if (type == typeof(float))
{
return FromSingle((float)value);
}
else if (type == typeof(double))
{
return FromDouble((double)value);
}
else if (type == typeof(DateTime))
{
return FromDateTime((DateTime)value);
}
else if (type.IsArray)
{
var instance = (Array)value;
if (instance.Rank > 1)
{
#if COMPILERCORE
throw new InvalidOperationException(CodeAnalysisResources.ArraysWithMoreThanOneDimensionCannotBeSerialized);
#else
throw new InvalidOperationException(WorkspacesResources.Arrays_with_more_than_one_dimension_cannot_be_serialized);
#endif
}
return Variant.FromArray(instance);
}
else if (value is Type)
{
return Variant.FromType((Type)value);
}
else
{
return Variant.FromObject(value);
}
}
}
public object ToBoxedObject()
{
switch (this.Kind)
{
case VariantKind.Array:
return this.AsArray();
case VariantKind.ArrayHeader:
return this.AsArrayHeader();
case VariantKind.Boolean:
return this.AsBoolean();
case VariantKind.BoxedEnum:
return this.AsBoxedEnum();
case VariantKind.Byte:
return this.AsByte();
case VariantKind.Char:
return this.AsChar();
case VariantKind.DateTime:
return this.AsDateTime();
case VariantKind.Decimal:
return this.AsDecimal();
case VariantKind.Float4:
return this.AsSingle();
case VariantKind.Float8:
return this.AsDouble();
case VariantKind.Int16:
return this.AsInt16();
case VariantKind.Int32:
return this.AsInt32();
case VariantKind.Int64:
return this.AsInt64();
case VariantKind.Null:
return null;
case VariantKind.Object:
return this.AsObject();
case VariantKind.ObjectHeader:
return this.AsObjectHeader();
case VariantKind.SByte:
return this.AsSByte();
case VariantKind.String:
return this.AsString();
case VariantKind.Type:
return this.AsType();
case VariantKind.UInt16:
return this.AsUInt16();
case VariantKind.UInt32:
return this.AsUInt32();
case VariantKind.UInt64:
return this.AsUInt64();
default:
throw ExceptionUtilities.UnexpectedValue(this.Kind);
}
}
}
}
\ No newline at end of file
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Roslyn.Utilities
{
internal enum VariantKind
{
None = 0,
Null,
Boolean,
SByte,
Byte,
Int16,
UInt16,
Int32,
UInt32,
Int64,
UInt64,
Decimal,
Float4,
Float8,
Char,
String,
DateTime,
Object,
ObjectHeader,
BoxedEnum,
Array,
ArrayHeader,
Type
}
}
\ No newline at end of file
......@@ -1248,7 +1248,7 @@ public virtual void SerializeTo(Stream stream, CancellationToken cancellationTok
throw new InvalidOperationException(CodeAnalysisResources.TheStreamCannotBeWrittenTo);
}
using (var writer = new ObjectWriter(stream, GetDefaultObjectWriterData(), binder: s_defaultBinder, cancellationToken: cancellationToken))
using (var writer = new StreamObjectWriter(stream, GetDefaultObjectWriterData(), binder: s_defaultBinder, cancellationToken: cancellationToken))
{
writer.WriteValue(this.Green);
}
......
......@@ -132,7 +132,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
''' Deserialize a syntax node from a byte stream.
''' </summary>
Public Shared Function DeserializeFrom(stream As IO.Stream, Optional cancellationToken As CancellationToken = Nothing) As SyntaxNode
Using reader = New ObjectReader(stream, defaultData:=GetDefaultObjectReaderData(), binder:=s_defaultBinder)
Using reader = New StreamObjectReader(stream, defaultData:=GetDefaultObjectReaderData(), binder:=s_defaultBinder)
Return DirectCast(reader.ReadValue(), InternalSyntax.VisualBasicSyntaxNode).CreateRed(Nothing, 0)
End Using
End Function
......
......@@ -35,7 +35,7 @@ protected override Data TryGetExistingData(Stream stream, Document value, Cancel
var list = SharedPools.Default<List<TodoItem>>().AllocateAndClear();
try
{
using (var reader = new ObjectReader(stream))
using (var reader = new StreamObjectReader(stream))
{
var format = reader.ReadString();
if (!string.Equals(format, FormatVersion))
......@@ -63,7 +63,7 @@ protected override Data TryGetExistingData(Stream stream, Document value, Cancel
protected override void WriteTo(Stream stream, Data data, CancellationToken cancellationToken)
{
using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken))
{
writer.WriteString(FormatVersion);
data.TextVersion.WriteTo(writer);
......
......@@ -115,14 +115,14 @@ public void TestSerialization()
var stream = new MemoryStream();
var bloomFilter = new BloomFilter(0.001, false, new[] { "Hello, World" });
using (var writer = new ObjectWriter(stream))
using (var writer = new StreamObjectWriter(stream))
{
bloomFilter.WriteTo(writer);
}
stream.Position = 0;
using (var reader = new ObjectReader(stream))
using (var reader = new StreamObjectReader(stream))
{
var rehydratedFilter = BloomFilter.ReadFrom(reader);
Assert.True(bloomFilter.IsEquivalent(rehydratedFilter));
......
......@@ -33,7 +33,7 @@ protected override Data TryGetExistingData(Stream stream, Document value, Cancel
{
try
{
using (var reader = new ObjectReader(stream))
using (var reader = new StreamObjectReader(stream))
{
var format = reader.ReadString();
if (!string.Equals(format, FormatVersion, StringComparison.InvariantCulture))
......@@ -56,7 +56,7 @@ protected override Data TryGetExistingData(Stream stream, Document value, Cancel
protected override void WriteTo(Stream stream, Data data, CancellationToken cancellationToken)
{
using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken))
{
writer.WriteString(FormatVersion);
data.TextVersion.WriteTo(writer);
......
......@@ -140,7 +140,7 @@ private CompilationWithAnalyzers CreateAnalyzerDriver(CompilationWithAnalyzers a
// handling of cancellation and exception
var version = await DiagnosticIncrementalAnalyzer.GetDiagnosticVersionAsync(project, cancellationToken).ConfigureAwait(false);
using (var reader = new ObjectReader(stream))
using (var reader = new StreamObjectReader(stream))
{
return DiagnosticResultSerializer.Deserialize(reader, analyzerMap, project, version, cancellationToken);
}
......
......@@ -134,7 +134,7 @@ private static bool TryReadFrom(Project project, string keyName, out Versions ve
try
{
using (var reader = new ObjectReader(stream))
using (var reader = new StreamObjectReader(stream))
{
var formatVersion = reader.ReadInt32();
if (formatVersion != SerializationFormat)
......@@ -207,7 +207,7 @@ private static async Task WriteToDependentSemanticVersionAsync(IPersistentStorag
IPersistentStorage storage, string keyName, VersionStamp projectVersion, VersionStamp semanticVersion, CancellationToken cancellationToken)
{
using (var stream = SerializableBytes.CreateWritableStream())
using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken))
{
writer.WriteInt32(SerializationFormat);
projectVersion.WriteTo(writer);
......
......@@ -130,7 +130,7 @@ public async Task RequestAssetAsync(int serviceId, byte[][] checksums, string st
using (Logger.LogBlock(FunctionId.JsonRpcSession_RequestAssetAsync, streamName, _source.Token))
using (var stream = await DirectStream.GetAsync(streamName, _source.Token).ConfigureAwait(false))
{
using (var writer = new ObjectWriter(stream))
using (var writer = new StreamObjectWriter(stream))
{
writer.WriteInt32(serviceId);
......
......@@ -85,7 +85,7 @@ private VersionStamp GetIdentifierSetVersion(EsentStorage.Key key, int identifie
return VersionStamp.Default;
}
using (var reader = new ObjectReader(stream))
using (var reader = new StreamObjectReader(stream))
{
return VersionStamp.ReadFrom(reader);
}
......@@ -149,7 +149,7 @@ private bool ReadIdentifierPositions(EsentStorage.Key key, int identifierId, Lis
return true;
}
using (var reader = new ObjectReader(stream))
using (var reader = new StreamObjectReader(stream))
{
var formatVersion = reader.ReadString();
if (formatVersion != IdentifierSetSerializationVersion)
......@@ -240,7 +240,7 @@ private bool WriteIdentifierLocations(EsentStorage.Key key, Document document, V
identifierId = identifierMap[identifier];
using (var stream = accessor.GetWriteStream(key, identifierId))
using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken))
{
writer.WriteString(IdentifierSetSerializationVersion);
WriteList(writer, positions);
......@@ -298,7 +298,7 @@ private void Free(Dictionary<string, List<int>> map)
accessor.PrepareBatchOneInsert();
using (var stream = accessor.GetWriteStream(key, identifierId))
using (var writer = new ObjectWriter(stream))
using (var writer = new StreamObjectWriter(stream))
{
version.WriteTo(writer);
}
......
......@@ -39,7 +39,7 @@ public DiagnosticDataSerializer(VersionStamp analyzerVersion, VersionStamp versi
public async Task<bool> SerializeAsync(object documentOrProject, string key, ImmutableArray<DiagnosticData> items, CancellationToken cancellationToken)
{
using (var stream = SerializableBytes.CreateWritableStream())
using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken))
{
WriteTo(writer, items, cancellationToken);
......@@ -68,7 +68,7 @@ public async Task<StrongBox<ImmutableArray<DiagnosticData>>> DeserializeAsync(ob
return null;
}
using (var reader = new ObjectReader(stream))
using (var reader = new StreamObjectReader(stream))
{
// we return StrongBox rather than ImmutableArray due to task lib's issue with allocations
// when returning default(value type)
......
......@@ -47,7 +47,7 @@ public Checksum CreateChecksum(MetadataReference reference, CancellationToken ca
public Checksum CreateChecksum(AnalyzerReference reference, CancellationToken cancellationToken)
{
using (var stream = SerializableBytes.CreateWritableStream())
using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken))
{
WriteTo(reference, writer, cancellationToken);
......@@ -180,7 +180,7 @@ private void WritePortableExecutableReferencePropertiesTo(PortableExecutableRefe
private Checksum CreatePortableExecutableReferenceChecksum(PortableExecutableReference reference, CancellationToken cancellationToken)
{
using (var stream = SerializableBytes.CreateWritableStream())
using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken))
{
WritePortableExecutableReferencePropertiesTo(reference, writer, cancellationToken);
WriteMvidsTo(TryGetMetadata(reference), writer, cancellationToken);
......
......@@ -40,7 +40,7 @@ public override Task WriteObjectToAsync(ObjectWriter writer, CancellationToken c
private static Checksum CreateChecksumFromStreamWriter(string kind, Action<ObjectWriter, CancellationToken> writer)
{
using (var stream = SerializableBytes.CreateWritableStream())
using (var objectWriter = new ObjectWriter(stream))
using (var objectWriter = new StreamObjectWriter(stream))
{
objectWriter.WriteString(kind);
writer(objectWriter, CancellationToken.None);
......
......@@ -100,7 +100,7 @@ internal partial class SymbolTreeInfo
{
if (stream != null)
{
using (var reader = new ObjectReader(stream))
using (var reader = new StreamObjectReader(stream))
{
// We have some previously persisted data. Attempt to read it back.
// If we're able to, and the version of the persisted data matches
......@@ -129,7 +129,7 @@ internal partial class SymbolTreeInfo
if (result != null)
{
using (var stream = SerializableBytes.CreateWritableStream())
using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken))
{
writeObject(writer, result);
stream.Position = 0;
......
......@@ -53,7 +53,7 @@ private static bool TryReadVersion(ObjectReader reader, string formatVersion, ou
return null;
}
using (var reader = new ObjectReader(stream))
using (var reader = new StreamObjectReader(stream))
{
VersionStamp persistVersion;
if (TryReadVersion(reader, formatVersion, out persistVersion) &&
......@@ -77,7 +77,7 @@ private static bool TryReadVersion(ObjectReader reader, string formatVersion, ou
// attempt to load from persisted state
using (var storage = persistentStorageService.GetStorage(document.Project.Solution))
using (var stream = SerializableBytes.CreateWritableStream())
using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken))
using (var writer = new StreamObjectWriter(stream, cancellationToken: cancellationToken))
{
data.WriteVersion(writer, formatVersion);
data.WriteTo(writer);
......@@ -100,7 +100,7 @@ protected static async Task<bool> PrecalculatedAsync(Document document, string p
{
if (stream != null)
{
using (var reader = new ObjectReader(stream))
using (var reader = new StreamObjectReader(stream))
{
VersionStamp persistVersion;
return TryReadVersion(reader, formatVersion, out persistVersion) &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册