/// <summary> /// Serialize the <see cref="StateManagerFileProperties"/> into the given stream. /// </summary> /// <param name="writer">Stream to write to.</param> public override void Write(BinaryWriter writer) { // Allow the base class to write first. base.Write(writer); // 'metadata' - BlockHandle writer.Write(MetadataHandlePropertyName); VarInt.Write(writer, (int)BlockHandle.SerializedSize); this.MetadataHandle.Write(writer); // 'blocks' - BlockHandle writer.Write(BlocksHandlePropertyName); VarInt.Write(writer, (int)BlockHandle.SerializedSize); this.BlocksHandle.Write(writer); // 'count' - uint writer.Write(StateProviderCountPropertyName); VarInt.Write(writer, (int)sizeof(uint)); writer.Write(this.StateProviderCount); // 'roots' - uint writer.Write(RootStateProviderCountPropertyName); VarInt.Write(writer, (int)sizeof(uint)); writer.Write(this.RootStateProviderCount); // 'partitionid' - Guid writer.Write(PartitionIdPropertyName); var partitionIdBytes = this.PartitionId.ToByteArray(); VarInt.Write(writer, (int)partitionIdBytes.Length); writer.Write(partitionIdBytes); // 'replicaid' - long writer.Write(ReplicaIdPropertyName); VarInt.Write(writer, (int)sizeof(long)); writer.Write(this.ReplicaId); // #12249219: Without the "allowPrepareCheckpointLSNToBeInvalid" being set to true in the backup code path, // It is possible for all backups before the first checkpoint after the upgrade to fail. if (this.doNotWritePrepareCheckpointLSN == false && this.test_Ignore == false) { // 'checkpointlsn' - long writer.Write(PrepareCheckpointLSNPropertyName); VarInt.Write(writer, (int)sizeof(long)); writer.Write(this.PrepareCheckpointLSN); } }
/// <summary> /// Deserialize the <see cref="FileProperties"/> from the given stream. /// </summary> /// <param name="reader">The stream to read from.</param> /// <param name="handle">Starting offset and size within the stream for the file properties.</param> /// <returns>The deserialized <see cref="FileProperties"/> section.</returns> public static TProperties Read <TProperties>(BinaryReader reader, BlockHandle handle) where TProperties : FileProperties, new() { var properties = new TProperties(); if (handle.Size == 0) { return(properties); } // The FileProperties start at the given 'offset' within the stream, and contains properties up to 'offset' + 'size'. reader.BaseStream.Position = handle.Offset; while (reader.BaseStream.Position < handle.EndOffset) { // Read the property name. var property = reader.ReadString(); // Read the size in bytes of the property's value. var valueSize = VarInt.ReadInt32(reader); if (valueSize < 0) { throw new InvalidDataException(string.Format(SR.Error_FileProperties_Corrupt, SR.Error_FileProperties_NegativeSize)); } if (reader.BaseStream.Position + valueSize > handle.EndOffset) { throw new InvalidDataException( string.Format(SR.Error_FileProperties_Corrupt, SR.Error_FileProperties_LargeSize)); } // Read the property's value. properties.ReadProperty(reader, property, valueSize); } // Validate the properties section ended exactly where expected. if (reader.BaseStream.Position != handle.EndOffset) { throw new InvalidDataException(string.Format(SR.Error_FileProperties_Corrupt, SR.Error_FileProperties_SectionSize)); } return(properties); }
/// <summary> /// Serialize the <see cref="BackupLogFileProperties"/> into the given stream. /// </summary> /// <param name="writer">Stream to write to.</param> public override void Write(BinaryWriter writer) { // Allow the base class to write first. base.Write(writer); // 'records' - BlockHandle writer.Write(RecordsHandlePropertyName); VarInt.Write(writer, (int)BlockHandle.SerializedSize); this.RecordsHandle.Write(writer); // 'count' - uint writer.Write(CountPropertyName); VarInt.Write(writer, (int)sizeof(uint)); writer.Write(this.Count); // 'indexepoch' - Epoch writer.Write(IndexingRecordEpochPropertyName); VarInt.Write(writer, (int)(sizeof(long) * 2)); writer.Write(this.IndexingRecordEpoch.DataLossNumber); writer.Write(this.IndexingRecordEpoch.ConfigurationNumber); // 'indexlsn' - long writer.Write(IndexingRecordLsnPropertyName); VarInt.Write(writer, (int)sizeof(long)); writer.Write(this.IndexingRecordLsn.LSN); // 'backupepoch' - Epoch writer.Write(LastBackedUpEpochPropertyName); VarInt.Write(writer, (int)(sizeof(long) * 2)); writer.Write(this.LastBackedUpEpoch.DataLossNumber); writer.Write(this.LastBackedUpEpoch.ConfigurationNumber); // 'backuplsn' - long writer.Write(LastBackedUpLsnPropertyName); VarInt.Write(writer, (int)sizeof(long)); writer.Write(this.LastBackedUpLsn.LSN); }