internal void WriteTo(ObjectWriter writer) { writer.WriteString(Name); writer.WriteString(ContainerDisplayName); writer.WriteString(FullyQualifiedContainerName); writer.WriteByte((byte)Kind); writer.WriteInt32(Span.Start); writer.WriteInt32(Span.Length); writer.WriteUInt16(ParameterCount); writer.WriteUInt16(TypeParameterCount); }
public void SerializeDocumentSnapshotInfo(DocumentChecksumObjectInfo info, ObjectWriter writer, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); SerializeDocumentId(info.Id, writer, cancellationToken); writer.WriteString(info.Name); writer.WriteValue(info.Folders.ToArray()); writer.WriteInt32((int)info.SourceCodeKind); writer.WriteString(info.FilePath); writer.WriteBoolean(info.IsGenerated); }
public void SerializeProjectSnapshotInfo(ProjectChecksumObjectInfo info, ObjectWriter writer, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); SerializeProjectId(info.Id, writer, cancellationToken); // TODO: figure out a way to send version info over as well // info.Version.WriteTo(writer); writer.WriteString(info.Name); writer.WriteString(info.AssemblyName); writer.WriteString(info.Language); writer.WriteString(info.FilePath); writer.WriteString(info.OutputFilePath); }
public async Task SerializeChecksumObjectWithChildrenAsync(ChecksumObjectWithChildren checksumObject, ObjectWriter writer, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); writer.WriteString(checksumObject.Kind); checksumObject.Checksum.WriteTo(writer); writer.WriteInt32(checksumObject.Children.Length); foreach (var child in checksumObject.Children) { var checksum = child as Checksum; if (checksum != null) { writer.WriteByte(ChecksumKind); checksum.WriteTo(writer); continue; } var checksumCollection = child as ChecksumCollection; if (checksumCollection != null) { writer.WriteByte(ChecksumCollectionKind); await SerializeChecksumObjectWithChildrenAsync(checksumCollection, writer, cancellationToken).ConfigureAwait(false); continue; } throw ExceptionUtilities.UnexpectedValue(child); } }
public void SerializeChecksumWithChildren(ChecksumWithChildren checksums, ObjectWriter writer, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var kind = checksums.GetWellKnownSynchronizationKind(); writer.WriteString(kind); checksums.Checksum.WriteTo(writer); writer.WriteInt32(checksums.Children.Count); foreach (var child in checksums.Children) { var checksum = child as Checksum; if (checksum != null) { writer.WriteByte(ChecksumKind); checksum.WriteTo(writer); continue; } var checksumCollection = child as ChecksumCollection; if (checksumCollection != null) { writer.WriteByte(ChecksumWithChildrenKind); SerializeChecksumWithChildren(checksumCollection, writer, cancellationToken); continue; } throw ExceptionUtilities.UnexpectedValue(child); } }
public static void WriteTo(this BitArray bitArray, ObjectWriter writer) { // Our serialization format doesn't round-trip bit arrays of non-byte lengths Contract.ThrowIfTrue(bitArray.Length % 8 != 0); writer.WriteString(SerializationFormat); writer.WriteInt32(bitArray.Length / 8); // This will hold the byte that we will write out after we process every 8 bits. This is // LSB, so we push bits into it from the MSB. byte b = 0; for (var i = 0; i < bitArray.Length; i++) { if (bitArray[i]) { b = (byte)(0x80 | b >> 1); } else { b >>= 1; } if ((i + 1) % 8 == 0) { // End of a byte, write out the byte writer.WriteByte(b); } } }
public void WriteTo(ObjectWriter writer) { writer.WriteString(SerializationFormat); writer.WriteBoolean(_isCaseSensitive); writer.WriteInt32(_hashFunctionCount); _bitArray.WriteTo(writer); }
// this is temporary solution until option is supported in compiler layer natively // this won't serialize all options but some we pre-selected public void SerializeOptionSet(OptionSet options, string language, ObjectWriter writer, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); writer.WriteString(language); var serializationService = GetOptionsSerializationService(language); serializationService.WriteTo(options, writer, cancellationToken); }
private static Checksum CreateChecksumFromStreamWriter(string kind, Action<ObjectWriter, CancellationToken> writer) { using (var stream = SerializableBytes.CreateWritableStream()) using (var objectWriter = new ObjectWriter(stream)) { objectWriter.WriteString(kind); writer(objectWriter, CancellationToken.None); return Checksum.Create(stream); } }
public void SerializeSourceText(ITemporaryStorageWithName storage, SourceText text, ObjectWriter writer, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); writer.WriteInt32((int)text.ChecksumAlgorithm); writer.WriteString(text.Encoding?.WebName); // TODO: refactor this part in its own abstraction (Bits) that has multiple sub types // rather than using enums if (storage != null && storage.Name != null) { writer.WriteInt32((int)SerializationKinds.MemoryMapFile); writer.WriteString(storage.Name); writer.WriteInt64(storage.Size); return; } writer.WriteInt32((int)SerializationKinds.Bits); writer.WriteString(text.ToString()); }
public void SerializeSolutionSnapshotInfo(SolutionChecksumObjectInfo info, ObjectWriter writer, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); SerializeSolutionId(info.Id, writer, cancellationToken); // TODO: figure out a way to send version info over as well. // right now, version get updated automatically, so 2 can't be exactly match // info.Version.WriteTo(writer); writer.WriteString(info.FilePath); }
public void SerializeCompilationOptions(CompilationOptions options, ObjectWriter writer, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var language = options.Language; // TODO: once compiler team adds ability to serialize compilation options to ObjectWriter directly, we won't need this. writer.WriteString(language); var service = GetOptionsSerializationService(language); service.WriteTo(options, writer, cancellationToken); }
public static void WriteTo(this BitArray bitArray, ObjectWriter writer) { // TODO : think about a way to use pool for byte array. // BitArray will internally allocate another int array. probably need to drop BitArray usage. var bytes = new byte[(bitArray.Length + 7) / 8]; bitArray.CopyTo(bytes, 0); writer.WriteString(SerializationFormat); writer.WriteInt32(bytes.Length); for (var i = 0; i < bytes.Length; i++) { writer.WriteByte(bytes[i]); } }
protected void WriteCompilationOptionsTo(CompilationOptions options, ObjectWriter writer, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); writer.WriteInt32((int)options.OutputKind); writer.WriteBoolean(options.ReportSuppressedDiagnostics); writer.WriteString(options.ModuleName); writer.WriteString(options.MainTypeName); writer.WriteString(options.ScriptClassName); writer.WriteInt32((int)options.OptimizationLevel); writer.WriteBoolean(options.CheckOverflow); // REVIEW: is it okay this being not part of snapshot? writer.WriteString(options.CryptoKeyContainer); writer.WriteString(options.CryptoKeyFile); writer.WriteValue(options.CryptoPublicKey.ToArray()); writer.WriteBoolean(options.DelaySign.HasValue); if (options.DelaySign.HasValue) { writer.WriteBoolean(options.DelaySign.Value); } writer.WriteInt32((int)options.Platform); writer.WriteInt32((int)options.GeneralDiagnosticOption); writer.WriteInt32(options.WarningLevel); // REVIEW: I don't think there is a guarantee on ordering of elements in the immutable dictionary. // unfortunately, we need to sort them to make it deterministic writer.WriteInt32(options.SpecificDiagnosticOptions.Count); foreach (var kv in options.SpecificDiagnosticOptions.OrderBy(o => o.Key)) { writer.WriteString(kv.Key); writer.WriteInt32((int)kv.Value); } writer.WriteBoolean(options.ConcurrentBuild); writer.WriteBoolean(options.Deterministic); writer.WriteBoolean(options.PublicSign); // REVIEW: What should I do with these. we probably need to implement either out own one // or somehow share these as service.... // // XmlReferenceResolver xmlReferenceResolver // SourceReferenceResolver sourceReferenceResolver // MetadataReferenceResolver metadataReferenceResolver // AssemblyIdentityComparer assemblyIdentityComparer // StrongNameProvider strongNameProvider }
public static void Serialize(ObjectWriter writer, DiagnosticAnalysisResultMap<string, DiagnosticAnalysisResultBuilder> result, CancellationToken cancellationToken) { var diagnosticSerializer = new DiagnosticDataSerializer(VersionStamp.Default, VersionStamp.Default); var analysisResult = result.AnalysisResult; writer.WriteInt32(analysisResult.Count); foreach (var kv in analysisResult) { writer.WriteString(kv.Key); Serialize(writer, diagnosticSerializer, kv.Value.SyntaxLocals, cancellationToken); Serialize(writer, diagnosticSerializer, kv.Value.SemanticLocals, cancellationToken); Serialize(writer, diagnosticSerializer, kv.Value.NonLocals, cancellationToken); diagnosticSerializer.WriteTo(writer, kv.Value.Others, cancellationToken); } var telemetryInfo = result.TelemetryInfo; writer.WriteInt32(telemetryInfo.Count); foreach (var kv in telemetryInfo) { writer.WriteString(kv.Key); Serialize(writer, kv.Value, cancellationToken); } var exceptions = result.Exceptions; writer.WriteInt32(exceptions.Count); foreach (var kv in exceptions) { writer.WriteString(kv.Key); diagnosticSerializer.WriteTo(writer, kv.Value, cancellationToken); } }
public void WriteTo(ObjectWriter writer) { Id.WriteTo(writer); // TODO: figure out a way to send version info over as well. // right now, version get updated automatically, so 2 can't be exactly match // info.Version.WriteTo(writer); writer.WriteString(FilePath); }
void IObjectWritable.WriteTo(ObjectWriter writer) { writer.WriteString(SerializationFormat); Checksum.WriteTo(writer); _bkTree.WriteTo(writer); }
public void WriteTo(AnalyzerReference reference, ObjectWriter writer, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var file = reference as AnalyzerFileReference; if (file != null) { writer.WriteString(nameof(AnalyzerFileReference)); writer.WriteInt32((int)SerializationKinds.FilePath); writer.WriteString(file.FullPath); // TODO: remove this kind of host specific knowledge from common layer. // but think moving it to host layer where this implementation detail actually exist. // // analyzer assembly path to load analyzer acts like // snapshot version for analyzer (since it is based on shadow copy) // we can't send over bits and load analyer from memory (image) due to CLR not being able // to find satellite dlls for analyzers. writer.WriteString(GetAnalyzerAssemblyPath(file)); return; } var image = reference as AnalyzerImageReference; if (image != null) { // TODO: think a way to support this or a way to deal with this kind of situation. throw new NotSupportedException(nameof(AnalyzerImageReference)); } var unresolved = reference as UnresolvedAnalyzerReference; if (unresolved != null) { writer.WriteString(nameof(UnresolvedAnalyzerReference)); writer.WriteString(reference.FullPath); return; } throw ExceptionUtilities.UnexpectedValue(reference.GetType()); }
private bool TryWritePortableExecutableReferenceBackedByTemporaryStorageTo( ISupportTemporaryStorage reference, ObjectWriter writer, CancellationToken cancellationToken) { var storages = reference.GetStorages(); if (storages == null) { return false; } using (var pooled = Creator.CreateList<ValueTuple<string, long>>()) { foreach (var storage in storages) { var storage2 = storage as ITemporaryStorageWithName; if (storage2 == null) { return false; } pooled.Object.Add(ValueTuple.Create(storage2.Name, storage2.Size)); } WritePortableExecutableReferenceHeaderTo((PortableExecutableReference)reference, SerializationKinds.MemoryMapFile, writer, cancellationToken); writer.WriteInt32((int)MetadataImageKind.Assembly); writer.WriteInt32(pooled.Object.Count); foreach (var tuple in pooled.Object) { writer.WriteInt32((int)MetadataImageKind.Module); writer.WriteString(tuple.Item1); writer.WriteInt64(tuple.Item2); } return true; } }
protected void WritePortableExecutableReferenceHeaderTo( PortableExecutableReference reference, SerializationKinds kind, ObjectWriter writer, CancellationToken cancellationToken) { writer.WriteString(nameof(PortableExecutableReference)); writer.WriteInt32((int)kind); WriteTo(reference.Properties, writer, cancellationToken); writer.WriteString(reference.FilePath); }
private void WriteTo(Stream stream, ImmutableArray<DiagnosticData> items, CancellationToken cancellationToken) { using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken)) { writer.WriteInt32(FormatVersion); AnalyzerVersion.WriteTo(writer); Version.WriteTo(writer); writer.WriteInt32(items.Length); foreach (var item in items) { cancellationToken.ThrowIfCancellationRequested(); writer.WriteString(item.Id); writer.WriteString(item.Category); writer.WriteString(item.Message); writer.WriteString(item.ENUMessageForBingSearch); writer.WriteString(item.Title); writer.WriteString(item.Description); writer.WriteString(item.HelpLink); writer.WriteInt32((int)item.Severity); writer.WriteInt32((int)item.DefaultSeverity); writer.WriteBoolean(item.IsEnabledByDefault); writer.WriteBoolean(item.IsSuppressed); writer.WriteInt32(item.WarningLevel); if (item.HasTextSpan) { // document state writer.WriteInt32(item.TextSpan.Start); writer.WriteInt32(item.TextSpan.Length); } else { // project state writer.WriteInt32(0); writer.WriteInt32(0); } WriteTo(writer, item.DataLocation, cancellationToken); WriteTo(writer, item.AdditionalLocations, cancellationToken); writer.WriteInt32(item.CustomTags.Count); foreach (var tag in item.CustomTags) { writer.WriteString(tag); } writer.WriteInt32(item.Properties.Count); foreach (var property in item.Properties) { writer.WriteString(property.Key); writer.WriteString(property.Value); } } } }
private static void WriteTo(ObjectWriter writer, DiagnosticDataLocation item, CancellationToken cancellationToken) { if (item == null) { writer.WriteBoolean(false); return; } else { writer.WriteBoolean(true); } if (item.SourceSpan.HasValue) { writer.WriteBoolean(true); writer.WriteInt32(item.SourceSpan.Value.Start); writer.WriteInt32(item.SourceSpan.Value.Length); } else { writer.WriteBoolean(false); } writer.WriteString(item.OriginalFilePath); writer.WriteInt32(item.OriginalStartLine); writer.WriteInt32(item.OriginalStartColumn); writer.WriteInt32(item.OriginalEndLine); writer.WriteInt32(item.OriginalEndColumn); writer.WriteString(item.MappedFilePath); writer.WriteInt32(item.MappedStartLine); writer.WriteInt32(item.MappedStartColumn); writer.WriteInt32(item.MappedEndLine); writer.WriteInt32(item.MappedEndColumn); }
private static void WriteUnresolvedAnalyzerReferenceTo(AnalyzerReference reference, ObjectWriter writer) { writer.WriteString(nameof(UnresolvedAnalyzerReference)); writer.WriteString(reference.FullPath); }
internal void WriteTo(ObjectWriter writer) { writer.WriteString(SerializationFormat); Version.WriteTo(writer); _bkTree.WriteTo(writer); }
protected virtual void WriteTo(ObjectWriter writer) { writer.WriteValue(_messageProvider); writer.WriteCompressedUInt((uint)_errorCode); writer.WriteInt32((int)_effectiveSeverity); writer.WriteInt32((int)_defaultSeverity); int count = (_arguments != null) ? _arguments.Length : 0; writer.WriteCompressedUInt((uint)count); if (count > 0) { foreach (var arg in _arguments) { writer.WriteString(arg.ToString()); } } }
private bool WriteIdentifierLocations(EsentStorage.Key key, Document document, VersionStamp version, SyntaxNode root, CancellationToken cancellationToken) { // delete any existing data if (!DeleteIdentifierLocations(key, cancellationToken)) { return false; } var identifierMap = SharedPools.StringIgnoreCaseDictionary<int>().AllocateAndClear(); Dictionary<string, List<int>> map = null; try { map = CreateIdentifierLocations(document, root, cancellationToken); // okay, write new data using (var accessor = _esentStorage.GetIdentifierLocationTableAccessor()) { // make sure I have all identifier ready before starting big insertion int identifierId; foreach (var identifier in map.Keys) { if (!TryGetUniqueIdentifierId(identifier, out identifierId)) { return false; } identifierMap[identifier] = identifierId; } // save whole map var uncommittedCount = 0; foreach (var kv in map) { cancellationToken.ThrowIfCancellationRequested(); var identifier = kv.Key; var positions = kv.Value; if ((uncommittedCount + positions.Count) > FlushThreshold) { accessor.Flush(); uncommittedCount = 0; } accessor.PrepareBatchOneInsert(); identifierId = identifierMap[identifier]; using (var stream = accessor.GetWriteStream(key, identifierId)) using (var writer = new ObjectWriter(stream, cancellationToken: cancellationToken)) { writer.WriteString(IdentifierSetSerializationVersion); WriteList(writer, positions); } accessor.FinishBatchOneInsert(); uncommittedCount += positions.Count; } // save special identifier that indicates version for this document if (!TrySaveIdentifierSetVersion(accessor, key, version)) { return false; } return accessor.ApplyChanges(); } } finally { SharedPools.StringIgnoreCaseDictionary<int>().ClearAndFree(identifierMap); Free(map); } }
internal override void WriteTo(ObjectWriter writer) { base.WriteTo(writer); writer.WriteInt16((short)this.contextualKind); writer.WriteString(this.valueText); }
public void WriteTo(ObjectWriter writer) { Id.WriteTo(writer); // TODO: figure out a way to send version info over as well // info.Version.WriteTo(writer); writer.WriteString(Name); writer.WriteString(AssemblyName); writer.WriteString(Language); writer.WriteString(FilePath); writer.WriteString(OutputFilePath); writer.WriteBoolean(IsSubmission); writer.WriteBoolean(HasAllInformation); // TODO: once CompilationOptions, ParseOptions, ProjectReference, MetadataReference, AnalyzerReference supports // serialization, we should include those here as well. }
protected virtual void WriteTo(ObjectWriter writer) { writer.WriteValue(_messageProvider); writer.WriteInt32(_errorCode); writer.WriteInt32((int)_effectiveSeverity); writer.WriteInt32((int)_defaultSeverity); int count = _arguments?.Length ?? 0; writer.WriteInt32(count); if (count > 0) { foreach (var arg in _arguments) { writer.WriteString(arg.ToString()); } } }
void IObjectWritable.WriteTo(ObjectWriter writer) { writer.WriteValue(_resourceSource); writer.WriteString(_nameOfLocalizableResource); var length = (uint)_formatArguments.Length; writer.WriteCompressedUInt(length); for (int i = 0; i < length; i++) { writer.WriteString(_formatArguments[i]); } }
public void WriteTo(ObjectWriter writer) { Id.WriteTo(writer); writer.WriteString(Name); writer.WriteValue(Folders.ToArray()); writer.WriteInt32((int)SourceCodeKind); writer.WriteString(FilePath); writer.WriteBoolean(IsGenerated); }